fix(acp): atomic session persistence via replace_messages (salvage #13675)#20279
Merged
Conversation
ACP's save_session() did a non-atomic clear_messages() + append_message() loop. If any message hit an exception mid-loop (bad tool_call shape, etc.), the DELETE had already committed and the persisted conversation was lost. SessionDB.replace_messages() wraps DELETE + bulk INSERT in a single BEGIN IMMEDIATE transaction that rolls back on any exception, so a bad message can no longer clobber previously-persisted history. Salvages @Awsh1's PR #13675 — uses the existing replace_messages() helper (which covers more message fields than the PR's own copy) instead of adding a duplicate.
…ssages on encode failure
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.
Salvages @Junass1's PR #13675 onto current main with a simpler implementation.
What it does
ACP's
save_session()rewrote the transcript viaclear_messages()+ a loop ofappend_message()calls. If any message hit an exception mid-loop (badtool_callsshape, encoding error, etc.), the DELETE had already committed and the persisted conversation was lost.Changes
acp_adapter/session.py— replace the clear+loop with a singledb.replace_messages(state.session_id, state.history)call.SessionDB.replace_messages()already exists on current main (added for /retry, /undo, /compress) and wraps DELETE + bulk INSERT in aBEGIN IMMEDIATEtransaction that rolls back on exception.tests/acp/test_session.py— new regression test asserting a mid-encode failure leaves the previously-persisted transcript intact.scripts/release.py— AUTHOR_MAP entry for Junass1.Reshape vs. original
The original PR added its own
replace_messagestohermes_state.py. Main now already has a more comprehensivereplace_messages(handlescodex_message_items,reasoning_content, role-gated fields). Re-wiring ACP to use the existing helper gives the contributor's safety guarantee with less code and no duplication.Authorship preserved on the
acp_adapter/session.pycommit.Validation
tests/acp/test_session.py— 40 passed locally.Closes #13675 via salvage.