Skip to content

fix(app): release closed session transcripts - #86

Closed
trmosala wants to merge 1 commit into
CM-Split-v2from
transcript-retention
Closed

trmosala wants to merge 1 commit into
CM-Split-v2from
transcript-retention

Conversation

@trmosala

Copy link
Copy Markdown
Owner

Summary

Releases cached session transcripts after their tabs close (#77).

The client data cache kept every session's transcript and pending rows after its tab closed. Late reads, older pages and later events could also bring evicted rows back.

  • Retention policy. createSessionRetention (packages/app/src/runtime/server/session-retention.ts) is wired in createServerController. It evicts a session family once nothing has kept it for 1 s while no navigation is pending.
    • These keep a family:
      • this server's open tabs (sessionId, routeSessionId, routeParentId)
      • the current session route
      • running work (data.session.active())
      • permission and form requests
    • The 1 s delay covers Home's open path, which reads the transcript before the transition that adds its tab commits.
  • Returning rows. Rows that come back after eviction are released at the next deadline. This covers late message.sync, loadMore and events. A family that keeps receiving rows still releases at its first deadline.
  • Optimistic state. Eviction keeps unacknowledged submissions and sessions still being created. The policy retries while the family stays unkept, so they are released once acknowledged or rejected.
  • New accessor. data.session.cached (packages/client/src/solid/data.ts) lists sessions holding transcript or pending rows. It notifies only when that set changes, not for each streamed row.
  • Unchanged. The 16-entry timeline view cache is untouched.

Tests

  • packages/app/test-browser/session-retention.test.ts: 8 pass.
    • Uses a real createData, run with bun test --conditions=browser --isolate --preload ./happydom.ts ./test-browser/session-retention.test.ts.
    • Covers:
      • families kept by a visible tab, running work and attention requests
      • closing a child while its parent tab stays open
      • waiting for persisted tabs and pending navigation
      • late reads, late pages and later events
      • optimistic prompt echo and reject
      • an in-flight session create
      • heap churn
    • Heap churn uses 48 × 512 KiB transcripts. After GC the heap went 15.37 MB base → 40.84 MB loaded → 15.99 MB released, and every row WeakRef was collected.
    • Before the retry fix, the echo and in-flight create cases failed.
    • Like the other test-browser/ files, this file is outside packages/app/tsconfig.json, so the typecheck does not cover it.
  • packages/app/e2e/regression/tabs.spec.ts: 20 passed in dev mode.
    • The new test closes tab B, waits past the delay and reopens it with Ctrl+Shift+T. It checks that B's transcript is read again and that the open tab A is read only once.
    • With runtime.tsx reverted to the base, the new test fails: B is read once instead of twice. So it depends on the app actually evicting B.
    • The existing child-close test still passes.
  • Client and TUI:
    • packages/client test/solid-eviction.test.ts: 4 pass.
    • packages/tui test/context/session-retention.test.ts: 6 pass.
  • Typecheck: bun typecheck passes in packages/client and packages/app.
  • Root bun run check: passes. Lint has 0 errors (2186 existing warnings), sdk-docs reports 0 problems, and typecheck is 37/37.
    • Local environment note: on this VM's 4G limit, @opencode/core's tsgo is OOM-killed unless Go's GC is tuned.
    • The check ran as GOGC=25 GOMEMLIMIT=3GiB TURBO_ENV_MODE=loose bun run check, with scripts, hooks and coverage unchanged.

Performance

The result is mixed. This is not a no-regression claim.

Full timeline benchmark, baseline vs. after:

  • Base dafdcd41 and this branch, build mode, --repeat-each=10, n=10 per metric, in ms.
  • Both runs had 90 pass and 10 fail. All 10 failures are the cold-home review staging scenario, a pre-existing mismatch that fails on the base too and is excluded below.
Scenario Metric Baseline median / p95 After median / p95 Median Δ
home: open session first 472.6 / 565.0 439.2 / 574.6 −7.1%
home: open session stable 509.1 / 684.1 473.6 / 612.6 −7.0%
home: close only tab first 192.9 / 221.9 181.8 / 392.0 −5.8%
home: close only tab stable 225.4 / 279.0 209.2 / 485.8 −7.2%
prefetch: activate after restore firstCorrect 219.3 / 337.8 285.8 / 312.7 +30.3%
prefetch: activate after restore stable 259.1 / 415.9 317.9 / 424.7 +22.7%
prefetch: close before response firstCorrect 194.7 / 239.9 211.3 / 299.3 +8.6%
prefetch: close before response stable 232.4 / 275.7 293.3 / 381.7 +26.2%
switch: cold, review closed firstCorrect 367.4 / 479.7 413.7 / 464.7 +12.6%
switch: cold, review closed stable 393.4 / 547.8 482.2 / 506.6 +22.6%
switch: cold, review open firstCorrect 390.0 / 453.2 431.4 / 547.9 +10.6%
switch: cold, review open stable 417.8 / 468.5 459.7 / 683.8 +10.0%
switch: warm, review closed firstCorrect 72.9 / 83.7 76.9 / 117.2 +5.5%
switch: warm, review closed stable 152.4 / 165.3 154.9 / 214.6 +1.6%
switch: warm, review open firstCorrect 105.0 / 115.4 111.9 / 125.5 +6.6%
switch: warm, review open stable 110.1 / 130.1 125.9 / 213.7 +14.4%
switch: warm, review resized firstCorrect 125.4 / 137.3 150.6 / 186.5 +20.1%
switch: warm, review resized stable 212.8 / 285.7 248.6 / 324.5 +16.9%

Matched rerun of the two largest firstCorrect rises:

  • The control run used the base runtime.tsx and data.ts, and the treatment run used this branch. They ran back to back with the same command, in that fixed order.
  • Each arm had 20/20 pass. n=10 per metric, in ms.
Scenario Metric Control median / p95 Treatment median / p95 Median Δ
prefetch: activate after restore firstCorrect 309.8 / 365.0 278.0 / 372.8 −10.3%
prefetch: activate after restore stable 350.2 / 499.6 360.2 / 463.6 +2.9%
switch: warm, review resized firstCorrect 145.5 / 174.0 156.2 / 181.2 +7.3%
switch: warm, review resized stable 222.0 / 314.6 279.1 / 311.7 +25.7%

Reading the results:

  • Prefetch activation: the +30.3% did not reproduce. The matched control alone ran about 90 ms slower than the baseline median, so the spread between batches is larger than the original gap.
  • Warm resized, stable: the median rose in both batches, but its p95 stayed flat and the samples overlap widely (control 156.7–314.6, treatment 118.9–311.7).
  • Source review: found no costly path on a warm switch.
    • The policy only does set lookups and timer work.
    • cached notifies only when the set of cached sessions changes.
    • Families with an open tab are never evicted. This is consistent with warm firstCorrect staying near 150 ms, against cold medians of 367–431 ms.
  • Conclusion: treat this as an unresolved difference within small-sample noise, not as proven neutral.

Follow-up

Refs #77

The client data cache kept every session's transcript and pending rows
after its tab closed, and late reads, older pages and later events
could bring evicted rows back.

createSessionRetention, wired in createServerController, evicts a
session family once no open tab, session route, running work or
attention request has kept it for one second with no navigation
pending. Rows that return after eviction are released at the next
deadline. Eviction keeps unacknowledged submissions and sessions still
being created, so the policy retries until they settle.

Adds data.session.cached, which lists sessions holding transcript or
pending rows and notifies only when that set changes.

Refs #77
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@trmosala

Copy link
Copy Markdown
Owner Author

Superseded by PR #96, squashed into CM-Split-v2 as 290d7d6353c0c7a4a356af780b5687f2dcfe5cfc. This PR's current head was checked against the reviewed head and is an ancestor of integration source 68ab9205709350385471eb2d383b3cff3c18e678; the squash commit's tree matches that source exactly. Later corrections and the actual private dependency pin are included there.

Closing this earlier PR as superseded, not claiming it was independently merged. Its branch remains intact. Final combined verification is deferred until the scoped implementation issues are closed, as requested by the user.

@trmosala trmosala closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant