Skip to content

fix(desktop): rebind sessions after websocket reconnect#41740

Closed
joshuadow wants to merge 1 commit into
NousResearch:mainfrom
joshuadow:fix/desktop-websocket-session-recovery
Closed

fix(desktop): rebind sessions after websocket reconnect#41740
joshuadow wants to merge 1 commit into
NousResearch:mainfrom
joshuadow:fix/desktop-websocket-session-recovery

Conversation

@joshuadow

@joshuadow joshuadow commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rebinds session.activate to the current WebSocket transport so parked live sessions are no longer treated as orphaned after reconnect.
  • Makes Desktop re-run route resume when the gateway transitions back to open, even if the selected stored session still has a cached runtime id.
  • Updates the Desktop TypeScript lib target to ES2023, matching existing findLast / findLastIndex usage so Desktop type-check validates cleanly.
  • Adds regression coverage for both the backend transport rebind and the Desktop reconnect route-resume path.

Why

When Windows Desktop connects to a WSL-hosted gateway, with or without a reverse proxy in the middle, the transport can drop while the backend process and stored sessions remain alive. The previous route guard treated the cached runtime id as authoritative after reconnect, so Desktop could continue using a stale runtime id and later surface session not found until restart.

Validation

  • python -m pytest tests/tui_gateway/test_protocol.py -q → 59 passed, 8 warnings (discord.player audioop deprecation)
  • npm run type-check from apps/desktop → passed
  • npm run test:ui -- --run src/app/session/hooks/use-route-resume.test.tsx from apps/desktop → 1 file passed, 3 tests passed
  • npx eslint src/app/session/hooks/use-route-resume.ts src/app/session/hooks/use-route-resume.test.tsx from apps/desktop → passed

@joshuadow joshuadow force-pushed the fix/desktop-websocket-session-recovery branch from 0d8f8c1 to e338dcc Compare June 8, 2026 03:15
@joshuadow joshuadow marked this pull request as ready for review June 8, 2026 03:16
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Jun 8, 2026
@OutThisLife

Copy link
Copy Markdown
Collaborator

Superseded by #43004, which keeps your fix as-is (authorship preserved) and adds a comment-only follow-up documenting the seenGatewayStateRef / gatewayBecameOpen guard. I validated the backend rebind against _ws_session_is_orphaned and re-ran the gateway tests, desktop type-check, and the route-resume vitest on top of current main (your tsconfig ES2023 bump already landed upstream). Thanks @joshuadow. Closing in favor of #43004.

@OutThisLife OutThisLife closed this Jun 9, 2026
OutThisLife added a commit that referenced this pull request Jun 9, 2026
…41740) (#43004)

* fix(desktop): rebind sessions after websocket reconnect

* docs(desktop): explain the reconnect-resume guard in use-route-resume

The reconnect fix turns on two subtle conditions with no inline rationale:
`seenGatewayStateRef` suppresses a spurious "became open" on the first effect
run (so a session mounting with the gateway already open doesn't double-resume),
and the `gatewayBecameOpen ||` arm forces a re-resume even when the route looks
`alreadyActive` because the cached runtime id can be stale after the gateway
rebinds/reaps the session. Comment both so the next reader doesn't "simplify"
them back into the original bug. No behavior change.

---------

Co-authored-by: Josh Dow <josh.dow@prepad.io>
wachoo pushed a commit to wachoo/hermes-agent that referenced this pull request Jun 10, 2026
…ousResearch#41740) (NousResearch#43004)

* fix(desktop): rebind sessions after websocket reconnect

* docs(desktop): explain the reconnect-resume guard in use-route-resume

The reconnect fix turns on two subtle conditions with no inline rationale:
`seenGatewayStateRef` suppresses a spurious "became open" on the first effect
run (so a session mounting with the gateway already open doesn't double-resume),
and the `gatewayBecameOpen ||` arm forces a re-resume even when the route looks
`alreadyActive` because the cached runtime id can be stale after the gateway
rebinds/reaps the session. Comment both so the next reader doesn't "simplify"
them back into the original bug. No behavior change.

---------

Co-authored-by: Josh Dow <josh.dow@prepad.io>
changman pushed a commit to changman/hermes-agent that referenced this pull request Jun 10, 2026
…ousResearch#41740) (NousResearch#43004)

* fix(desktop): rebind sessions after websocket reconnect

* docs(desktop): explain the reconnect-resume guard in use-route-resume

The reconnect fix turns on two subtle conditions with no inline rationale:
`seenGatewayStateRef` suppresses a spurious "became open" on the first effect
run (so a session mounting with the gateway already open doesn't double-resume),
and the `gatewayBecameOpen ||` arm forces a re-resume even when the route looks
`alreadyActive` because the cached runtime id can be stale after the gateway
rebinds/reaps the session. Comment both so the next reader doesn't "simplify"
them back into the original bug. No behavior change.

---------

Co-authored-by: Josh Dow <josh.dow@prepad.io>
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
…41740) (#43004)

* fix(desktop): rebind sessions after websocket reconnect

* docs(desktop): explain the reconnect-resume guard in use-route-resume

The reconnect fix turns on two subtle conditions with no inline rationale:
`seenGatewayStateRef` suppresses a spurious "became open" on the first effect
run (so a session mounting with the gateway already open doesn't double-resume),
and the `gatewayBecameOpen ||` arm forces a re-resume even when the route looks
`alreadyActive` because the cached runtime id can be stale after the gateway
rebinds/reaps the session. Comment both so the next reader doesn't "simplify"
them back into the original bug. No behavior change.

---------

Co-authored-by: Josh Dow <josh.dow@prepad.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) 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