fix(agent): validate tool calls before persisting to prevent session poisoning (rebased)#14407
fix(agent): validate tool calls before persisting to prevent session poisoning (rebased)#14407Bartok9 wants to merge 1 commit into
Conversation
|
The test CI failure is pre-existing on |
…poisoning (v2, rebased) Malformed tool calls (empty function name, non-JSON arguments) can poison a session's history and cause repeated HTTP 400 errors on every subsequent turn when the broken history is replayed to strict providers. Adds `_is_valid_tool_call()` static method called in the tool-call persistence loop. Invalid tool calls are skipped with a warning log and never written to session history. Fixes NousResearch#4714
|
Rebased on current main ( |
4649275 to
d35b9d8
Compare
|
Test CI failure is pre-existing on main — verified at main |
|
The test CI failure is pre-existing on |
|
The test CI failure is pre-existing on |
|
Closing — this fix has landed on main via a subsequent PR or is superseded. Thanks for the review. |
Problem
Rebased version of #4724.
Malformed tool calls (empty function name, non-JSON arguments) silently enter session history and cause repeated HTTP 400 errors on every subsequent turn when that history is replayed to strict providers. The session becomes permanently broken — requiring /new to recover.
Root Cause
The tool-call persistence loop (
_build_assistant_message) did not validate tool calls before appending them to session history.Fix
Adds
_is_valid_tool_call()static method and calls it in the persistence loop. Invalid calls are logged as warnings and skipped:Validation checks:
functionattribute existsnameis a non-empty stringarguments(when present) is a non-empty string that parses as a JSON objectChanges
run_agent.py_is_valid_tool_call()static method + validation in persistence loopSupersedes #4724.