Skip to content

[Fix] LiteLLM + Gemini: tool call id truncation corrupts thought_signature - #2119

Open
PierrunoYT wants to merge 1 commit into
Zoo-Code-Org:mainfrom
PierrunoYT:fix/litellm-tool-id-thought-signature
Open

PierrunoYT wants to merge 1 commit into
Zoo-Code-Org:mainfrom
PierrunoYT:fix/litellm-tool-id-thought-signature

Conversation

@PierrunoYT

Copy link
Copy Markdown
Contributor

Fixes #2064

Problem

LiteLLM carries a Gemini thought signature inside the tool call id (call_xxx__thought__<signature>). The LiteLLM handler ran every tool call id through sanitizeOpenAiCallId, which truncates to 64 characters and appends _ + an 8-hex hash. For these ids that cut the signature and added the hash, so Gemini rejected the next request with 400 ... thought_signature ... Base64 decoding failed.

Fix

New sanitizeLiteLlmCallId (utils/tool-id.ts): ids containing __thought__ are only character-sanitized (never truncated); all other ids keep the existing OpenAI 64-character treatment. LiteLLMHandler uses it for both the standard and the R1-format message conversion.

Notes

  • Gemini through LiteLLM does not need the 64-character limit for these ids; the ids stay as LiteLLM generated them.
  • A history that mixes a long thought-signature id with a provider that enforces 64 characters is not specially handled (same as before for non-LiteLLM providers).

Tests

tool-id.spec.ts (intact long id, invalid-character sanitizing, other long ids still truncated, short ids unchanged) and a lite-llm.spec.ts test that the assistant tool_calls[].id and the tool message tool_call_id reach the request unchanged. check-types passes.

🤖 Generated with Claude Code

…ture

LiteLLM encodes a Gemini thought signature into the tool call id after
__thought__. sanitizeOpenAiCallId cut such ids to 64 characters and appended
a hash, so Gemini received a corrupted signature (400 Base64 decoding failed).
Only character-sanitize ids containing the marker.

Fixes Zoo-Code-Org#2064

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: Zoo-Code-Org/Zoo-Code/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3fdba53b-98bf-49b7-9e2d-8883647e06cd
📥 Commits

Reviewing files that changed from the base of the PR and between 16425bc and b018630.

📒 Files selected for processing: 4
  • src/api/providers/__tests__/lite-llm.spec.ts
  • src/api/providers/lite-llm.ts
  • src/utils/__tests__/tool-id.spec.ts
  • src/utils/tool-id.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Required CI passed. Waiting for automated review of the latest commit.

If automated review does not start, a maintainer must restart it.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit coderabbit-review-active Required CI passed; CodeRabbit review is active

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] LiteLLM + Gemini 4: tool call id truncated to 64 chars with hash suffix, corrupting thought_signature (400 Base64 decoding failed)

1 participant