fix(cli): persist interrupted session transcript on SIGHUP/SIGTERM/window-close - #50004
Merged
Conversation
Contributor
🔎 Lint report:
|
Collaborator
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
finallyblock only forwarded_session_messagesto the memory provider and calledend_session()(which setsended_atbut writes no transcript). A terminal close, SSH disconnect, orkillmid-turn leftmessage_count = 0and no resumable transcript. Closes #6481.Changes
cli.py: new_persist_active_session_before_close()— flushes the agent's live_session_messages(falling back toconversation_history) via_persist_session()beforeend_session(), empty-guarded, syncsself.session_idfrom the agent. Called from the closefinallyblock right before SQLite session close.tests/cli/test_cli_shutdown_memory_messages.py: 3 regression tests (live transcript persisted,conversation_historyfallback, empty-transcript skip).Validation
message_count=0tests/cli/test_cli_shutdown_memory_messages.py— 7/7 pass.AIAgent+SessionDB, isolatedHERMES_HOME): simulated turn-1-flushed → in-flight turn-2 → close path → all 4 messages land instate.db,session_idsynced. 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