Skip to content

Render an earlier tool call's null arguments; serve those requests cold - #2651

Merged
jonathan308 merged 9 commits into
devfrom
fix/tool-call-history-nulls-v9-cold-c8
Nov 24, 2026
Merged

jonathan308 merged 9 commits into
devfrom
fix/tool-call-history-nulls-v9-cold-c8

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

An earlier assistant tool call's JSON null arguments now reach the model as null at their key or array position. Before, they were dropped, so the model saw {} for {"deadline": null} and repeated the omission.

The prompt contract stays darkbloom-request-normalization-v9, which still renders such calls without their nulls. A coordinator request whose tool-call history carries one is therefore served without the prompt cache: no lookup, no receipt, no cached-token usage and no checkpoint write. Every other request is unchanged.

Linked issue

None.

Base

Until the C7 candidate lands on dev, this PR is based on the C7 candidate head 9bd3e01f7d (release/0.10.18-c7-candidate-3), so its diff against dev also shows the C7 changes. This PR's change is commits 194b8d2404 (the change), bf0385b9a5 (parity classification) 808a6b53cd, 96fb1569c8 and 3e550134aa (MiMo other-family guard). Once C7 lands, dev is merged in with a signed merge commit (no rebase, no force). This replaces #2649, which was based on an earlier C7 candidate.

What changes

  • Rendering:
    • sanitizeMessageForJinja (ProviderCoreFoundation) drops null leaves as before, except inside each tool call's decoded function.arguments, where they become Jinja null. Object keys are kept and array positions stay uncompacted. Gemma 4's string-argument path does the same.
    • The tool parameter schema drop policy is unchanged.
  • Templates: renderingToolArgumentNulls adds a null branch to Gemma 4's format_argument macro and to the Qwen 3.5 / Nemotron 3.5 Lightning XML parameter value.
    • It is applied by the serving tokenizer (LocalTokenizerLoader) and by the render check only. The managed Nemotron Super contract, which uses normalizeSwiftJinjaTemplate directly, renders as before.
    • The rewrite is idempotent. It leaves templates without these blocks untouched, and it gives identical bytes for prompts without a null.
    • Qwen 3.6, Qwen 3.8, GPT-OSS and Inkling 2 write arguments with tojson, so they print the null without a template change.
  • Families that do not change: GLM-5.3, MiMo and Flint build their own history and already kept these nulls.
  • Cache (ToolCallHistoryNullCache):
    • Once the slot's model type is known, a coordinator-planned request whose tool-call history carries a null replaces its planned cache context with one that has no scope and no receipt nonce. This applies only to models that render through the shared sanitizer.
    • With no receipt nonce, the v2 evidence callbacks are never configured: no prefix_cache_lookup_v2 and no prefix_cache_ready_v2. The engine runs with caching disabled, and terminal usage carries no cache fields.
    • The template controls still come from the planned context, so the prompt differs from the plan only by the nulls.
  • Observability:
    • Each such request writes the public fixed line Prompt cache skipped: an earlier tool call has a null argument; served cold to darkbloom logs.
    • The count is kept in AtomicProviderStats and written to the daemon state as stats.promptCacheSkippedToolCallNull.
    • No wire change.

