Repository navigation
fix(inject): bound per-session state in a long-lived server - #77
Merged
Merged
Conversation
One 64-session LRU (same cap as repokey.ts) evicts epoch, latestPrompt, sessionStats and measuredTurns together. It is touched in the prompt and context hooks and in message.updated. An evicted session gets no relevance block until its next prompt, then a fresh "first" epoch, so it never sees stale state. Follow-up to abogartz#65, where latestPrompt made the leak worse. Closes abogartz#75. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 24, 2026
abogartz
approved these changes
Oct 24, 2026
abogartz
left a comment
Owner
There was a problem hiding this comment.
Approving. Verified independently on the merged batch (all five applied cleanly onto 0.8.4):
SessionLrusemantics are exactly right, and I caught my own probe being wrong on the first pass, which is the best kind of confirmation: atcap=3with the set already full,touch(a)evictsbimmediately — the eviction loop is strict and never runs one behind.- One owner for eviction over all four maps, touched in all three entry points (prompt hook, context hook,
message.updated) before anything inserts. I checked every write site ofepoch/latestPrompt/sessionStats/measuredTurnsindividually:epoch.setandlatestPrompt.setare downstream oftouch, and the onlystatsForcall that could insert without a touch is insidebuildPayload, which returns early when no epoch exists — so an evicted session cannot leave an orphan stats entry behind. - The semantics paragraph is the right trade: one recompute for a session idle behind 64 active ones, never stale state. For
opencode serveresidency that is the whole ballgame, and pairing withrepokey.ts's cap is the right consistency.
Combined-batch gates: 324 pass / 4 skip / 0 fail, tsc --noEmit clean, biome exit 0.
|
🎉 This PR is included in version 0.8.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #75. This is the bounded-maps item from your #65 review. #65 merged before I pushed it, and since #65's
latestPromptmade the leak worse, I'd like to close it promptly.The problem: see #75.
epoch,latestPrompt,sessionStatsandmeasuredTurnsinsrc/index.tshold one entry per session for the life of the server, and they're only cleared at compaction.latestPromptholds full prompt text.Change:
src/sessions.ts:SessionLruwithSESSION_CAP = 64, the same cap asrepokey.ts.message.updatedhandler, before anything is inserted.memory_statuscan't recreate an entry for an evicted session, becausebuildPayloadreturns beforestatsForwhen there's no epoch. Compaction only deletes.reason=firstepoch. It never gets stale state. The cost is one recompute for a session that sat idle while 64 others were active.systemDigest's signature isn't touched here. fix(inject): hold the frontier block and contextual pulls to injectBudget #66 converts it to the options object.Tests:
test/sessions.test.ts:SessionLruhonours its cap and LRU order, and callsonEvictonce per eviction.test/epoch.test.ts, through the real prompt/context hooks: afterSESSION_CAP + 1sessions, the first session gets no block on its next request and a secondfirstepoch on its next prompt. A session that kept being touched keeps its byte-identical block.With the eviction removed, both new tests fail.
Checks (Linux, Bun 1.4.4, on 0.8.4):
bun test ./test/304 pass, 4 skip, 0 fail.bun run test:e2eagainst opencode 2.0.26: 9 pass.tsc --noEmitis clean, andbiome lintexits 0 with warnings unchanged frommain. Nothing here is platform-specific.Merge order: independent of #62, #66, #67 and #76. I merged all of them together on 0.8.4 and they apply cleanly.
🤖 Generated with Claude Code