GeezerVison is showing github.com — fix(app,client): keep hidden transcripts to their tail under a size budget by kitlangton · Pull Request #58491 · anomalyco/opencode
Conversation
kitlangton
commented
Oct 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Stacked on #57025. This PR targets app-session-evict and should be retargeted to dev once #57025 merges.
What it does
#57025 keeps open tabs and recent sessions whole, with no limit on how many or how large they are, even though only one session is ever on screen. With this change, hidden sessions keep only their latest messages, and their total size has a budget. Switching to a tab is still instant. Scrolling up loads older messages from the server through the existing "load earlier" path.
How it works
- The data layer now remembers the server cursor for the oldest message of each page it loads (
message.sync and loadMore).
- The new
session.message.trim(id, tail) cuts at the newest loaded page boundary that still leaves at least tail messages, and restores that page's cursor. more()/loadMore() then refetch exactly what was dropped. If no page boundary lies within twice the tail (history that grew from live events), it keeps the last tail messages, clears the cursor and invalidates the read, so the next view refetches as many newest messages as it still shows (capped at the server's 200). A trim that lands while an older page is loading returns false and runs again when the page lands.
createSessionRetention still picks the same families as fix(app,client): wire session transcript retention and evict background transcripts #57025 (current, open tabs, 3 recent). The visible session, its ancestors (a subagent's header and background list read the parent's transcript) and any running session stay whole. Every other retained session is trimmed to 40 messages, and trimmed again whenever background events add to it.
- Hidden families are walked from most to least recently viewed (open tabs never viewed come last), with sizes estimated from string length and cached by length plus first and last message id. Families past the 50 MB budget are evicted fully, as fix(app,client): wire session transcript retention and evict background transcripts #57025 already does for families outside the retained set. The family of the current session doesn't count toward the budget, and a family with a running session is neither measured nor evicted, here or outside the retained set, until it goes idle.
The desktop app and the TUI both use these defaults through the shared createSessionRetention.
Risk
Client-side cache only; the server is unchanged.
- In the fallback case (no usable page boundary), returning to the session fetches the newest page again, the same way an evicted session reloads today. Events that arrive while that fetch is in flight can be overwritten by the response. This race already exists when an evicted session reloads.
- A hidden idle session whose existing messages change without a new message (no known case today) keeps its old size estimate until its length or ends change.
- After a fallback trim the cursor stays cleared until the refetch commits, so if that read fails, "load earlier" is unavailable until the next view retries it. Keeping the old cursor would page in from past the dropped messages and leave a gap.
- Siblings of the viewed session in the same family are still trimmed. Going back to them pages older messages in on scroll.
- Not covered: adapting to memory pressure.
Proof
Simulated with 15 open tabs, each holding 400 messages of 2,000 characters. Retained transcript size dropped from about 12.1 MB to 1.2 MB (estimated bytes; session-tail.test.ts asserts a 5× drop). I didn't measure this in the running app.
bun test test/context/session-tail.test.ts test/context/session-retention.test.ts (tui): 16 pass. New tests cover trimming when you leave a session, paging the dropped history back in with no gaps or extra reads, running sessions staying whole, background appends being re-trimmed (both the page-boundary cut and the fallback), a trim deferred by an in-flight page, a subagent's parent staying whole, re-measuring a transcript whose content changed at the same length, running families surviving both eviction paths, and eviction order under the budget. The four added in the second commit fail without it.
bun test test/cli/tui/data.test.tsx (tui): 50 pass
bun test test/solid-data.test.ts test/solid-eviction.test.ts test/solid-compaction.test.ts (client): 56 pass
bun run typecheck in packages/client, packages/tui and packages/app: clean
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…deferred trims
Size cache keys on length plus first and last id, trims deferred by a loading page run again when it lands, a fallback trim's revalidation fetches what it still shows, and the idle status and marker publish together.
|
Automated PR Cleanup
Thank you for contributing to opencode.
Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.
This PR was closed because it matched the following cleanup criteria:
- The PR was created more than 1 month ago
- The PR had fewer than 2 positive reactions
- Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR
PRs created within the last month are not affected by this cleanup.
If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.
Thanks again for taking the time to contribute.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|