Skip to content

GPT-OSS: render tool parameters as declared; serve changed renders cold - #2679

Closed
jonathan308 wants to merge 7 commits into
fix/gemma-string-first-union-v9-coldfrom
fix/gptoss-raw-tool-schema
Closed

jonathan308 wants to merge 7 commits into
fix/gemma-string-first-union-v9-coldfrom
fix/gptoss-raw-tool-schema

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

GPT-OSS's Harmony template prints a tool parameter's type list as a union (string | integer), a oneOf as the union of its members and a parameter without a type as any. The schema repair that runs before every template gave each such parameter one type, the first member's or string, so GPT-OSS was told string for numbers, booleans, objects and {}. It then wrote strings ("-0.75", "-4200"), JSON text, or reasoned at length about the mismatch. GPT-OSS now renders each tool from the request's own declaration and keeps the repair's type only where the declaration states one type.

A request whose tools arrive already repaired (today's coordinator) renders byte-identically. A coordinator request whose GPT-OSS render changes is served without the prompt cache, as in #2651 and #2658.

Base

Stacked on #2658 (final head 4af17dfdcf, merged in by 5c7797e1dd), so fold (e) has one served-cold block. This PR's changes are commits 4ebb3ee07d, 617338f8a0 (the template utility, GPT-OSS) and e310af3e89 (the template utility passes the declarations to Gemma's tool normalization, so a property declared without a type renders untyped there as in the served prompt).

What changes

  • ToolSchemaNormalization.repairedParameters(_:writesRenderTypes:budget:): the same walk as the ingress repair. With writesRenderTypes false it writes a type only where the node states one:
    • a type list with one concrete member (["integer","null"]) still collapses, as before;
    • a typeless node is still typed from its structure (properties, items), a union whose typed members share one type (anyOf [string, null]), its enum / const values, or assertions of one type family;
    • a type list of two or more types stays a list, a union of several types, {}, $ref and an annotation-only node stay typeless, and a positional boolean becomes {}.
    • ensureParameterTypes and its output are untouched.
  • GPTOSSToolSchemaRender: for GPT-OSS only, each prepared tool whose declaration (ChatTemplateControls.declaredTools, read from the received bytes) gives a different tree with and without render types renders that declaration's parameters without them. Every other tool keeps its prepared tool. On a declaration the repair already typed, those steps have nothing to do, so the tree is the same and the prompt is unchanged. It is wired into ProviderPromptContractPipeline.normalizedInput and the prompt-token floor.
  • Validation and constrained decoding are unchanged. GPTOSSAutoToolConstraint already compiles each call's arguments from declaredTools. With declarations as written, {} keeps free arguments and a union admits each of its members (tested).
  • Served cold (GPTOSSToolSchemaCache): chained after Gemma: render a string-first scalar union as its typed member; serve those requests cold #2658's check, on a context that still plans a cache attempt. The prompt contract stays darkbloom-request-normalization-v9, which renders the repaired types. The request gets no scope and no receipt nonce: no lookup or ready receipt, no cached-token usage and no checkpoint write. There is a fixed darkbloom logs line and stats.promptCacheSkippedToolRawSchema in the daemon state. No wire change. The coordinator argument accepted for Render an earlier tool call's null arguments; serve those requests cold #2651 applies unchanged: only that request loses cache routing and calibrated first-content admission.
  • Template utility (/tokenize, MultiModelBatchSchedulerEngine.applyTemplate): it renders the body's tools unrepaired; for GPT-OSS it now renders each through the repair without its render types (GPTOSSToolSchemaRender.servedTools), the tools the served prompt shows, so its count matches.
  • Template utility renders the body as received. The local /tokenize utility renders the tools of the body it receives. For a raw client body that is the render of the caller's own declarations (GPT-OSS as written; Gemma 4's untyped properties with an empty type). Today's coordinator-served prompts are built from repaired declarations and match that render only once the platform forwards the caller's declarations (darkbloom-platform CI (dev): split the slow cluster runtime groups over 5 shards #1868).
  • Local API: its request keeps the body's own tools, so GPT-OSS renders them as written there immediately.
  • Inert on today's forwarding. The production coordinator forwards the repaired declarations to every family but GLM (darkbloom-platform consumer.go ApplyResolvedBuild then body.Current(); tool_schema_state.go resolvedTools). On a repaired declaration every type is already a string and every positional node typed, so parametersWithoutRenderTypes returns nil, renderedTools keeps each prepared tool, changesRender is false and nothing is served cold: the GPT-OSS prompt and its cache context are byte-for-byte as before (corpus test below). The render changes only where a body arrives with the caller's own declarations: the local API, and the coordinator once it forwards originals (darkbloom-platform CI (dev): split the slow cluster runtime groups over 5 shards #1868, DARKBLOOM_FORWARD_ORIGINAL_TOOL_SCHEMAS, default off).

Test plan

  • CI (dev) on this head.
  • New GPTOSSToolSchemaRenderTests, rendering the served GPT-OSS template (Fixtures/GPTOSS/chat_template.jinja, hash-pinned) on the serving input path:
    • type [string, integer] → string | integer, [integer, string, null] → integer | string | null, {}, true, anyOf [string, number] and a description-only node → any, oneOf [integer, string] → a union. Before, each rendered string (number for the integer-first list).
    • The same declarations repaired, as today's coordinator forwards them: byte-identical prompts.
    • Declarations of one type ([string, null], [integer, null], anyOf [X, null], an enum, a mixed enum, an object, items, minimum) render exactly as before and are not served cold.
    • Other families (Qwen 3.5, Gemma 4, GLM) are unchanged.
    • Corpus: all 1,336 distinct parameters of a realistic tool-call schema corpus (Fixtures/GPTOSS/tool-schema-corpus.json). Forwarded repaired, each renders byte-identically and keeps its cache context. Forwarded as written, none fails to render where the repaired one renders, and some change.
    • Auto tool grammar with declarations as written: {} stays free (-0.75, arrays, objects, null, strings), and type [string, integer], oneOf [integer, string] and anyOf [string, boolean] admit each member.
    • Served cold: a planned GPT-OSS request whose render changed; a repaired one, an unplanned one and another family keep their context.
    • Local API (LocalChatRequest): renders as written.
    • The prompt-token floor renders the same tools.
    • The template utility gives the template the same tools as the served prompt for [string, integer], [integer, null], true, {} and anyOf [string, null] (GPT-OSS), and the same render type for {}, a description-only and an integer property (Gemma 4).
  • ProductionPromptParityTests:
    • the GPT-OSS vector bodies whose render changes are pinned to exactly gpt-oss-20b/{endpoint_messages_tool_turn, gemma_tool_turn, tools} (a {} or description-only parameter). Each is served cold, and its contract tokens are checked on its repaired tools.
    • New: every vector body with tools renders the same prompt from its original tools and from the repaired tools, except the served-cold cases of this PR and of Gemma: render a string-first scalar union as its typed member; serve those requests cold #2658 (both pins kept exact).
  • Red control: linked below. It keeps the API and test files but never changes the render, so it fails exactly the new render, served-cold, local and parity-classification expectations. The corpus-inertness, single-type and auto-grammar tests pass on both: they guard behaviour that must not change.
  • Refactor pass: done; no behaviour-preserving changes warranted.

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. The prompt contract ID and normalization version (v9) are unchanged, and no message or field is added. The daemon state gains an optional counter.
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated: docs/architecture/inference.md (GPT-OSS render), docs/architecture/prefix-cache.md (served cold), docs/developer/test.md (corpus fixture).
  • No documentation needed — reason:

Changelog

  • Added changelog.d/gptoss-tool-schema-render.md and ran python3 scripts/changelog.py check.
  • No user-visible change, or an explicitly authorized release/history change.

Before And After

flowchart LR
  A["value: type [string, integer]"] --> R["ingress repair:<br/>type string + anyOf"]
  R --> B["Before: GPT-OSS prompt shows value: string<br/>model writes \"-4200\""]
  A --> D["declaredTools (bytes as received)"]
  D --> C["After: GPT-OSS prompt shows value: string | integer<br/>model writes -4200"]
Loading
flowchart TD
  P["prepared tools (repaired)"] --> Q{"GPT-OSS and declaration<br/>differs without render types?"}
  Q -- no --> S["render prepared tool (unchanged bytes)"]
  Q -- yes --> T["render declaration without invented types"]
  T --> U{"coordinator planned a cache attempt?"}
  U -- yes --> V["serve cold: no scope, no receipt<br/>promptCacheSkippedToolRawSchema"]
  U -- no --> W["serve as planned"]
Loading

Red control

#2680 (draft): the same tests with the render switched back; expected to fail only at the new expectations.

GPT-OSS's Harmony template prints a type list as a union, a oneOf as the
union of its members and a node without a type as any. The shared schema
repair gave each such node one type (the first member's or string), so the
model was told string for numbers, booleans, objects and {}.

GPT-OSS now renders each tool's parameters from the body's own declaration
through the repair without the types it invents. A tool that this leaves as
the repair leaves it keeps its prepared tool, so a body whose tools arrive
already repaired renders byte-identically. Normalization v9 still plans the
repaired prompt, so a coordinator request whose GPT-OSS render changed is
served without the prompt cache (promptCacheSkippedToolRawSchema).
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference-landing Ready Ready Preview Nov 24, 2026 4:00pm UTC
darkbloom-status Ready Ready Preview Nov 24, 2026 4:00pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 24, 2026 4:00pm UTC

Request Review

@jonathan308 jonathan308 added the run-ci Trigger one-shot PR CI run (auto-removed when run starts) label Nov 24, 2026
@github-actions github-actions Bot removed the run-ci Trigger one-shot PR CI run (auto-removed when run starts) label Nov 24, 2026
…cold' into fix/gptoss-raw-tool-schema

# Conflicts:
#	provider-swift/Sources/ProviderCore/ProviderLogger.swift
#	provider-swift/Sources/ProviderCore/ProviderLoop+InferenceHandler.swift
#	provider-swift/Tests/ProviderCoreTests/Inference/Prompting/ProductionPromptParityTests.swift
The template utility (/tokenize's applyTemplate) renders the body's tools
unrepaired. For GPT-OSS it now renders each through the repair without its
render types, as the served prompt does, so its count matches.
applyTemplate renders the body's tools for /tokenize. Gemma's invariant 8
(a property declared without a type renders untyped) reads the
declarations; without them the utility counted STRING where the served
prompt renders an empty type.
…d ids

The served-cold check for another family used a GPT-OSS build id with a
Qwen model type. The family is selected by build id and model type, as the
Harmony template path selects it; use each family's own id.
@jonathan308

Copy link
Copy Markdown
Collaborator Author

Closing: this branch's head (de58437) is already contained in dev.

@jonathan308 jonathan308 closed this Dec 2, 2026

This branch was successfully deployed

3 active deployments
Preview – d-inference-landing — de58437b Deployed Nov 24, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — de58437b Deployed Nov 24, 2026 by vercel[bot]
Preview – darkbloom-status — de58437b Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant