Skip to content

[codex] Fix desktop stale WebSocket prompt timeout - #40168

Draft
Tamaz-sujashvili wants to merge 1 commit into
NousResearch:mainfrom
Tamaz-sujashvili:codex/fix-desktop-stale-ws-session-busy
Draft

[codex] Fix desktop stale WebSocket prompt timeout#40168
Tamaz-sujashvili wants to merge 1 commit into
NousResearch:mainfrom
Tamaz-sujashvili:codex/fix-desktop-stale-ws-session-busy

Conversation

@Tamaz-sujashvili

Copy link
Copy Markdown
Contributor

Fixes #40164.

Summary

  • Close stale desktop JSON-RPC WebSockets when an RPC request times out.
  • Reconnect using the gateway client's actual connection state.
  • Treat a prompt.submit timeout as accepted when session.status confirms the backend turn is running.
  • Rebind live TUI session transports to the current WebSocket on session-scoped requests.
  • Add frontend and backend regression coverage.

Root Cause

After idle time, the desktop WebSocket could become stale. The backend accepted prompt.submit, but failed to send the response over the old socket, producing request timed out: prompt.submit in the renderer. Later sends hit the still-running backend and surfaced as session busy.

Validation

  • npm --workspace apps/desktop run test:ui -- src/lib/json-rpc-gateway.test.ts
  • npm --workspace apps/desktop run type-check
  • scripts/run_tests.sh tests/test_tui_gateway_server.py -- -k session_lookup_rebinds_current_transport

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Jun 5, 2026
@alt-glitch alt-glitch added the comp/desktop Electron desktop app (apps/desktop/*) label Jun 26, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for targeting a real stale-transport failure mode. Current apps/shared/src/json-rpc-gateway.ts:267-273 still rejects a timed-out RPC without closing the socket, while apps/desktop/src/app/gateway/hooks/use-gateway-request.ts:104-116 only reconnects for disconnected/closed errors.

Problems

  • The Desktop submit implementation moved after this branch: apps/desktop/src/app/session/hooks/use-prompt-actions.ts no longer exists on main. The active flow is apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts:337-381, which already has selected-session timeout recovery, and apps/desktop/src/hermes.ts:74-82, which gives prompt.submit a 1,800,000 ms timeout. The proposed status path needs to be integrated with that current behavior.
  • apps/desktop/src/lib/json-rpc-gateway.test.ts proves socket closure only. It does not exercise the accepted-submit/lost-response/reconnect path or guard against duplicate submission.

Suggested changes

  • Port the behavior to the current submit pipeline and add an end-to-end unit regression for that sequence.

Automated hermes-sweeper review.

@@ -320,7 +339,19 @@ export function usePromptActions({
await syncImageAttachmentsForSubmit(sessionId, attachments, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This submit hook was extracted on current main: the live path is now apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts:337-381, which already resumes and retries selected stored sessions after a timeout. Please port and reconcile this recovery there rather than applying the old-hook logic unchanged.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@100yenadmin

Copy link
Copy Markdown

The still-relevant Desktop heartbeat and reconnect-recovery behavior from this PR has been adapted to the current shared gateway architecture in #83166. Tamaz Sujashvili is credited in the combined PR and as a co-author on the synthesized integration commit. This cross-link does not close or rewrite this PR.

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/*) comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages 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 chat can get stuck busy after idle WebSocket prompt timeout

4 participants