fix: repair broken tool_call arguments at the recovery write site - #16505
fix: repair broken tool_call arguments at the recovery write site#16505guigui0711 wants to merge 1 commit into
Conversation
Follow-up to NousResearch#15348 / 7a192b1. The loop-top _sanitize_tool_call_arguments pass repairs corrupted entries on the *next* iteration, but the recovery append at line 11911 still writes broken JSON into messages[] first. Repair at the write site so corrupted arguments never enter the persistent message history, eliminating the one-iteration window where broken data exists in the list. Ref: NousResearch#4662, NousResearch#14518 (prior PR, closed as covered by NousResearch#15348) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi @teknium1 @alt-glitch — this is the follow-up micro-improvement suggested in #14518, narrowly scoped to the recovery append site. Would appreciate a review when you have a chance 🙏 |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the narrowly scoped defense-in-depth follow-up. The underlying write-time gap still exists on current main: agent/conversation_loop.py:4519-4522 detects invalid arguments, and agent/conversation_loop.py:4571-4572 appends the built assistant message before recovery tool results are added.
Problems
- The live loop no longer resides in
run_agent.py. Commit053025238434cfbf121873977b39888d7f27d1c1extracted it toagent/conversation_loop.py; this PR'srun_agent.pyhunk will not affect the active recovery path. - The diff adds no regression coverage for the third-invalid-response recovery branch.
Suggested changes
- Apply the same repair to
recovery_assistantatagent/conversation_loop.py:4571, beforemessages.append()at line 4572. - Add an end-to-end loop test that reaches this branch and asserts the recovery assistant's persisted/replayed
tool_calls[*].function.argumentsare valid JSON while tool-call/result pairing remains intact.
Automated hermes-sweeper review.
|
|
||
| # Append the assistant message with its (broken) tool_calls | ||
| # Append the assistant message, repairing broken tool_call | ||
| # arguments at write time so corrupted JSON never enters |
There was a problem hiding this comment.
Current main extracted the live run_conversation loop into agent/conversation_loop.py; the active recovery branch is now at agent/conversation_loop.py:4571 (commit 053025238). Salvage this write-site repair there, before the assistant message is appended.
Summary
Follow-up micro-improvement to #15348 (
7a192b12), as suggested by @teknium1 in #14518:The loop-top
_sanitize_tool_call_arguments()pass (added in #15348) repairs corrupted entries on the next iteration, but the recovery append site still writes broken JSON intomessages[]first. This creates a one-iteration window where corrupted data exists in the list and can be persisted to session state.This PR repairs arguments at the write site using the existing
_repair_tool_call_arguments()helper, so corrupted JSON never enters the message history at all.Changes
run_agent.py:11911Ref: #4662, #14518
cc @alt-glitch
🤖 Generated with Claude Code