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 reliable Gemini 3 fallback and model switching when replayed tool histories lack Google thought signatures.

Bug Fixes:

  • Allow Gemini 3 to replay unsigned cross-provider function-call histories without triggering thought-signature validation errors.

Enhancements:

  • Preserve genuine Google thought signatures while applying the documented fallback sentinel only to the first unsigned function call in a tool step.
  • Keep Gemini 2.5 and non-Gemini conversation histories unchanged.

Tests:

  • Add coverage for unsigned cross-provider tool calls, foreign signatures, genuine Gemini signatures, and unchanged Gemini 2.5 behavior.

@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
@SunmiJJW
SunmiJJW force-pushed the codex/fix-gemini3-cross-provider-signature branch from 9e7c76c to 821f2c7 Compare August 31, 2026 13:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T13:45:49.402166Z 821f2c7 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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