Skip to content

fix(anthropic): include Anthropic in tool call ID sanitization#13976

Open
omair445 wants to merge 1 commit intoopenclaw:mainfrom
omair445:fix/anthropic-tool-call-id-sanitize
Open

fix(anthropic): include Anthropic in tool call ID sanitization#13976
omair445 wants to merge 1 commit intoopenclaw:mainfrom
omair445:fix/anthropic-tool-call-id-sanitize

Conversation

@omair445
Copy link
Contributor

@omair445 omair445 commented Feb 11, 2026

Summary

Anthropic API rejects tool_use IDs that contain underscores (e.g. toolu_01XYZ), requiring IDs to match ^[a-zA-Z0-9-]+$. However, sanitizeToolCallIds only covers Google and Mistral — Anthropic is missing. This causes persistent API errors when tool call IDs from other providers contain invalid characters.

Fixes #13799

Root Cause

In transcript-policy.ts:

// Before (missing Anthropic)
const sanitizeToolCallIds = isGoogle || isMistral;

// After
const sanitizeToolCallIds = isGoogle || isMistral || isAnthropic;

The gateway logs "Tool calls will be sanitized on retry" but since sanitizeToolCallIds is false for Anthropic, the retry uses unsanitized IDs too — causing an infinite loop.

Behavior Changes

  • Anthropic provider now has sanitizeToolCallIds: true with toolCallIdMode: "strict"
  • Tool call IDs with underscores or other invalid chars get sanitized before sending to Anthropic
  • No change to OpenAI, Google, or Mistral behavior

Tests

9 new tests in transcript-policy.test.ts:

✓ src/agents/transcript-policy.test.ts (9 tests) 5ms

Covers sanitizeToolCallIds and toolCallIdMode for Anthropic, Google, Mistral, and OpenAI.

lobster-biscuit

Sign-Off

  • Models used: Claude Opus 4
  • Submitter effort: AI-assisted, verified provider detection logic
  • Agent notes: One-line fix with significant impact — prevents infinite retry loops on Anthropic

Greptile Overview

Greptile Summary

Added Anthropic to the list of providers that require tool call ID sanitization. The Anthropic API requires tool call IDs to match ^[a-zA-Z0-9-]+$ (no underscores), but sanitizeToolCallIds only covered Google and Mistral, causing retry loops when tool call IDs from other providers contained invalid characters. The one-line fix on transcript-policy.ts:98 now includes isAnthropic in the condition, and comprehensive tests verify the behavior for all major providers (Anthropic via both provider and modelApi, Google, Mistral, and OpenAI).

Confidence Score: 5/5

  • Safe to merge with minimal risk
  • One-line fix with clear intent, comprehensive test coverage (9 new tests), and consistent with existing provider detection patterns. The change is minimal, well-isolated, and matches the described issue perfectly.
  • No files require special attention

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 11, 2026
TWFBusiness added a commit to TWFBusiness/openclaw-tw that referenced this pull request Feb 11, 2026
…pstream fixes

- Remove Discord, Telegram, Slack, Signal, iMessage, BlueBubbles extensions
- Remove @buape/carbon, grammy, and other gateway-specific dependencies
- Add session-based login system (cookie auth, rate limiting)
- Add type stubs for optional deps (baileys, ciao, qrcode-terminal)
- Apply upstream PRs: XSS fix (openclaw#13952), orphan tool_results (openclaw#13974),
  Anthropic tool ID sanitization (openclaw#13976), BM25 score fix (openclaw#14005),
  redaction fix (openclaw#14006), subagent timeout (openclaw#13996), context window
  guard (openclaw#13986), model default reset (openclaw#13993), cache token accounting (openclaw#13853)
- Fix all TypeScript compilation errors from channel removal

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sanitizeToolCallIds excludes Anthropic, causing persistent tool_use.id format errors

1 participant

Comments