Skip to content

fix(cli): persist interrupted session transcript on SIGHUP/SIGTERM/window-close - #50004

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-68e09a57
Jun 21, 2026
Merged

fix(cli): persist interrupted session transcript on SIGHUP/SIGTERM/window-close#50004
teknium1 merged 1 commit into
mainfrom
hermes/hermes-68e09a57

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

CLI conversations survive SIGHUP/SIGTERM/window-close — the interrupted in-flight turn is now flushed to SQLite + the JSON log before the session is marked closed.

Previously the shutdown finally block only forwarded _session_messages to the memory provider and called end_session() (which sets ended_at but writes no transcript). A terminal close, SSH disconnect, or kill mid-turn left message_count = 0 and no resumable transcript. Closes #6481.

Changes

  • cli.py: new _persist_active_session_before_close() — flushes the agent's live _session_messages (falling back to conversation_history) via _persist_session() before end_session(), empty-guarded, syncs self.session_id from the agent. Called from the close finally block right before SQLite session close.
  • tests/cli/test_cli_shutdown_memory_messages.py: 3 regression tests (live transcript persisted, conversation_history fallback, empty-transcript skip).

Validation

Before After
SIGHUP/SIGTERM mid-turn transcript lost, message_count=0 turn flushed to SQLite + jsonl
Idle startup→quit (n/a) no empty session write
  • Targeted suite: tests/cli/test_cli_shutdown_memory_messages.py — 7/7 pass.
  • E2E (real AIAgent + SessionDB, isolated HERMES_HOME): simulated turn-1-flushed → in-flight turn-2 → close path → all 4 messages land in state.db, session_id synced. The fix correctly triggers a final flush on the abnormal exit path while honoring the existing identity-based dedup (no double-writes of already-flushed messages).

Salvaged from #26894 by @haran2001 (commit cherry-picked, authorship preserved).

Infographic

session-persistence-on-hard-exit

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-68e09a57 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11283 on HEAD, 11283 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5916 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround labels Jun 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #6481 (root-cause issue — CLI session messages lost on SIGTERM/SIGHUP/window close) and #26894 (the salvaged community PR, authorship preserved). TUI counterpart: #50003.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: session messages lost on SIGTERM/SIGHUP/window close

2 participants