Skip to content

fix(compression): dedup duplicate tool_call_ids to prevent HTTP 400 on strict providers - #60270

Closed
isheng-eqi wants to merge 1 commit into
NousResearch:mainfrom
isheng-eqi:fix/compression-dedup-duplicate-tool-call-ids
Closed

fix(compression): dedup duplicate tool_call_ids to prevent HTTP 400 on strict providers#60270
isheng-eqi wants to merge 1 commit into
NousResearch:mainfrom
isheng-eqi:fix/compression-dedup-duplicate-tool-call-ids

Conversation

@isheng-eqi

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a context compression bug where duplicate tool_call_id values survive into the post-compression message list, causing strict providers (DeepSeek) to reject the API call with HTTP 400 and abort the session.

Related Issue

Fixes #58327

Type of Change

  • Bug fix

Changes Made

  • agent/context_compressor.py: Extend _sanitize_tool_pairs() with a dedup pass (step 1b) that removes duplicate tool results sharing the same tool_call_id. Walks the message list in reverse so the most recent result (closest to the tail) is always preserved.
  • tests/agent/test_context_compressor_tool_dedup.py: 6 tests covering single duplicates, multiple duplicates, no-op, dedup+orphan interaction, and non-tool message preservation

How to Test

  1. Run a long session with many tool calls on DeepSeek
  2. Trigger context compression
  3. Verify the session continues normally instead of aborting with HTTP 400 'Duplicate value for tool_call_id'

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 7, 2026
@isheng-eqi
isheng-eqi force-pushed the fix/compression-dedup-duplicate-tool-call-ids branch from 7f7b237 to 3143035 Compare July 7, 2026 15:45
@isheng-eqi

Copy link
Copy Markdown
Contributor Author

Branch contaminated — rebuilding with clean base from upstream/main.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

2 participants