Skip to content

fix(sse): normalize OpenAI tool-call IDs longer than 64 characters - #16490

Merged
diegosouzapw merged 2 commits into
release/v3.8.52from
fix/port-pr-3167-openai-overlong-tool-call-ids
Oct 13, 2026
Merged

diegosouzapw merged 2 commits into
release/v3.8.52from
fix/port-pr-3167-openai-overlong-tool-call-ids

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Summary

  • The official OpenAI Chat Completions API rejects tool-call IDs longer than 64 characters (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 the openai provider fail with a 400.
  • For the first-party openai provider 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_-]), keeping assistant.tool_calls[].id and tool.tool_call_id linked. 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 in DefaultExecutor.transformRequest() next to the existing NVIDIA tool-call-ID normalization (net line count unchanged, file stays at its frozen ceiling of 1213).
  • The max_tokens → max_completion_tokens half 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

  • New test fails before the fix: node --import tsx/esm --test tests/unit/openai-tool-call-id-normalization.test.ts → ℹ tests 10 ℹ pass 4 ℹ fail 6
  • Same test after the fix → ℹ tests 10 ℹ pass 10 ℹ fail 0
  • NVIDIA regression: tests/unit/nvidia-tool-compatibility-2840.test.ts → ℹ tests 7 ℹ pass 7 ℹ fail 0
  • All 121 unit test files that reference DefaultExecutor / executors/default (node --import tsx/esm --test --test-concurrency=4 …) → ℹ tests 1012 ℹ pass 1012 ℹ fail 0
  • npx eslint --suppressions-location config/quality/eslint-suppressions.json <changed files> → exit 0; npx prettier --check <changed files> → all formatted
  • npm run typecheck:core → exit 0
  • GITHUB_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: PASS
  • npm run check:file-size → default.ts within its ceiling; the only violation (open-sse/services/combo/executeTargetAttempt.ts 1288 > 1284) is pre-existing on the base and untouched here

⚠️ base-red inherited: #15306 — unit/vitest/integration/package-artifact gates on release/v3.8.52

diegosouzapw and others added 2 commits October 13, 2026 09:39
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
@diegosouzapw
diegosouzapw merged commit 3527f04 into release/v3.8.52 Oct 13, 2026
26 of 46 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

CI Coverage Report

  • Coverage job: skipped
  • PR test policy: success

Coverage artifact was not available for this run.

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