Skip to content

fix(workers-ai-provider): remove tool_call_id sanitization#446

Merged
threepointone merged 1 commit intomainfrom
fix/remove-sanitize-tool-call-id
Mar 18, 2026
Merged

fix(workers-ai-provider): remove tool_call_id sanitization#446
threepointone merged 1 commit intomainfrom
fix/remove-sanitize-tool-call-id

Conversation

@threepointone
Copy link
Collaborator

Summary

  • Remove sanitizeToolCallId() which truncated all tool call IDs to 9 alphanumeric chars, causing every tool call ID to collide to chatcmplt after round-trip
  • Simplify normalizeMessagesForBinding() to only handle content: null → "" normalization
  • Update tests to verify IDs pass through unchanged

This mirrors the same fix applied to @cloudflare/tanstack-ai in #424. The binding's [a-zA-Z0-9]{9} validation has been relaxed upstream, confirmed by e2e tool round-trip tests passing across all 10 models without sanitization.

Test plan

  • 204 unit tests pass
  • 133/134 e2e tests pass (1 unrelated Mistral Small structured output timeout)
  • All tool call and tool round-trip e2e tests pass across all models (binding + REST)

Made with Cursor

Remove the sanitizeToolCallId helper and the code that normalized tool_call_id and tool_calls[].id to a 9-char alphanumeric form. That truncation caused different IDs to collide after a round-trip, so the sanitization was removed to preserve original IDs. Tests were updated: sanitizeToolCallId unit tests were removed, normalizeMessagesForBinding tests now assert tool_call_id and tool_calls[].id are passed through unchanged, add a test for null content -> empty string, and adjust mutation checks. A changeset was added to publish this as a patch.
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 3c35051

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
workers-ai-provider Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 18, 2026

Open in StackBlitz

npx https://pkg.pr.new/cloudflare/ai/ai-gateway-provider@446
npx https://pkg.pr.new/cloudflare/ai/@cloudflare/tanstack-ai@446
npx https://pkg.pr.new/cloudflare/ai/workers-ai-provider@446

commit: 3c35051

@threepointone threepointone merged commit bc16d6a into main Mar 18, 2026
3 checks passed
@threepointone threepointone deleted the fix/remove-sanitize-tool-call-id branch March 18, 2026 23:20
@github-actions github-actions bot mentioned this pull request Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant