Repository navigation
Gemma: render a string-first scalar union as its typed member; serve those requests cold - #2658
Closed
jonathan308 wants to merge 3 commits into
Closed
jonathan308 wants to merge 3 commits into
jonathan308 wants to merge 3 commits into
Conversation
…those requests cold
Gemma 4's template prints one render type per tool parameter and never
anyOf/oneOf, and the shared schema repair types a union by its first non-null
member. A union of string and one other scalar type with string first, such as
{"type": ["string", "integer"]} or an anyOf/oneOf of the two, therefore
rendered STRING and Gemma quoted typed values ("-4200" for -4200).
Gemma's tool enforcement (Gemma4ToolSchemaEnforcement invariant 7) now renders
such a property as the other member (INTEGER, NUMBER or BOOLEAN); a null member
is skipped as nullable carries it. Unions with more members, non-scalar
members, an enum, a const or allOf keep STRING. The union stays in the request
and only the render input changes, so the validator and constrained decoding
still accept both members. Other families keep the shared repair's render type.
The prompt contract stays v9, which renders STRING. A coordinator-planned
request whose declared tools get a changed Gemma render type
(ChatTemplateFixes.changesGemmaToolUnionType, the same tool path run on the
declared tools) is served without the prompt cache, like a request whose
tool-call history carries a null: no scope or receipt nonce, logged and counted
(promptCacheSkippedToolUnionType). ProductionPromptParityTests pins the set of
vector bodies this applies to: none.
4 of 13 tasks
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
A stored static of [([String: Any], String)] is not Sendable under Swift 6 strict concurrency; the table is now computed on each use. Test-only.
5 of 13 tasks
…those requests cold
The shared schema repair gives a property the caller declared without any
type or schema keyword ({}: any value) the type string, so Gemma 4 saw STRING
and quoted its values. Gemma's tool enforcement (invariant 8) now reads the
caller's declarations as sent (ChatTemplateControls.declaredTools, which the
serving, recount and diffusion media paths pass to ChatTemplateFixes.normalizeTools)
and renders such a property with an empty type, type:<|"|><|"|>, as the served
template renders a typeless property. Without the declarations the injected
type stays. Other families are unchanged.
The same served-cold rule covers it: ChatTemplateFixes.changesGemmaToolRenderType
reports invariant 7 or 8, and the handler passes the declarations. Under the
v9 contract the vectors' Gemma bodies that declare city: {} now render
differently, so ProductionPromptParityTests pins exactly those six bodies
(three Gemma models x endpoint_messages_tool_turn and tools), checks they are
served cold and differ from the vector, and matches the vector for the same
body with each such property typed string (Gemma4ToolSchemaEnforcement.
declaresAnyValue), as the repair renders it under v9.
This was referenced Nov 24, 2026
Merged
Collaborator
Author
|
Closing: this branch's head (4af17df) is already contained in dev. |
This branch was successfully deployed
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
Gemma 4 showed a tool parameter typed as a string-first union of
stringand one other scalar type asSTRING, so it quoted typed values:"-4200"for-4200,"21.5","false". Examples are{"type": ["string", "integer"]}andanyOf/oneOfof the two. Gemma 4 now sees the other member (INTEGER,NUMBERorBOOLEAN). The union stays in the request.The prompt contract stays
darkbloom-request-normalization-v9, so a coordinator request whose Gemma tool declaration this changes is served without the prompt cache. Every other request is unchanged.Base
Stacked on #2651, which adds the served-cold machinery this reuses. This PR's change is commits
73cdc2d07e(string-first unions),ecd7435619(test-only Swift 6 fix) and4af17dfdcf(properties declared without a type). #2651 is based on the C7 candidate9bd3e01f7d, whose tree D7012821f59aequals.What changes
Gemma4ToolSchemaEnforcementinvariant 7):stringand hasanyOforoneOfmembers ofstringand exactly one other scalar type (integer,number,boolean).nullmember is skipped, becausenullablealready carries it.enum, aconstor anallOfkeepSTRING.enumcase keepsSTRINGso its enum stays visible. Unions with more members or non-scalar members keepSTRING. Member-reversed unions already rendered their first member.Gemma4ToolSchemaEnforcementinvariant 8):{}, any value) the typestring, so Gemma sawSTRINGand quoted its values.ChatTemplateControls.declaredTools) and renders such a property with an empty type,type:<|"|><|"|>. That is how the served template renders a typeless property; itsSTRING/ARRAY/OBJECTbranches all stay off.itemsandpropertiesdeclarations keep their render type.anyOf/oneOfthe shared repair wrote, so both members are accepted as before.ToolSchemaNormalization(ensureParameterTypes) and its output are untouched.GemmaToolUnionTypeCache):ChatTemplateFixes.changesGemmaToolRenderTyperuns the same Gemma tool path (metadata scope, sanitize, enforcement), with the declarations as sent, on the request's tools and reports whether invariant 7 or 8 changed a render type. Declared tools are a superset of the rendered ones, because tool choice only narrows them.darkbloom logs, andstats.promptCacheSkippedToolUnionTypein the daemon state. No wire change.Test plan
GemmaToolUnionTypeTests, each request built through the serving decode, so the shared repair runs:type,anyOfandoneOf× integer / number / boolean;["string","integer","null"]rendersINTEGERand nullable;anyOf/oneOf;string;{}and{description}render an empty type, and serve cold, only with the declarations;ProductionPromptParityTests:endpoint_messages_tool_turnandtools, which declarecity: {}. No vector body declares a string-first union (checked locally).string, the way the repair renders it under v9. The typeless check is the productiondeclaresAnyValue.Components touched
Protocol / interface changes
Documentation impact
docs/architecture/inference.md(Gemma render type) anddocs/architecture/prefix-cache.md(served cold).Changelog
changelog.d/gemma-tool-union-render-type.mdand ranpython3 scripts/changelog.py check.Notes
{}honestly, but the shared repair runs once at ingress and leaves no marker on a{}it typedstring. Keeping GPT-OSS's schemas as written therefore needs the raw schema or new repair markers on the render path. That is planned separately.anyOfplus the injectedtype), which is the shape it reads.{}already arrives typed, so the declarations the provider receives have no typeless property, and no request is served cold for it. It takes effect only when the coordinator forwards the caller's original tool schemas.city: {}bodies are classified, and the parity test checks both shapes.enumcase is left as is.Before And After
Refactor Pass
Refactor pass: done; no behaviour-preserving changes warranted.