Test plan

  • CI (dev) on this head.

  • ProviderCoreFoundation test target, built locally as a standalone package (no MLX):

    • all 62 Swift Testing tests in 8 suites and 110 XCTest tests pass;
    • PromptContractIdentityTests passes, so the v9 vectors are unchanged.
  • Every shipped chat template, checked locally against copies matching the manifest sha256 (not committed): Gemma 4 QAT and 8-bit, Qwen 3.5 9B and 35B, Qwen 3.6, Qwen 3.8, Nemotron 3.5 Lightning and GPT-OSS.

    • Rendered through this path, a history with top-level, nested-map, deep-object, array-element and object-in-array nulls shows each null. Gemma example: deadline:null,flags:{dark-mode:null},…,payload:{data:[null,{}]},rows:[[false,<|"|>Total<|"|>],null].
    • The same templates render a null-free history byte for byte with and without the rewrite.
  • New tests:

    • ToolArgumentNullRenderTests (ProviderCoreFoundation): sanitizer; verbatim served blocks for Gemma 4, Qwen 3.5 XML, Nemotron 3.5 Lightning, Qwen 3.6 / 3.8 tojson, GPT-OSS and Inkling 2; null detection; null-free bytes; rewrite idempotence; plain normalization keeps the Super path unchanged.
    • ToolCallHistoryNullCacheTests (ProviderCore):
      • a planned null-history request is served cold on each family;
      • no null, a null only in a schema or message field, or an unplanned request keeps its context;
      • GLM-5.3, MiMo, Flint and managed Super keep their plan;
      • the serving path's template input keeps the nulls for Gemma 4, Qwen 3.5 / 3.5 MoE / 3.8, Nemotron 3.5 Lightning, GPT-OSS and Inkling 2. GLM-5.3, MiMo and Flint pass on the old code too and are kept as guards.
  • ProductionPromptParityTests: the shared vectors are not changed or regenerated.

    • Production classifier: a vector body is classified as provider-rendered and uncacheable by the serving decision itself, ToolCallHistoryNullCache.servingContext (carriesNull plus rendersThroughSharedSanitizer).

    • Pinned set: the classified set must be exactly the 14 vector bodies whose earlier call carries a null (7 models × endpoint_messages_tool_turn and gemma_tool_turn). One more or one fewer fails the test.

    • For each classified body, the test checks that:

      • it is served cold (no scope, no receipt nonce, caching off);
      • the provider's render differs from the vector;
      • the vector still matches, token for token and block hash for block hash, the same body with each history call's arguments passed through the production sanitizeForJinja.

      On all 14 bodies that drop is byte-equal to a hand-written v9 drop (checked locally).

    • Other cases: every other case is checked exactly as before.

  • Guards updated because they asserted exactly the old drop:

    • JinjaSanitizationTests: the null unit argument stays Jinja null.
    • Gemma4ToolCallArgumentsTests: a parsed null leaf becomes Jinja null.
    • FlintTemplateReplayTests generic-architecture case: call arguments keep their nulls; its schema assertions are unchanged.

    Also MiMoV26PromptContractTests.testOtherFamilyStillUsesExistingPermissiveControlAndNullNormalization: it expected another family's render of a MiMo reference body to differ, because the shared sanitizer dropped that body's call-argument nulls. Those nulls are now kept, as MiMo always has, so for that arguments-only body the assertion now requires the renders to agree. A second body, with a null outside call arguments (a tool parameter schema's default, which the shared sanitizer still drops and MiMo keeps), is rendered twice per family: without the null the two families must render it alike, and with it they must differ. The null is therefore the only cause of the difference, and the guard keeps protecting MiMo from the other family's null removal. Its malformed-control half is unchanged. Each edit changes only the assertion about the old null-dropping, and the reason is given next to each guard above; nothing was re-baselined. The Nemotron Super golden tests and the other MiMo tests are unedited.

  • Red control: Red control for #2651: tests without the change (do not merge) #2652. It keeps the new API so the tests compile, but restores the old drop and never serves cold. Locally, ProviderCoreFoundation fails at exactly the new ToolArgumentNullRenderTests cases and nothing else.

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 WebSocket message or field is added. A null-history request simply sends no prefix-cache receipts, which the coordinator already handles as an unanswered attempt that expires.
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated: docs/architecture/inference.md (null rendering), docs/architecture/prefix-cache.md (served cold), docs/architecture/model-registry.md (render check feeds templates like the serving tokenizer).
  • No documentation needed — reason:

Changelog

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

Notes

  • Coordinator effect: a coordinator attempt that gets no lookup or ready receipt only expires. Only that request loses cache routing and its exact prompt-work count (the provider's recount differs by the null tokens), so it is admitted without calibrated first-content admission.
  • Edge case near the prompt limit: a pair-served null-history request within a few tokens of the pair's prompt limit can be refused by the leader with the existing request_exceeds_context 400, which carries no health effect, and then moves on to the rest of the fleet.
  • v10 follow-up: the full fix that lets these requests use the cache again needs a v10 prompt contract on both sides and a dual-version migration. That is planned separately.

Before And After

Before:

flowchart LR
  A["history call arguments<br/>{deadline: null}"] --> S["sanitizer drops null"] --> T["template renders<br/>call:f{}"] --> M["model repeats {}"]
  P["coordinator plan (v9)"] --> C["cache lookup + receipts<br/>prompt matches plan"]
Loading

After:

flowchart LR
  A["history call arguments<br/>{deadline: null}"] --> S["sanitizeMessageForJinja keeps null"] --> T["template renders<br/>call:f{deadline:null}"] --> M["model sees the real call"]
  P["coordinator plan (v9)"] --> D{"history null and<br/>shared sanitizer?"}
  D -- no --> C["cache lookup + receipts as before"]
  D -- yes --> X["no scope, no receipt nonce:<br/>served cold, logged, counted"]
Loading

Code flow (inference handler):

sequenceDiagram
  participant H as handleInferenceRequest
  participant N as ToolCallHistoryNullCache
  participant E as Engine
  H->>H: plannedCache = frame + sealed copy
  H->>H: templateControls from plannedCache
  H->>N: servingContext(plannedCache, request, modelType, managedSuper)
  N-->>H: planned, or cold context (servedCold)
  H->>E: cacheScope / cacheEnabled / nonce from served context
Loading

Refactor Pass

Refactor pass: done; comment fix deferred unless head moves.

jonathan308 and others added 5 commits November 24, 2026 05:34
The call parser converted argument text with the render types the ingress
repair writes for the chat template, so a union, `not` or if/then/else
parameter read as its first or default member: under `oneOf: [integer,
number]` the text "2.5" stayed a string, which the declaration refuses.

The parser and the Qwen strict grammar's reading now use each tool's
parameters as sent (`Prepared.argumentTools`, `ToolArgumentSchemas`), with
a typeless enum/const node typed by its own values, which accepts the same
instances. The template still renders the repaired declarations; auto
validation already read the declarations as sent. GLM is unchanged.

Tests cover the tool-call schema fuzz grid constructs: the reading accepts
exactly the declared instances, the rendered parameter keeps its render
type, and Qwen 3.5 calls parse to arguments their declaration accepts.
With reasoning on, Lightning sometimes closes its thought early to sketch
the calls it plans, keeps reasoning in plain text, closes the thought
again and then writes the real calls. The splitter absorbs the second
</think> as a stray close and keeps everything before it as content, so
the sketched frames were parsed as calls too: two parallel calls came
back as four.

On the Nemotron route (absorbStrayThinkClose with the nemotron parser),
the splitter now holds content from the first tool frame after a closed
thought. A stray </think> turns the held text into reasoning, so its
frames never become calls; at the end of the output the held text is
content as before. Calls are not deduplicated by value, since identical
parallel calls can be intended.
…d tool-call arguments with the caller's declarations
…draft calls before a second thought close as reasoning
A JSON null in an earlier assistant tool call's arguments was dropped before
the chat template rendered, so the model saw a different call than the one it
made (Gemma 4: call:clear_project_deadline{} for {"deadline": null}) and
repeated the omission. The shared sanitizer now keeps those nulls as Jinja
null at their key or array position (sanitizeMessageForJinja, and Gemma 4's
string-argument path). Gemma 4's format_argument macro and the Qwen 3.5 /
Nemotron 3.5 Lightning XML parameter value gain a branch that writes null;
the rewrite is applied by the serving tokenizer and the render check only, so
the managed Nemotron Super contract renders as before. Tool parameter schemas
keep the drop policy. GLM-5.3, MiMo and Flint already kept these nulls.

The prompt contract stays darkbloom-request-normalization-v9, which still
renders such a call without its nulls. A coordinator request whose tool-call
history carries one, on a model that renders through the shared sanitizer, is
served without the prompt cache: no scope or receipt nonce, so no lookup or
ready receipt, no cached-token usage and no checkpoint write. The template
controls still come from the planned context. Each such request is logged
(public fixed line) and counted in the daemon state
(promptCacheSkippedToolCallNull).

ProductionPromptParityTests classifies a vector body with a history null as
provider-rendered and uncacheable: it checks that the body is served cold and
that the vectors still match the same body with those nulls dropped; the
vectors are unchanged. Guards updated because they asserted exactly the old
drop: JinjaSanitizationTests (the null unit argument stays Jinja null),
Gemma4ToolCallArgumentsTests (a parsed null leaf becomes Jinja null) and
FlintTemplateReplayTests' generic-architecture case (call arguments keep their
nulls; its schema assertions are unchanged).
@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 3:05pm UTC
darkbloom-status Ready Ready Preview Nov 24, 2026 3:05pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 24, 2026 3:05pm UTC

Request Review

… pin the 14 cases

ProductionPromptParityTests now classifies a vector body as provider-rendered
by ToolCallHistoryNullCache.servingContext itself (the serving decision), builds
the v9 body for the vector comparison by passing each history call's arguments
through the production sanitizeForJinja instead of a test-only dropper, and
requires the classified set to be exactly the 14 vector bodies (7 models x
endpoint_messages_tool_turn and gemma_tool_turn) whose earlier call carries a
null. Every other case is checked as before; the vectors are unchanged.
MiMoV26PromptContractTests.testOtherFamilyStillUsesExistingPermissiveControlAndNullNormalization
rendered a MiMo reference body through another family's normalization and
expected different tokens, because the shared sanitizer dropped the nulls in
that body's earlier call arguments. Those are exactly the nulls it now keeps,
as MiMo always has, so the two renders agree. The assertion now requires that
agreement; the malformed-control half of the test is unchanged, and MiMo's own
render is still pinned by the reference corpus.
…ps a null

Adds a second body to
testOtherFamilyStillUsesExistingPermissiveControlAndNullNormalization with a
null outside any call's arguments (a tool parameter schema's default), which
the shared sanitizer still drops and MiMo keeps. The other family's render of
it must still differ from MiMo's. The arguments-only reference body keeps the
agreement assertion from the previous commit.
@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
The schema body now renders twice per family: without the default null the
two families must render it alike, and with the default null they must
differ, so the null is the only cause of the difference. The schema value is
typed as MLXLMCommon.JSONValue explicitly.

This branch was successfully deployed

3 active deployments
Preview – eigen-homepages-darkbloom — 3e550134 Deployed Nov 24, 2026 by vercel[bot]
Preview – d-inference-landing — 3e550134 Deployed Nov 24, 2026 by vercel[bot]
Preview – darkbloom-status — 3e550134 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