Skip to content

fix(tui): persist dashboard/TUI conversations on WS disconnect/restart - #62052

Merged
teknium1 merged 2 commits into
NousResearch:mainfrom
WilsonKinyua:fix/dashboard-session-persistence
Jul 10, 2026
Merged

fix(tui): persist dashboard/TUI conversations on WS disconnect/restart#62052
teknium1 merged 2 commits into
NousResearch:mainfrom
WilsonKinyua:fix/dashboard-session-persistence

Conversation

@WilsonKinyua

@WilsonKinyua WilsonKinyua commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Dashboard/TUI WebSocket conversations could contain many events yet be absent from state.db across a disconnect/restart. On teardown, _finalize_session is the safety-net that flushes any un-persisted transcript, but it called:

agent._persist_session(snapshot, conversation_history=history)

where snapshot (agent._session_messages) and history (session["history"]) reference the same list once a turn completes. Inside _flush_messages_to_session_db, every message whose identity appears in conversation_history is treated as already-durable and skipped — so the call wrote nothing. When _finalize_session was the sole persist path (e.g. an in-turn flush hit a transient SQLite failure, then the WS disconnected/the gateway restarted), the whole conversation was lost.

Fix

Flush agent._session_messages via _persist_session's intrinsic _DB_PERSISTED_MARKER dedup — the same contract the gateway-shutdown flush already uses (#13121):

  • Drop conversation_history=history (it aliased the snapshot and neutered the write).
  • Drop the or history fallback (it wrote a markerless copy of already-durable resumed rows → duplicates).

Markers persist the genuinely-unflushed tail while leaving durable rows untouched (including a resumed-but-not-run session's already-in-DB transcript), so no duplicates are appended.

Scope: reliability slice 1 only — no changes to cron, Telegram outbox, reconnect protocol, or monitoring. Stamping resumed history durable at load time is a noted follow-up (shared with the gateway path).

Test plan

New real-DB E2E tests in tests/tui_gateway/test_finalize_session_persist.py (drive the actual AIAgent flush against a real SessionDB — the prior tests only mocked _persist_session, so they asserted the call but not the write):

  • test_unflushed_turn_survives_disconnect — completed turn whose flush didn't durably land is persisted on disconnect (was 0 rows before the fix).
  • test_resumed_session_not_reflushed_as_duplicates — resumed, no turn run → no duplicate rows.
  • test_resumed_then_run_turn_not_duplicated — resumed and runs a turn: in-turn flush marker-stamps the loaded prefix, finalize re-appends nothing.

Mock-based contract tests updated to the corrected call shape.

Ran locally:

  • pytest tests/tui_gateway/test_finalize_session_persist.py14 passed
  • Broader: test_finalize_session_persist + test_13121_shutdown_inflight_transcript_flush + test_7100_transient_failure_transcript + test_42039_duplicate_user_message + test_hermes_state + test_empty_session_hygiene386 passed

Infographic

P1 reliability sweep

Copilot AI review requested due to automatic review settings July 10, 2026 12:01

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…s chat

finalize passed conversation_history=history aliasing the snapshot so flush
skipped every message and wrote nothing. now flush _session_messages via
marker dedup like gateway shutdown. add real db e2e tests.
@WilsonKinyua
WilsonKinyua force-pushed the fix/dashboard-session-persistence branch from 6d1f04f to 78daac8 Compare July 10, 2026 12:09
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/tui Terminal UI (ui-tui/ + tui_gateway/) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 10, 2026
@teknium1
teknium1 merged commit 35d777d into NousResearch:main Jul 10, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants