Repository navigation
fix(py/google-genai)!: keep candidate metadata, coalesce streamed parts, and fail fast without a Vertex project - #50
Merged
Conversation
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 19:08
0cee093 to
1069b42
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 19:55
1069b42 to
cadb036
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 20:02
cadb036 to
3f2f21f
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 20:21
3f2f21f to
9b18e5e
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 21:22
9b18e5e to
1a69ccf
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 21:27
1a69ccf to
1e3648e
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
2 times, most recently
from
November 9, 2026 22:03
3a2f2c1 to
2da210f
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 9, 2026 23:18
2da210f to
d675ef3
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 10, 2026 07:44
d675ef3 to
0693e72
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 10, 2026 18:37
0693e72 to
9beb25b
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 11, 2026 06:22
2ba52f0 to
8bea28f
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 11, 2026 16:21
8bea28f to
5dce93a
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 11, 2026 17:31
5dce93a to
c29693d
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 11, 2026 18:38
c29693d to
2139116
Compare
…s, and raise FAILED_PRECONDITION without a Vertex project Locks the response and error shapes callers will read after 1.0. - Candidate metadata: groundingMetadata, urlContextMetadata, citationMetadata, logprobsResult, safetyRatings, avgLogprobs, finishMessage and tokenCount land at custom['candidates'][i] for one-shot and streamed calls; promptFeedback stays at custom['promptFeedback']. Streamed logprobs and citations concatenate, grounding merges key by key, safetyRatings update per category. ModelResponse.finish_message carries candidate 0's finishMessage. - Streamed final message: adjacent text and reasoning fragments merge into one Part each; a fragment with a thought signature closes its block and keeps the signature. Chunks still stream unchanged. - thoughtSignature round-trips on text, media, executableCode and codeExecutionResult parts. fileData in a reply becomes a media part, a signature-only part becomes signed empty text, and the Language/Outcome enums in custom are wire strings. A malformed signature is INVALID_ARGUMENT. Gemma history drops reasoning parts and signatures, and messages left empty are skipped. - VertexAI with no project (regional, multi-region, or a per-request override) raises GenkitError FAILED_PRECONDITION at call time instead of google-genai's bare ValueError, which Retry treated as transient. Multi-region no longer raises ValueError at construction.
huangjeff5
force-pushed
the
fix/py-1.0-pr4-google-genai
branch
from
November 12, 2026 06:38
e5e7c1a to
9f606a1
Compare
hilariie
reviewed
Nov 16, 2026
hilariie
left a comment
Contributor
There was a problem hiding this comment.
A few lines in the description don't match the code: missing ADC gives FAILED_PRECONDITION for multi-region, chunk parts do change (signatures, fileData as media), and the Veo and try-on per-request clients weren't converted. With a Breaking changes section, the title should also have a !.
…alescing, and Vertex project
- Sum logProbabilitySum and tokenCount across stream chunks; token-weight avgLogprobs.
- Join coalesced stream fragments once per run instead of per fragment.
- Decode URL-safe and unpadded thought signatures; drop undecodable ones with a warning.
- Restore ADC project pickup for VertexAI(api_key=..., location=<multi-region>).
- Route Veo and Virtual Try-On per-request clients through the shared builder.
- README: custom is {} when Gemini sends no metadata.
hilariie
approved these changes
Nov 20, 2026
hilariie
left a comment
Contributor
There was a problem hiding this comment.
lgtm with one inline comment
# Conflicts: # packages/genkit-google-genai/src/genkit_google_genai/_google.py # packages/genkit-google-genai/tests/vertexai_location_test.py
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.
Gemini replies from
genkit-google-genaidropped grounding, citation, and logprobs data, streamed turns came back as onePartper chunk, andVertexAI()without a project failed with a bareValueErrorthat Retry kept retrying. This PR fixes the response and error shapes callers will depend on after 1.0. Bug fixes with no shape change (built-in + function tools, media validation, context cache, timeout floor) moved to #FOLLOWUP.Main Changes
response.custom['candidates'][i]: Previously, onlypromptFeedbackreachedcustom;groundingMetadata,urlContextMetadata,citationMetadata,logprobsResult,safetyRatings,avgLogprobs,finishMessage, andtokenCountwere dropped. One-shot and streamed calls now fill the same layout JS and Go already write, indexed by candidate. Streaming concatenates the per-chunklogprobsResultandcitationMetadatalists, sumslogProbabilitySumandtokenCount, token-weightsavgLogprobs(dropped when more than one chunk sent it and there's nothing to weigh by), and updatessafetyRatingsper category.groundingMetadataarrives whole on the last chunk in practice; it merges key by key in case Gemini splits it.promptFeedbackstays atcustom['promptFeedback'], andfinish_messageis set from candidate 0.response.message.contentheld every streamed fragment plus a trailing empty text part, so post-model guardrails and history saw split text. Adjacent text and reasoning fragments now merge into oneParteach, joined once at stream end; a fragment carrying athoughtSignaturecloses its block and keeps the signature. Chunk boundaries are unchanged, but chunk parts go through the same converter, so they pick up the part changes below (signatures inmetadata,fileDataas media). This has to land before 1.0 because it changes the content list callers index into.thoughtSignatureround-trips on every part kind: Previously, the converter kept signatures only on tool requests and reasoning, so Gemini 3 signed text, media, and code parts lost them and the next turn failed. They now survive both directions and JSON persistence. Three shapes change with it:fileDatain a reply becomes a media part instead of empty text, a signature-only part becomes signed empty text, andcustom.executableCode.language/custom.codeExecutionResult.outcomeare the wire strings ('PYTHON','OUTCOME_OK') instead of google-genai enum members. Outbound signatures decode from standard or URL-safe base64, padded or not, which covers google-genai's own JSON dump and Gemini'sskip_thought_signature_validatorplaceholder; one that still doesn't decode is dropped with a warning instead of failing the request. Gemma history drops reasoning parts and signatures, since Gemma rejects them.VertexAIproject raisesFAILED_PRECONDITION: Previously, ADC with no default project surfaced google-genai'sValueError, and Retry retries any exception that isn't aGenkitError. The plugin client and the Gemini, Veo, and Virtual Try-On per-request clients now share one builder and raiseGenkitError(status='FAILED_PRECONDITION')namingVertexAI(project=...)andGOOGLE_CLOUD_PROJECT. Multi-region moved from a construction-timeValueErrorto the same call-time error, so every missing-project path reports one status. With no ADC at all, regional clients still raiseUNAUTHENTICATED; multi-region raisesFAILED_PRECONDITION, because the plugin needs ADC to find the project and the rep endpoint can't be called without one.VertexAI(api_key=..., location='eu')still picks up the ADC project as before.Breaking changes
Pre-1.0 shape changes, called out because callers may read them:
response.message.contentis coalesced; code that expected onePartper chunk sees fewer parts.custom.executableCode.languageandcustom.codeExecutionResult.outcomeare strings, not enum members.fileDatareply parts are media parts, not empty text, in both chunks and the final message.VertexAI(location='eu')with no project no longer raisesValueErrorat construction; the first call raisesGenkitError(FAILED_PRECONDITION).base_url/api_version/locationoverride) with no Vertex project raiseFAILED_PRECONDITIONinstead ofINVALID_ARGUMENT.Cross-SDK
ModelResponse.customon Gemini models now carries candidate metadata, visible in traces and the Dev UI. The layout matches JS (response.custom.candidates[0]) and Go (resp.Custom["candidates"][0]):Replies with no candidate metadata or prompt feedback leave
customas{}. JS, Go, and Dart owners need no changes.