Skip to content

fix: normalize tool_call_id whitespace in sanitizer#10039

Open
nightq wants to merge 1 commit into
NousResearch:mainfrom
nightq:fix/issue-9999-sanitizer-whitespace
Open

fix: normalize tool_call_id whitespace in sanitizer#10039
nightq wants to merge 1 commit into
NousResearch:mainfrom
nightq:fix/issue-9999-sanitizer-whitespace

Conversation

@nightq

@nightq nightq commented Apr 15, 2026

Copy link
Copy Markdown

Summary

Fixes tool result misclassification when tool_call_id has leading/trailing whitespace.

Root Cause

_sanitize_api_messages() compared raw tool_call_id strings without stripping whitespace. When assistant-side IDs (via _get_tool_call_id_static) and tool-result IDs diverged due to surrounding whitespace, valid tool results were treated as orphaned and replaced with stub placeholders.

Fix

  • Strip whitespace in _get_tool_call_id_static() for both dict and object tool_calls
  • Strip whitespace when collecting result_call_ids from tool messages
  • Strip whitespace when filtering orphaned results

Test Plan

  • Relevant unit tests pass (9/9 in test_agent_guardrails.py)
  • New regression tests: whitespace-preserved tool results, orphaned whitespace still removed

Closes #9999

Fixes NousResearch#9999

Root cause: _sanitize_api_messages compared raw tool_call_id strings
without stripping whitespace, causing valid tool results to be treated
as orphaned when IDs had leading/trailing spaces.
Fix: strip whitespace in _get_tool_call_id_static and when collecting
result_call_ids from tool messages.
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #10000 — same fix: normalize tool_call_id whitespace in run_agent sanitizer to prevent orphaned tool results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run_agent sanitizer misclassifies tool results when tool_call_id has surrounding whitespace

2 participants