Skip to content

fix: Desktop session lost after sleep/wake — WS orphan reap grace (20s) too short #44183

@xiaoxianjj

Description

@xiaoxianjj

Problem

When a Mac sleeps with Hermes Desktop open, the WebSocket connection drops. The TUI gateway parks the session but reaps it after only 20 seconds (HERMES_TUI_WS_ORPHAN_REAP_GRACE_S). On wake, Desktop holds a stale runtime session ID — any action (send message, interrupt) 404s with "session not found".

The Desktop frontend already has retry logic (use-prompt-actions.ts:667-686) that catches the 404, calls session.resume to re-register, and retries once. This means the team already knows this race exists — but the grace window is still far too short for real-world sleep durations (minutes to hours).

Steps to Reproduce

  1. Open Hermes Desktop with an active session
  2. Close the MacBook lid (sleep) for >20 seconds
  3. Wake the Mac
  4. Try to send a message in the existing session
  5. Observe "session not found" error (may recover via retry, may not)

Root Cause

tui_gateway/server.py:146-162:

_WS_ORPHAN_REAP_GRACE_S = 20.0  # default

This grace was designed to prevent leaked _SlashWorker processes from browser refreshes (#38591), not to handle sleep/wake. For sleep/wake, 20s is effectively instant.

Environment

  • Hermes Desktop (Electron) on macOS
  • Gateway: embedded TUI gateway
  • Reproducible: every sleep/wake cycle >20s

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/tuiTerminal UI (ui-tui/ + tui_gateway/)type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions