fix: self-heal sessions evicted from the backend (Session is not active -32004) - #69
Merged
Merged
Conversation
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.
Problem
Replying to a conversation in the editor sometimes failed with:
while remote clients saw the same session as empty (the editor still
showed its local copy of the history).
Root cause (verified against live backend)
The zcode backend evicts idle resident runtimes after ~10 minutes
(observed log:
session.resident_deactivated,reason: "idle_timeout",idleTimeoutMs: 600000) and also keeps an LRU cap on residents. An evictedsession fails every session-scoped RPC with
-32004while the sessionfile stays intact:
session/resumesession/readsession/messagesfetchMessagesswallows → empty replay (the "remote sees empty session" symptom)session/subscribesession/resumeThe bridge trusted in-memory state forever:
sessionMapreturned the stalesid from
prompt(), and a stalebackendLoadedSessionsflag madesession/loadskip the backend resume RPC.Fix — self-healing on every entry point
prompt(): onSession is not activefrom subscribe →session/resumereload → re-baseline the differ (so turn completion doesn't diff-replay the
whole history) → retry the subscribe once. Other errors propagate unchanged.
BACKEND_RESIDENT_TTL_MS= 5min, halfthe eviction window):
session/load·resumestop trusting staleverifications and re-issue the resume RPC; timestamps refresh on subscribe
success and turn completion.
ensureRealSession(): config/slash/extension entry points reload astale mapping before use — skipped while a turn is in flight (a running
turn proves the resident is live), fail-safe on reload failure.
Testing
tests/session-eviction.test.ts(8 cases): prompt recovery + re-baseline,non-eviction error propagation, recovery-resume failure propagation, TTL
expiry, stale-mapping reload, in-flight skip, fail-safe.
docs/TROUBLESHOOTING.md: dedicated-32004entry (also corrected thesubscribe timeout retry numbers).