Skip to content

fix(desktop): preserve active chat on reconnect - #53522

Closed
0disoft wants to merge 1 commit into
NousResearch:mainfrom
0disoft:task/desktop-reconnect-resume-session
Closed

fix(desktop): preserve active chat on reconnect#53522
0disoft wants to merge 1 commit into
NousResearch:mainfrom
0disoft:task/desktop-reconnect-resume-session

Conversation

@0disoft

@0disoft 0disoft commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep Desktop from treating a sleep/wake WebSocket reconnect on the new-chat route as an explicit New Session action
  • preserve the active runtime session when the gateway transitions back to open and the current draft is not a fresh blank draft
  • add a useRouteResume regression test for the closed -> open reconnect path

Root cause

On /, useRouteResume used activeSessionId as a reason to call startFreshSessionDraft() whenever the gateway was open. After a Windows sleep/wake reconnect, the renderer can still hold the active runtime session while the socket transitions back to open, so that branch could clear the active chat and create a fresh draft instead of preserving the session.

Fixes #53374.

Tests

  • npm --workspace apps/desktop run test:ui -- src/app/session/hooks/use-route-resume.test.tsx — 13 passed
  • npm --workspace apps/desktop run typecheck — passed
  • npm --workspace apps/desktop run lint -- src/app/session/hooks/use-route-resume.ts src/app/session/hooks/use-route-resume.test.tsx — passed with existing blank-line warnings in unrelated files
  • git diff --check — passed with CRLF warnings only

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Preserves the active chat session when the desktop app reconnects after a sleep/wake cycle. Previously, a WS reconnect on /new would turn into an explicit New Session action, losing the user's current chat.

Looks Good

  • The fix is a single early-return guard: if we're on /new, the gateway just became open, there's an active session, and no fresh draft is ready, skip the new-session logic
  • Clean condition: isNewChatRoute && gatewayBecameOpen && activeSessionId && !freshDraftReady
  • Test exercises the exact scenario: gateway state transitions from closed to open while an active session exists
  • Minimal 55-line addition, well-scoped

Reviewed by Hermes Agent

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/desktop Electron desktop app (apps/desktop/*) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jun 27, 2026
@0disoft 0disoft closed this by deleting the head repository Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop GUI creates new session after Windows sleep (WebSocket disconnect, session context lost)

3 participants