Correctness and contracts report · NVIDIA/hyperflare-inference #686

Raw Markdown for agents: https://autobot.eidonix.com/p/1cc05738-2912-4591-8e78-9cfaaec61948.md

Review — PR #686, lens: Correctness, Contracts & System-Level Consequences

docs(api.md): document DeepSeek V4/V4.1 behavior for tool_choice: "required" — head 6a2cacc, base c513e46, +14/−8 in one file (docs/api.md).

Key findings

  1. Major — the same false sentence the PR corrects is left standing in docs/core-design.md:1727-1729. docs/core-design.md:1727 still reads "tool_choice=required adds a prompt instruction and requires a completed call to a declared tool", unconditionally, and :1732 only defers to api.md at file level. After merge the two normative docs contradict each other, and half of the gap yatesdr's #445 triage asked for ("The docs should say so") remains open while Fixes #445 closes the issue.
  2. Minor — "they render required mode identically to "auto"" (docs/api.md:669-670) is prompt-identity, not behavior-identity. With a strict: true tool the request still forces a tool call during decoding: require_call is derived from the server-side ToolChoice::Required (helios/src/server/request.rs:277-281), which masks plain prose (helios/src/grammar/strict.rs:1829-1835), and the in-repo test asserts exactly that on the default thinking path (helios/tests/deepseek_requests.rs:815). One qualifying clause would prevent misreading.
  3. Every factual claim in the new paragraph and in the PR description is accurate — verified against renders_tool_choice, template_inputs, template_messages, the DeepSeek frontend downgrade, Encoder::finish, and the two named tests. No inaccurate before/after claim.
  4. No system-level consequences are possible. The diff is prose only: no runtime, wire/proto, captured-graph, admission, scheduler, metric/rate, buffer or cache path is touched, so the concurrency/contention, memory-amplification, failure-blast-radius, metric-span and Unix/Windows parity checks come back clean by construction. No owner sign-off is required for a docs correction under charter line 35 ("bad docs").

1. Major — docs/core-design.md keeps the unconditional claim (contract divergence)

Severity: Major. File: docs/core-design.md:1727-1733 (unchanged by this PR; the diff touches docs/api.md only).

Verbatim, at PR head:

1727  `tool_choice=required` adds a prompt instruction and requires a completed call
1728  to a declared tool. Without a grammar it uses ordinary sampling. Named tool
1729  selection filters the definitions to that tool; it does not by itself enable a
1730  grammar.

Contrast with the paragraph this PR writes, docs/api.md:667-674:

Prompt encoders using shared lowering (Jinja templates and TMLv0) add a
system instruction to call a tool to the prompt. The native DeepSeek V4 and V4.1
prompt encoders omit that shared instruction: ...
... In all
modes, including DeepSeek thinking mode, completion validates that generation
produced at least one completed call to a declared tool.

docs/core-design.md:1732-1733 says only "See the API contracts for the accepted strict schema subset, parser formats, protocol mappings and streamed errors" — a file-level pointer, not a pointer to the required-mode paragraph, so nothing in core-design.md rescinds its own unconditional statement.

Implementation confirms the api.md side and refutes the core-design side: helios/src/frontend/mod.rs:154-156 (renders_tool_choice true only for DeepseekV4 | DeepseekV41), helios/src/server/request.rs:465-476 (shared_lowering = !frontend.prompt_encoder().renders_tool_choice(); non-shared encoders get ToolChoice::Auto for the messages), and helios/src/server/inference.rs:387-390 (the instruction is appended only inside template_messages, i.e. only on the shared-lowering path).

Impact: the PR exists to make the docs say that required mode does not always add a prompt instruction. A reader who lands on core-design.md — the document AGENTS.md routes runtime/frontend questions to, and the one that carries the request-grammar contract this paragraph sits in — keeps the original inaccuracy after this PR merges, and Fixes #445 will close the issue with the docs half only partly done. The DeepSeek default is thinking-enabled, so this is the common path, not an edge case.

Fix (in this PR, scope already docs-only): rewrite core-design.md:1727 to separate the two halves, e.g. "tool_choice=required requires a completed call to a declared tool; shared-lowering prompt encoders (Jinja templates and TMLv0) also add a prompt instruction, while the native DeepSeek V4/V4.1 encoders do not." Alternatively drop the instruction half at :1727 and replace the file-level link at :1732 with a link to api.md's required-mode paragraph.

2. Minor — "render identically to "auto"" overstates the equivalence for strict tools

Severity: Minor (wording precision; no false statement about prompt rendering). File: docs/api.md:668-672.

Verbatim:

The native DeepSeek V4 and V4.1
prompt encoders omit that shared instruction: in thinking mode they render
required mode identically to `"auto"` so reasoning starts in `<think>`, and in
non-thinking (`chat`) mode their template opens the DSML tool-call block at the
end of the prompt so generation starts inside the tool-call envelope.

The prompt is indeed identical (downgrade at helios/src/frontend/deepseek.rs:276-280, the Required → Auto swap happens in frontend option parsing only; asserted by helios/tests/deepseek_requests.rs:697-703). But the request grammar is not: the server-side request.tool_choice is still Required when the plan is built —

helios/src/server/request.rs:277-281
    allow_undeclared: request.tool_choice == ToolChoice::Auto,
    require_call: matches!(
        request.tool_choice,
        ToolChoice::Required | ToolChoice::Named(_)
    ),

and helios/src/grammar/strict.rs:1829-1835 makes the body branches "tools_entry" whenever plan.require_call, so prose is masked out. The in-repo test shows the observable difference on the default (thinking) path, helios/tests/deepseek_requests.rs:810-816:

let req_single = json!({
    "tools": tools,
    "tool_choice": "required",
    "parallel_tool_calls": false
});
assert!(!f.accepts(req_single.clone(), "Thinking.</think>Just text."));

while the auto control at helios/tests/deepseek_requests.rs:774 accepts the same plain prose.

The same concern touches the retained sentence at docs/api.md:674 — "Sampling is unchanged; no calls are fabricated and no retries are attempted" — which is also pre-existing on main and reads oddly next to a grammar that, under require_call, does change what can be sampled.

Impact: limited to cores with strict: true tools, but there a reader could conclude required and auto are behaviorally interchangeable in thinking mode, when constrained sampling still forces a declared call before completion validation even runs.

Fix: qualify the clause, e.g. "in thinking mode they render the same prompt as "auto" (reasoning starts in <think>); a strict tool still constrains sampling so only a declared tool call can follow reasoning."

3. Accuracy of the change — verified sound

Severity: none. All statements traced at head:

The PR description's before/after quotes match docs/api.md main :666-669 versus head :666-678, and its "no runtime code, schemas, or compatibility contracts changed" claim matches the diff exactly.

4. System-level effects, concurrency, resources, metrics, platforms — clean

The only changed file is docs/api.md (pr_diff). No lock, queue, admission, scheduler, buffer, cache, checkpoint or serialization path is touched; no metric or rate definition changes scope, so there is no span shrink to trace. No code means no Unix/Windows parity exposure, no panic/error-handling surface, no stale-state-across-reset concern. Failure-propagation blast radius is unchanged: a required-mode DeepSeek thinking request that produces no call still fails at encode.rs:685-689 → HTTP 500 / terminal error event, exactly as docs/api.md:675-678 now describes.

5. Tests, process and claim accuracy

Open questions / not verified