fix(agent): catch persist errors in finalize_turn to avoid losing tur… - #43057
Closed
MorAlekss wants to merge 2 commits into
Closed
fix(agent): catch persist errors in finalize_turn to avoid losing tur…#43057MorAlekss wants to merge 2 commits into
MorAlekss wants to merge 2 commits into
Conversation
Contributor
|
Verification review — clean ✅ Reviewed the full diff including the new test file. The change wraps What I checked:
Design consideration: This is intentional graceful degradation — the user already received their response; persist failure should not crash the turn. The warning-level log ensures the failure is diagnosable from agent.log. No issues found. LGTM. |
This was referenced Jun 21, 2026
Contributor
|
Thanks for the focused persistence-failure fix. This is now implemented on current
Automated hermes-sweeper review. |
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
Wraps
_drop_trailing_empty_response_scaffoldingand_persist_sessionin
finalize_turn()with atry/exceptblock. When session persistencefails due to a disk or SQLite error, the turn result is still returned to
the caller instead of propagating an unhandled exception.
Root cause
finalize_turn()inagent/turn_finalizer.pycalls_drop_trailing_empty_response_scaffolding()and_persist_session()without any error handling. If
_persist_session()raises (e.g.OSError: disk full,sqlite3.OperationalError: database is locked),the exception propagates up through
run_conversation()with no catchat that level either. The caller receives an exception instead of the
expected
resultdict, the turn response is never delivered to theuser, and the session is not saved.
Behavioral change
Before: any exception in
_persist_session()causedfinalize_turn()to raise, losing the turn result and the user's response entirely.
After: exceptions from both
_drop_trailing_empty_response_scaffolding()and
_persist_session()are caught as a pair. Alogger.warningisemitted with the error details, and
finalize_turn()continues toreturn the
resultdict. The user receives the response for this turneven if the session was not persisted to SQLite.
What changed
agent/turn_finalizer.py_drop_trailing_empty_response_scaffoldingand_persist_session) intry/except Exception as exc: logger.warning(...)_persist_sessionis nevercalled with unclean messages if
_drop_trailing_empty_response_scaffoldingraises first
tests/agent/test_turn_finalizer.py(new file)test_finalize_turn_survives_persist_session_failure: patches_persist_sessionto raiseOSError("disk full"), verifies thatfinalize_turnreturns a validresultdict and emits the expectedwarning
What is NOT changed
finalize_turn()return contract unchanged: always returnsresultdict_persist_sessioninternals unchangedexcept Exceptionscope is consistent with the file's existinggraceful-degradation pattern used in
transform_llm_outputandpost_llm_callhooks