Repository navigation
Conversation
There was a problem hiding this comment.
The change looks sound and fixes the problem. I ran the #65822 reproduction from source against a mock OpenAI-compatible gateway that rejects replayed tool names over 64 characters. On the base, the unknown-tool call is replayed under a 70-character name and the next request fails with Member must have length less than or equal to 64. With this PR, it is replayed as tools__websearch-demo-agent____websearch-web-search-tool___WebSe (64 characters) and the session goes on. I also checked the Responses lowering on the OpenAI Responses route, which keeps native namespaces: declared namespaced tools keep their name and namespace, including one added and later removed mid-conversation, and custom tools are unchanged. The nearby provider, tool-update and compile tests pass (1564, 0 fail), and tsc --noEmit passes for packages/ai.
The public API is unchanged. replayToolName is a new export of the internal ProviderShared module only.
No blocking concerns. Two notes: cutting names to 64 characters can make two different made-up names identical, which is harmless because results are matched by call ID. And #65739 rewrites this tool-name code, so whichever PR lands second will need to carry the 64-character limit over.
Related: #54146
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Thanks for flagging — I've updated the PR description to follow the PR template (issue link, type of change, description, verification, checklist). Please let me know if anything is still missing. |
|
Thanks for the update. My review didn't ask for any changes. The fix worked when I ran the #65822 reproduction, the nearby tests pass, and I had no blocking concerns, so nothing is missing from my side. The PR template request seems to come from a separate check (the |
A model sometimes calls a tool no one declares, under a made-up name. That call is stored and replayed on later requests, and providers cap tool names at 64 characters (OpenAI, Anthropic, Bedrock Converse, Gemini). The replayed name was sanitized but never truncated, so the next request was rejected and the session died (anomalyco#65822). Cap undeclared replayed names at 64 characters in the shared replay helper used by flattenRequest, which covers every protocol without native namespaces, and apply the same rule in the Responses lowering, which keeps native namespaces and never sees flattenRequest. Declared names are kept as-is. This is complementary to anomalyco#59915, which only normalizes the characters. Fixes anomalyco#65822
7a2e19d to
47d03fb
Compare
Issue for this PR
Closes #65822
Type of change
What does this PR do?
A model sometimes calls a tool no one declares, under a made-up name. That call is stored and replayed on later requests, and providers cap tool names at 64 characters (OpenAI, Anthropic, Bedrock Converse, Gemini). The replayed name was sanitized but never truncated, so the next request was rejected and the session died.
Changes
packages/ai/src/protocols/shared.ts: newreplayToolNamehelper — a declared name is kept as-is, anything else is sanitized to provider-accepted characters and truncated to 64 characters.flattenToolNameuses it, so every protocol without native namespaces (OpenAI Chat, Anthropic, Gemini, Mistral, Bedrock Converse, ...) replays unknown calls under a valid name. The Bedrock direct path already sliced calls to 64 in its own lowering; this makes the gateway/OpenAI-compatible path match.packages/ai/src/protocols/open-responses.ts: Responses routes keep native namespaces, so they never seeflattenRequest.lowerToolCallapplies the same rule (declared tools keep name and namespace, custom tools keep their own name).Complementary to #59915, which only normalizes the characters; this caps the length. No feature flag: this is a fix, per the repo guide.
How did you verify your code works?
packages/ai/test/provider/openai-chat.test.tsusing the exact made-up name from the issue (70 chars sanitized → replayed at 64), plus a 65-char name and a declared name kept as-is; the recorded history is asserted unmutated.packages/ai/test/provider/conversation-lowering.test.tsfor the Responses lowering.packages/aisuite: 2289 pass, 29 skip, 0 fail.bun run checkfrom the repo root: 36/36 tasks successful.Screenshots / recordings
Not a UI change.
Checklist
Added by the opencode bot (AI-generated).
Related: #54146