fix(agent): preserve tool_name on sanitizer-injected stub tool results - #29185
Open
soynchux wants to merge 1 commit into
Open
fix(agent): preserve tool_name on sanitizer-injected stub tool results#29185soynchux wants to merge 1 commit into
soynchux wants to merge 1 commit into
Conversation
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the remaining manual stub construction.
Problems
agent/conversation_loop.py:792-905builds and sanitizes anapi_messagescopy, whilerun_agent.py:1692-1695persists the canonicalmessageslist. The proposedtool_nametherefore cannot reach the session DB or JSON log.- More importantly,
agent/chat_completion_helpers.py:1705-1708stripstool_namebeforeagent/chat_completion_helpers.py:1728runs this sanitizer, and then sends the result directly atagent/chat_completion_helpers.py:1852. Replacing the stub withmake_tool_result_message()would re-addtool_name;agent/transports/chat_completions.py:159-163documents that strict providers reject it.
Suggested changes
- Keep this API-bound stub schema-only, or strip
tool_nameagain after sanitization on direct-request paths. If persistence is the target, trace the canonical message construction path and add an end-to-end persistence regression instead.
Automated hermes-sweeper review.
| "content": "[Result unavailable — see context summary above]", | ||
| "tool_call_id": cid, | ||
| }) | ||
| patched.append(make_tool_result_message( |
Contributor
There was a problem hiding this comment.
sanitize_api_messages() operates on the per-request API copy, not the persisted history. In the iteration-summary path, tool_name is deliberately stripped before this sanitizer and the request then bypasses ChatCompletionsTransport; this helper would add tool_name back and strict providers reject that schema-foreign field. Keep this stub API-schema-only rather than using make_tool_result_message() here.
This was referenced Aug 3, 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.
What
Use
make_tool_result_message()when_sanitize_api_messages()injects a stub tool result for an assistant tool call whose result is missing.This keeps sanitizer-generated tool messages consistent with normal tool execution messages by including both:
namefor provider/wire-format compatibilitytool_namefor internal session DB and JSON session log persistenceWhy
Recent fixes made tool result construction populate
tool_namesostate.db, JSON session logs, and tool-aware search do not get blank tool names.The pre-call sanitizer still had one manual stub-message path that only set
name,content, andtool_call_id. If that path ran after a missing/dropped tool result, the generated stub could still persist with an emptytool_name.Testing
Ran targeted tests on Windows with thread-based pytest timeout override: