fix(desktop): recover session after sleep/wake gateway restart - #42688
Merged
Conversation
Contributor
🔎 Lint report:
|
When the laptop sleeps and wakes, the WebSocket reconnects but the
gateway's in-memory session table is cleared. The desktop app still
holds the old activeSessionId, so the next prompt.submit call returns
error 4001 ('session not found'), surfaced to the user as:
'Prompt failed: session not found'
Fix: wrap prompt.submit in a try/catch. On 'session not found', call
session.resume with the durable SQLite session ID (selectedStoredSessionIdRef)
to re-register the session in the gateway, update activeSessionIdRef to
the fresh live session_id, then retry prompt.submit once.
If recovery fails or the error is unrelated, the original error is
re-thrown and surfaces normally.
Adds three vitest cases for the recovery path: resume+retry on "session not found", no-resume passthrough on other errors, and no-resume when there is no stored session id. Also maps the contributor's commit email in release.py AUTHOR_MAP.
teknium1
force-pushed
the
fix/desktop-session-recovery-sleep-wake
branch
from
June 9, 2026 09:47
e25a8b7 to
f53806c
Compare
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.
Summary
The desktop app now recovers transparently when a sleep/wake gateway restart clears the in-memory session table — the first message after wake sends instead of failing with "Prompt failed: session not found".
Salvage of #40776 by @bpasquini onto current
main(the surroundingprompt.submitsite moved under the remote-media-relay attachment-sync rewrite since the PR was authored).Root cause
requestGatewayretries transport errors (not connected/connection closed) but never gateway-levelsession not found(error 4001 from_sess_nowaitintui_gateway/server.py). After sleep/wake the WS reconnects but the gateway's in-memory_sessionsdict is empty, so the heldactiveSessionIdis stale and the firstprompt.submitalways 4001s.Changes
apps/desktop/.../use-prompt-actions.ts: onsession not found+ a stored id, callsession.resume(returns a fresh livesession_id), updateactiveSessionIdRef, retryprompt.submitonce. One-shot — any other error re-throws and surfaces normally.apps/desktop/.../use-prompt-actions.test.tsx: three vitest cases (resume+retry, non-recoverable passthrough, no-stored-id short-circuit).scripts/release.py: map contributor commit email →bpasquini.Layering
Complements the already-merged
cadb74ada("recover chat after sleep/wake by revalidating a stale remote backend"), which reconnects the transport. This fix runs one level up: it re-registers the session the reconnect orphaned. Not a replacement — disjoint files, sequential failure points.Validation
tsc -bPre-existing unrelated failure in this file ("clears a leftover interrupted flag") fails on clean
origin/maintoo — out of scope here.Infographic