Repository navigation
fix(sse): normalize OpenAI tool-call IDs longer than 64 characters - #16490
Merged
diegosouzapw merged 2 commits intoOct 13, 2026
Merged
diegosouzapw merged 2 commits into
diegosouzapw merged 2 commits into
Conversation
The official OpenAI Chat Completions API rejects tool-call IDs longer than 64
characters ("string too long ... maximum length 64"), and clients such as
Cursor replay longer IDs minted elsewhere. For the first-party `openai`
provider only, each distinct overlong ID is now rewritten once per request to
`<sanitized 20-char prefix>_<sha256 base64url>` (64 chars, [A-Za-z0-9_-]),
keeping assistant `tool_calls[].id` and `tool.tool_call_id` linked in any
order. The digest covers the full ID, so IDs sharing a long prefix never
collide, and the mapping is deterministic across turns. IDs of 64 characters
or fewer, and every other provider, are untouched.
The helper lives in a new leaf module and is copy-on-write, so the caller's
body (shared with logging/replay/combo fallback) is never mutated.
Co-authored-by: mwpn <wirapratamaindonesia@gmail.com>
Inspired-by: decolua/9router#3167
Contributor
CI Coverage Report
Coverage artifact was not available for this run. |
diegosouzapw
deleted the
fix/port-pr-3167-openai-overlong-tool-call-ids
branch
October 18, 2026 23:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Invalid 'messages[N].tool_calls[0].id': string too long. Expected a string with maximum length 64). Clients such as Cursor replay longer IDs minted elsewhere, so multi-turn tool conversations routed to theopenaiprovider fail with a 400.openaiprovider only, every distinct overlong ID is now rewritten once per request to<sanitized 20-char prefix>_<sha256 base64url>(exactly 64 chars,[A-Za-z0-9_-]), keepingassistant.tool_calls[].idandtool.tool_call_idlinked. IDs of 64 chars or fewer, and every other provider (openrouter,openai-compatible-*, azure-openai, nvidia), are untouched.Attribution
Thanks to @mwpn for the original implementation.
Changes
open-sse/executors/default/openaiToolCallIds.ts(new leaf):normalizeOpenAIToolCallIds()— request-scoped map, so repeated IDs and tool results that precede their assistant call map identically; full-ID SHA-256 digest, so IDs that share a long prefix never collide; deterministic across turns. Copy-on-write: the caller's body/messages (shared with logging, replay and combo fallback) are never mutated.open-sse/executors/default.ts: one-line wiring inDefaultExecutor.transformRequest()next to the existing NVIDIA tool-call-ID normalization (net line count unchanged, file stays at its frozen ceiling of 1213).max_tokens → max_completion_tokenshalf of the original change already exists here and was not re-ported.tests/unit/openai-tool-call-id-normalization.test.ts: 10 cases (86-char ID linked on both sides, 64-char ID untouched, repeated IDs, result-before-call ordering, shared-prefix collision, unsafe-char prefix sanitizing, determinism, no mutation of the caller body, openrouter / openai-compatible untouched).Test plan
node --import tsx/esm --test tests/unit/openai-tool-call-id-normalization.test.ts→ℹ tests 10 ℹ pass 4 ℹ fail 6ℹ tests 10 ℹ pass 10 ℹ fail 0tests/unit/nvidia-tool-compatibility-2840.test.ts→ℹ tests 7 ℹ pass 7 ℹ fail 0DefaultExecutor/executors/default(node --import tsx/esm --test --test-concurrency=4 …) →ℹ tests 1012 ℹ pass 1012 ℹ fail 0npx eslint --suppressions-location config/quality/eslint-suppressions.json <changed files>→ exit 0;npx prettier --check <changed files>→ all formattednpm run typecheck:core→ exit 0GITHUB_BASE_REF=release/v3.8.52 npm run check:test-masking→OK — 0 modificado(s) … sem enfraquecimento;check-pr-test-policy.mjs(PR context) →Result: PASSnpm run check:file-size→default.tswithin its ceiling; the only violation (open-sse/services/combo/executeTargetAttempt.ts 1288 > 1284) is pre-existing on the base and untouched here