fix(gemini): handle thinking model response parts correctly#1140
Merged
chumyin merged 1 commit intozeroclaw-labs:mainfrom Feb 21, 2026
Merged
Conversation
Gemini thinking models (e.g. gemini-3-pro-preview) return response parts with `thought: true` for internal reasoning and `thoughtSignature` for opaque signatures. The previous extraction logic blindly took the first part, which was the thinking part, returning reasoning text instead of the actual answer. - Add `thought` field to `ResponsePart` to detect reasoning parts - Add `effective_text()` on `CandidateContent` to skip thinking/signature parts and extract only the real answer (falls back to thinking text if no non-thinking content is available) - Make `Candidate.content` optional to guard against candidates with no content (e.g. safety-filtered responses) - Add 7 focused tests covering thinking, non-thinking, fallback, empty, multi-part, signature-only, and internal API responses Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR intake checks found warnings (non-blocking)Fast safe checks found advisory issues. CI lint/test/build gates still enforce merge quality.
Action items:
Run logs: https://github.com/zeroclaw-labs/zeroclaw/actions/runs/22238834237 Detected blocking line issues (sample):
Detected advisory line issues (sample):
|
|
Thanks for contributing to ZeroClaw. For faster review, please ensure:
See |
Contributor
|
Thanks for the contribution and collaboration.\n\nFinalization update:\n- Verified PR state, review status, and checks for merge eligibility.\n- Completed rebase merge.\n\nWe are currently conducting ZeroClaw automated testing. This is an automated comment from ZeroClaw. If you have any questions, please contact @chumyin. |
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
gemini-3-pro-preview) return response parts withthought: true(internal reasoning) andthoughtSignature(opaque signature blob). The current extraction logic takes the first part, which is the thinking part, returning reasoning text instead of the actual answer — or failing with "error decoding response body" when the response structure doesn't match expectations.thoughtfield toResponsePart, implementseffective_text()onCandidateContentto skip thinking/signature parts, updates extraction to use it.Candidate.contentoptional to guard against candidates with no content (e.g. safety-filtered responses).Problem
When using
gemini-3-pro-preview(or other thinking-enabled Gemini models), the API returns parts like:{ "candidates": [{ "content": { "parts": [ {"thought": true, "text": "Let me reason about this..."}, {"text": "The actual answer."}, {"thoughtSignature": "base64blob..."} ] } }] }The previous code blindly took
.parts.into_iter().next(), which returned the thinking part instead of the answer. Parts with onlythoughtSignature(notext) were noise that could cause empty responses.Changes
src/providers/gemini.rsResponsePart: addsthought: boolfield (#[serde(default)]) to detect reasoning partsCandidate: makescontentoptional (Option<CandidateContent>) for robustnessCandidateContent::effective_text(): new method following theeffective_content()pattern from OpenAI provider — skipsthought: trueparts, skips signature-only parts, concatenates non-thinking text, falls back to thinking text if that's all that's availablesend_generate_content: useseffective_text()instead of.parts.into_iter().next().and_then(|p| p.text)CHANGELOG.md[Unreleased] > Fixeddocs/providers-reference.mdValidation Evidence
cargo check --lib— compiles clean (no new warnings)cargo clippy— no issues ingemini.rscargo fmt— no formatting issues in changed filescargo test --libis blocked by a pre-existing compilation error insrc/agent/loop_.rs:3603(missing 8th arg tobuild_system_prompt_with_mode) — unrelated to this PRSecurity Impact
Rollback Plan
🤖 Generated with Claude Code