fix: repair orphaned toolUse in the last session message during restore#2073
Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: repair orphaned toolUse in the last session message during restore#2073Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Conversation
_fix_broken_tool_use skipped the last message with an explicit guard, relying on the agent-class fallback (_has_tool_use_in_latest_message). That fallback only works within the same process. When a new process restores a session that ended with an orphaned toolUse (e.g. after a runtime timeout), the guard causes the broken history to be sent to the model, producing a ValidationException. Remove the guard and handle the last-message case by appending a synthetic toolResult with status 'error'. The tool execution context is already lost at restore time, so letting the model decide how to proceed is the correct behavior. Updates the test that asserted the old (incorrect) behavior.
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.
Description
_fix_broken_tool_useexplicitly skipped the last message in the session history,relying on the agent-class fallback (
_has_tool_use_in_latest_message) to handleit. That fallback only works when the same agent instance re-enters the event loop
within the same process. When a different process restores a session that ended with
an orphaned
toolUse— for example, after a runtime timeout while waiting for along-running tool — and a new user message is then appended, the orphaned
toolUsereaches the model without a corresponding
toolResult, producing aValidationException.The fix removes the guard and handles the last-message case the same way as interior
messages: append a synthetic
toolResultwithstatus: "error". The original toolexecution context is already lost at restore time, so reporting an error to the model
and letting it decide how to proceed is the correct behavior.
Related Issues
Resolves #2025
Documentation PR
N/A
Type of Change
Bug fix
Testing
test_fix_broken_tool_use_ignores_last_message(which asserted the old,incorrect behavior) to
test_fix_broken_tool_use_repairs_orphaned_last_message,verifying that a synthetic
toolResultis appended.hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.