Skip to content

fix(desktop): recover session after sleep/wake gateway restart - #42688

Merged
teknium1 merged 2 commits into
mainfrom
fix/desktop-session-recovery-sleep-wake
Jun 9, 2026
Merged

fix(desktop): recover session after sleep/wake gateway restart#42688
teknium1 merged 2 commits into
mainfrom
fix/desktop-session-recovery-sleep-wake

Conversation

@teknium1

@teknium1 teknium1 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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 surrounding prompt.submit site moved under the remote-media-relay attachment-sync rewrite since the PR was authored).

Root cause

requestGateway retries transport errors (not connected / connection closed) but never gateway-level session not found (error 4001 from _sess_nowait in tui_gateway/server.py). After sleep/wake the WS reconnects but the gateway's in-memory _sessions dict is empty, so the held activeSessionId is stale and the first prompt.submit always 4001s.

Changes

  • apps/desktop/.../use-prompt-actions.ts: on session not found + a stored id, call session.resume (returns a fresh live session_id), update activeSessionIdRef, retry prompt.submit once. 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

Before After
First send after sleep/wake "session not found" bubble sends transparently
New recovery tests 3/3 pass
tsc -b clean

Pre-existing unrelated failure in this file ("clears a leftover interrupted flag") fails on clean origin/main too — out of scope here.

Infographic

nous-jewelcase

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/desktop-session-recovery-sleep-wake vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10608 on HEAD, 10608 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5560 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have labels Jun 9, 2026
daxxster and others added 2 commits June 9, 2026 02:47
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
teknium1 force-pushed the fix/desktop-session-recovery-sleep-wake branch from e25a8b7 to f53806c Compare June 9, 2026 09:47
@teknium1
teknium1 merged commit be2f739 into main Jun 9, 2026
23 checks passed
@teknium1
teknium1 deleted the fix/desktop-session-recovery-sleep-wake branch June 9, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants