Skip to content

fix(tui): keep Desktop sessions open across gateway reload - #95961

Closed
HexLab98 wants to merge 2 commits into
NousResearch:mainfrom
HexLab98:fix/95868-desktop-reload-session-delete
Closed

HexLab98 wants to merge 2 commits into
NousResearch:mainfrom
HexLab98:fix/95868-desktop-reload-session-delete

Conversation

@HexLab98

@HexLab98 HexLab98 commented Aug 27, 2026 •

Copy link
Copy Markdown

Summary

  • Desktop backend reloads (profile switch, WS 1012 service restart) were tearing down live chats as if the user had closed them: process-exit finalize stamped tui_shutdown, and the disconnect path still armed the WS-orphan reap against detached sessions (reaped_sessions=0, detached_sessions=N).
  • Populated Desktop/TUI rows now stay open through that bounce so the next process can list and resume them. tui_shutdown is treated as a recoverable accidental end for rows already stamped by older builds.
  • delete_session / delete_session_if_empty log id, reason, and whether the row had messages, so a silent hard-delete is greppable.

Fixes #95868

Test plan

  • scripts/run_tests.sh tests/tui_gateway/test_finalize_session_persist.py tests/test_empty_session_hygiene.py tests/tui_gateway/test_startup_orphan_sweep.py tests/test_tui_gateway_ws.py
  • scripts/run_tests.sh tests/test_tui_gateway_server.py tests/tui_gateway/test_session_reclaim_notify.py -k "close_sessions_for_transport or test_session_delete or reclaim"
  • Desktop: open several multi-turn chats, switch profiles (watch for ws closed ... code=1012 ... detached_sessions>0), switch back, confirm the original chats still appear and resume with history intact
  • sqlite3 state.db "SELECT id, ended_at, end_reason FROM sessions;" after the reload — pre-reload ids still present, ended_at null for the bounced chats
  • Explicit sidebar delete still removes the row and logs delete_session id=... reason=session.delete (or api.sessions.delete)

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) comp/desktop Electron desktop app (apps/desktop/*) area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 27, 2026
Process-exit teardown was ending every live chat with tui_shutdown, and a
WS 1012 service restart still armed the orphan reap. Neither path is a
user delete, so populated Desktop rows must stay resumable after a
profile-switch backend bounce. Log hard-deletes with a reason so a silent
row loss is greppable.
@teknium1

Copy link
Copy Markdown
Collaborator

Closing as superseded on main. The delete vector this PR targeted (non-empty Desktop session rows being hard-deleted during a gateway reload, #95868) was fixed on main through a different design:

Your alternative (never stamping tui_shutdown, treating it as recoverable) now conflicts semantically with main's lease-guard architecture, and the branch is ~880 commits behind with conflicts in every core file. Your diagnosis of the reload delete vector was correct and early — thank you. One still-useful piece of this PR is audit logging on delete_session/delete_session_if_empty (id/reason/had-messages); if you'd like to resubmit that as a small fresh PR against current main, it would be welcome.

@teknium1 teknium1 closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/cli CLI entry point, hermes_cli/, setup wizard comp/desktop Electron desktop app (apps/desktop/*) comp/tui Terminal UI (ui-tui/ + tui_gateway/) P1 High — major feature broken, no workaround 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: active non-empty sessions silently hard-deleted from sessions table during gateway reload (detached_sessions>0, no delete_session call logged)

3 participants