Skip to content

fix: bridge unsigned Gemini 3 tool histories - #9853

Open
SunmiJJW wants to merge 2 commits into
AstrBotDevs:masterfrom
SunmiJJW:codex/fix-gemini3-cross-provider-signature
Open

fix: bridge unsigned Gemini 3 tool histories#9853
SunmiJJW wants to merge 2 commits into
AstrBotDevs:masterfrom
SunmiJJW:codex/fix-gemini3-cross-provider-signature

Conversation

@SunmiJJW

@SunmiJJW SunmiJJW commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Gemini 3 requires a thought signature when function-call history is replayed. AstrBot preserves genuine Gemini signatures, but a tool call produced by another provider has no Google-specific metadata, so switching or falling back to Gemini 3 can fail with a 4xx validation error.

Google documents skip_thought_signature_validator for the unavoidable cross-model-history case: https://ai.google.dev/gemini-api/docs/generate-content/thought-signatures

Modifications / 改动点

  • Detect Gemini 3 requests while converting AstrBot conversation history.
  • Preserve genuine Google thought signatures exactly as received.
  • When a function-call step has no genuine signature, add the documented sentinel only to the first call in that step (including parallel calls).
  • Leave Gemini 2.5 and unsigned non-Gemini histories unchanged.
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Verification Steps / 验证步骤

python -m pytest tests/test_gemini_source.py -q
python -m ruff check astrbot/core/provider/sources/gemini_source.py tests/test_gemini_source.py
python -m ruff format --check astrbot/core/provider/sources/gemini_source.py tests/test_gemini_source.py

Test Results / 运行结果

  • 9 passed
  • Ruff check passed.
  • Ruff format check passed.

Checklist / 检查清单

  • 👀 My changes have been well-tested, and verification steps/results are provided above.
  • 🤓 No new dependencies are introduced.
  • 😮 My changes do not introduce malicious code.

Summary by Sourcery

Support replaying unsigned cross-provider tool histories with Gemini 3 without changing existing Gemini 2.5 or non-Gemini behavior.

Bug Fixes:

  • Prevent Gemini 3 request validation failures when replaying unsigned function-call histories from other providers.
  • Preserve genuine Google thought signatures while supplying the documented fallback for unsigned Gemini 3 tool steps.

Tests:

  • Add coverage for cross-provider, foreign-signature, genuine-signature, and Gemini 2.5 tool-call histories.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Aug 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4359c44258

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread astrbot/core/provider/sources/gemini_source.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant