Repository navigation
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: malformed tool history panics, and accepted structured-output forms lose their prompt schemas.
Must fix
1. Reject non-object historical functions before mutation
crates/serve/src/v41.rs:88 On the official V4.1 seat, a chat request with messages: [{"role":"assistant","tool_calls":[{"function":7}]}] passes the request checks and text guard, then reaches this indexed assignment through prepare. Indexing the number panics and closes the connection without an HTTP error. Reject it before this normalizer becomes the default.
Replace the definition below and change the call in prepare to tool_arguments(request.messages)?;. Add an HTTP 400 assertion for this input.
pub fn tool_arguments(messages: &mut [Value]) -> Result<(), String> {
for (i, message) in messages.iter_mut().enumerate() {
let Some(Value::Array(calls)) = message.get_mut("tool_calls") else {
continue;
};
for (j, call) in calls.iter_mut().enumerate() {
let function = call.get_mut("function")
.and_then(Value::as_object_mut)
.ok_or_else(|| format!(
"messages[{i}].tool_calls[{j}].function must be an object"
))?;
let text = match function.get("arguments") {
Some(Value::String(text)) => text.clone(),
Some(Value::Object(_)) => continue,
Some(other) => other.to_string(),
None => String::new(),
};
let object = serde_json::from_str::<Map<String, Value>>(&text)
.unwrap_or_else(|_| Map::from_iter([
("arguments".to_owned(), Value::String(text)),
]));
function.insert(
"arguments".to_owned(),
Value::String(Value::Object(object).to_string()),
);
}
}
Ok(())
}2. Render the accepted flat tool-choice and schema forms
crates/serve/src/templates/v41-official.jinja:31 constrain/schema.rs:573–579,625–631 accepts flat named choices and response schemas. The Responses adapter preserves tool_choice: {"type":"function","name":"f"}. With matching tools, the template sets named to undefined and filters out every tool schema. Independently, lines 39–40 omit an accepted response_format: {"type":"json_schema","schema":...}.
Align preparation with constrained decoding before serving these requests.
Replace line 31:
{%- set named = choice['function']['name'] | default(choice['name']) -%}Replace lines 39–40:
{%- elif rf['type'] == 'json_schema' and (rf['json_schema']['schema'] is defined or rf['schema'] is defined) -%}
{%- set rf_schema = rf['json_schema']['schema'] | default(rf['schema']) | tojson -%}Add flat-form cases beside the nested fixtures; the current fixtures miss both omissions.
3. Reuse the existing template constant
crates/serve/src/ctl_tests.rs:27 duplicates crates/serve/src/v41.rs:23: both constants own the same template inclusion. R14 requires one owner.
Remove the duplicate now so the control-token tests use the served template's owner.
Delete V41_OFFICIAL_TEMPLATE and replace its use in templates():
all.push(("v41-official", crate::v41::TEMPLATE));4. Remove the unused ChatSurface preparation field
crates/gpu-gates/src/bind.rs:308 is initialized only to None and is never assigned. The V4.1 seat carries its preparation in a separate local and discards this field. The generic seat forwards that None.
Remove it before callers inherit dead configuration.
Update its description and definition:
pub struct ChatSurface {
/// The explicit template or the model file's template.
pub template: String,
/// The model name or the seat's default alias.
pub name: String,
}Replace the construction in ChatSurface::read with:
Ok(ChatSurface { template, name })In SeatFlags::bind, replace preparation: chat.preparation, with:
preparation: None,5. Inline the selector with one caller
crates/gpu-gates/src/bind.rs:287 introduces a public abstraction for future seats. Its only caller is V4.1; no second caller appears in this diff.
Remove it now instead of maintaining an API around one Option guard.
Delete official_template, its documentation and its import in ds41.rs. Replace the match header at ds41.rs:588:
match official.filter(|_| a.template_file.path().is_none()) {Checked
Duplicates/elements: verified both constants, all ChatSurface constructors, and the selector's sole caller.
Complexity: template selection and hook dispatch; no kernel edits.
Silent failure: malformed history passes guards and reaches indexed mutation.
Tests: prompt-byte fixtures omit both flat forms and malformed functions.
Gates: no pins moved or cases removed.
Escape catalog and ledger: no applicable patterns.
Notes
Static validation only; Rust tests were not run. The PR supplies no card-gate or FAIL-first output.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs, crates/gpu-gates/src/bin/shared/serve_seats/glm.rs, crates/gpu-gates/src/bin/shared/serve_seats/qwen3.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
| {%- set renders_tools = has_tools and choice != 'none' -%} | ||
| {%- set named = none -%} | ||
| {%- if choice is not none and choice is not string and choice['type'] == 'function' -%} | ||
| {%- set named = choice['function']['name'] -%} |
There was a problem hiding this comment.
Fall back to the flat named-tool choice accepted by the Responses path and request validator.
| {%- set named = choice['function']['name'] -%} | |
| {%- set named = choice['function']['name'] | default(choice['name']) -%} |
| {%- elif rf['type'] == 'json_schema' and rf['json_schema'] is defined and rf['json_schema']['schema'] is defined -%} | ||
| {%- set rf_schema = rf['json_schema']['schema'] | tojson -%} |
There was a problem hiding this comment.
Include the flat JSON schema accepted by the request validator.
| {%- elif rf['type'] == 'json_schema' and rf['json_schema'] is defined and rf['json_schema']['schema'] is defined -%} | |
| {%- set rf_schema = rf['json_schema']['schema'] | tojson -%} | |
| {%- elif rf['type'] == 'json_schema' and (rf['json_schema']['schema'] is defined or rf['schema'] is defined) -%} | |
| {%- set rf_schema = rf['json_schema']['schema'] | default(rf['schema']) | tojson -%} |
There was a problem hiding this comment.
Verdict: MUST_FIX: malformed tool metadata can panic, unsupported roles disappear, and template plumbing has duplicate or unused elements.
Must fix
1. Return an error for a non-object function
crates/serve/src/v41.rs:88 With the V4.1 preparation enabled, POST /apply-template with {"messages":[{"role":"assistant","tool_calls":[{"function":1}]}]} passes render_chat validation and reaches JSON indexing on a scalar. The connection thread panics before sending an HTTP error.
Validate at the owner before callers multiply. Replace this definition; in prepare, call tool_arguments(request.messages)?;. Add a named-400 regression.
fn tool_arguments(messages: &mut [Value]) -> Result<(), String> {
for (i, message) in messages.iter_mut().enumerate() {
let calls = match message.get_mut("tool_calls") {
None | Some(Value::Null) => continue,
Some(Value::Array(calls)) => calls,
Some(_) => return Err(format!("messages[{i}].tool_calls must be an array")),
};
for (j, call) in calls.iter_mut().enumerate() {
let function = call.get_mut("function")
.and_then(Value::as_object_mut)
.ok_or_else(|| format!(
"messages[{i}].tool_calls[{j}].function must be an object"
))?;
let text = match function.get("arguments") {
Some(Value::String(text)) => text.clone(),
Some(Value::Object(_)) => continue,
Some(other) => other.to_string(),
None => String::new(),
};
let arguments = match serde_json::from_str::<Map<String, Value>>(&text) {
Ok(object) => Value::Object(object),
Err(_) => Value::Object(Map::from_iter([
("arguments".to_owned(), Value::String(text)),
])),
};
function.insert("arguments".into(), Value::String(arguments.to_string()));
}
}
Ok(())
}2. Reject message roles the template cannot encode
crates/serve/src/templates/v41-official.jinja:143 A message with role: "critic" passes the server's string-role check. No branch consumes it: /apply-template returns 200 without its content and generation loses the instruction.
Reject unknown roles before clients depend on silent loss. Insert before this endif:
{%- else -%}
{{- raise_exception('unsupported message role: ' + role) -}}3. Reuse the template constant
crates/serve/src/ctl_tests.rs:27 duplicates crates/serve/src/v41.rs:23: both constants own the same template include path (R14).
Avoid maintaining two bindings. Delete V41_OFFICIAL_TEMPLATE; replace its table entry:
all.push(("v41-official", crate::v41::TEMPLATE));4. Remove unused surface state and helper surface
crates/gpu-gates/src/bind.rs:308 is always None; V4.1 carries its preparation separately. official_template also wraps one condition for one caller.
Remove these before other seats depend on them. Restore:
pub struct ChatSurface {
/// The override template, else the model file's template.
pub template: String,
/// The model file's name, else the seat's default alias.
pub name: String,
}In ChatSurface::read, replace the constructor with Ok(ChatSurface { template, name }). In SeatFlags::listen, replace preparation: chat.preparation with preparation: None. Delete official_template and its import; replace the match header at crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs:588 with:
match official.filter(|_| a.template_file.path().is_none()) {Make crates/serve/src/v41.rs:99 private too: order_tool_results has only a same-module caller (R13). Use fn order_tool_results(messages: &mut [Value]) {.
Non-blocking
⚠ Pin argument normalization: crates/serve/src/v41.rs:33. Deleting this call leaves the fixtures unchanged: their historical arguments already encode objects. Add non-JSON and scalar-JSON fixtures with exact expected text to protect the fallback.
Checked
Duplicates: template bindings confirmed; helper and field uses searched across the tree. Dryer reports 0 pairs and excludes gpu-gates.
Complexity: diagnostics report ds41::run 60 → 64 (template selection), render_chat 27 → 29 (preparation dispatch).
Failure paths: checked validation, guarding, preparation, rendering and HTTP response handling.
Tests: all 3 historical tool calls in the 26-case fixture encode JSON objects; none exercises normalization's fallback. Mutation reasoning was static.
Gates: no existing pins or cases removed. Escape catalog C1–C4: no matches.
Notes
Tests were not run. The PR supplies Mac check results, but no FAIL-first output or complete GPU gate evidence.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs, crates/gpu-gates/src/bin/shared/serve_seats/glm.rs, crates/gpu-gates/src/bin/shared/serve_seats/qwen3.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
| {%- elif role == 'latest_reminder' -%} | ||
| {{- reminder_token + (message['content'] or '') -}} | ||
| {%- set ns.prev = 'other' -%} | ||
| {%- endif -%} |
There was a problem hiding this comment.
Reject unsupported message roles instead of silently dropping their content.
| {%- endif -%} | |
| {%- else -%}{{- raise_exception('unsupported message role: ' + role) -}} | |
| {%- endif -%} |
|
Landing batch (fixture tier): 23 gates from |
There was a problem hiding this comment.
Since the last review: the panic and silent message-loss findings remain open. The new predicate finding is item 3.
Verdict: MUST_FIX: malformed tool calls panic, unsupported roles silently disappear, and the gate adds an unnecessary wrapper.
Must fix
1. Return an error for a non-object function
Still open: crates/serve/src/v41.rs:88. With V4.1 preparation, POST /apply-template with {"messages":[{"role":"assistant","tool_calls":[{"function":1}]}]} passes render_chat's message checks and reaches prepare → tool_arguments. Indexing the numeric function panics on the connection thread instead of returning an HTTP error.
Validate at the owner before more callers depend on it. In prepare, call tool_arguments(request.messages)?;. Replace the definition and add a named-400 regression:
fn tool_arguments(messages: &mut [Value]) -> Result<(), String> {
for (i, message) in messages.iter_mut().enumerate() {
let calls = match message.get_mut("tool_calls") {
None | Some(Value::Null) => continue,
Some(Value::Array(calls)) => calls,
Some(_) => return Err(format!("messages[{i}].tool_calls must be an array")),
};
for (j, call) in calls.iter_mut().enumerate() {
let function = call.get_mut("function")
.and_then(Value::as_object_mut)
.ok_or_else(|| format!(
"messages[{i}].tool_calls[{j}].function must be an object"
))?;
let text = match function.get("arguments") {
Some(Value::String(text)) => text.clone(),
Some(Value::Object(_)) => continue,
Some(other) => other.to_string(),
None => String::new(),
};
let arguments = match serde_json::from_str::<Map<String, Value>>(&text) {
Ok(object) => Value::Object(object),
Err(_) => Value::Object(Map::from_iter([
("arguments".into(), Value::String(text)),
])),
};
function.insert("arguments".into(), Value::String(arguments.to_string()));
}
}
Ok(())
}2. Reject unsupported message roles
Still open: crates/serve/src/templates/v41-official.jinja:143. POST /apply-template with {"messages":[{"role":"critic","content":"keep me"}]} passes the string-role check at api.rs:2509, takes no template branch, and returns HTTP 200 without the message content.
Reject it before clients depend on silent loss. Insert before this endif:
{%- else -%}
{{- raise_exception('unsupported message role: ' + role) -}}3. Inline the single-use family predicate
crates/gpu-gates/src/bin/gate_serve_start.rs:159 adds a method used only once. Its two arms are exactly self == Family::Glm.
Delete the method now; this removes a name and a branch table. Replace its call at line 918:
ok &= if self.family == Family::Glm {Checked
Duplicates/elements: both added methods inspected; the predicate has one caller, while template_args has two.
Complexity: template_file adds a startup and comparison.
Silent failure: new file-write, startup, health, render and stop errors reach the s5 failure result.
Tests: ignoring the override at bind.rs:324 loses FILE_MARK and fails s5; ignoring the override flag at ds41.rs:588 fails the new default comparison. Mutation checks were static.
Gates: s5 baseline adapted to the official default; no numeric pins moved. Escape catalog C1–C4: no matches.
Notes
Gates were not run. The PR has no FAIL-first output or complete GPU gate evidence.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_serve_start.rs, crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs, crates/gpu-gates/src/bin/shared/serve_seats/glm.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
…ily request preparation The V4.1 GGUF files carry a V4 chat template. The official V4.1 encoding opens with the system token and the reasoning effort line, and writes the tool choice and the response format into the first system message. The template renders the official encoder's text byte for byte on 25 request shapes (fixture from deepseek-recipe 935817c); the server hands a family's request preparation the messages and vars before the render, and None keeps every other template as it was. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…emplate-file is given Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nmarked file, and names whether the seat's default is the file's template Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n refuses a malformed tool call by name and the template an unknown role; two argument-fallback fixture cases Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eat picks the official template in place Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review fixes: a malformed tool call and an unknown role now each return a named 400 (a template's own refusal is the request's 400), |
There was a problem hiding this comment.
Since the last review: item 1 (non-object function panic) is fixed in v41.rs:71 with a named 400 and a test on both paths. Item 2 (unknown role) is fixed: the template raises at v41-official.jinja:145, and the 400 is tested. Item 3 (single-use predicate) is still open (see below).
Verdict: MUST_FIX: one unneeded single-use method is still in the gate.
Must fix
1. Inline the single-use family predicate
Still open: crates/gpu-gates/src/bin/gate_serve_start.rs:159. serves_the_files_template has one caller (line 918) and its two arms are exactly self == Family::Glm. Line 857 already tests self.family == Family::Glm directly. The method adds a name and a match for no second user.
Cost: deleting it now removes 9 lines and one name. Delete lines 157 to 165 and change line 918:
ok &= if self.family == Family::Glm {Non-blocking
⚠ A tool call with no string name is a 500, not a 400: crates/serve/src/templates/v41-official.jinja:121. {"role":"assistant","tool_calls":[{"function":{}}]} passes tool_arguments (it checks only that function is an object) and the template then concatenates an undefined name; the jinja Add arm returns cannot add ... (crates/jinja/src/lib.rs:2667), which is not a refusal, so it maps to a 500. This is a client error shown as a server fault. If you want a 400, check name in tool_arguments next to the function check. Not run.
Checked
Duplicates: 6 new items checked (refusal, REFUSAL, template_error, the new tests, tool_arguments changes), none duplicated. dryer: 0 pairs.
Complexity: render_chat 27 → 29 (the 500 map moved to template_error: even growth). ds41::run 60 → 64 (the official.filter replaces a helper; one match arm: even growth). Gate::template_file 9 → 14 was in the earlier commits and is unchanged since.
Silent failure: 3 sites followed. The malformed tool_calls and function return named errors. The unknown role raises. A template refusal goes to a 400 through TemplateError::refusal.
Tests: removing .and_then(Value::as_object_mut) makes {"function":1} panic or pass and turns the_v41_preparation_refuses_a_malformed_tool_call_by_name red. Dropping the else branch at v41-official.jinja:144 turns the_v41_template_refuses_a_role_it_cannot_encode red. Static check; not run.
Gates: no pins moved. The two new fixture cases pin the JSON-fallback rule.
Escape catalog: no match.
Notes
Gates were not run, and the PR carries no card evidence. The author's earlier open question (thinking default on) is the maintainer's call.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_serve_start.rs, crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs, crates/gpu-gates/src/bin/shared/serve_seats/glm.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Since the last review: the single-use predicate is fixed at crates/gpu-gates/src/bin/gate_serve_start.rs:910.
Verdict: CLEAN: the remaining must-fix is resolved, and the replacement preserves both families' gate behavior.
Checked
Duplicates: 0 new items; the removed predicate has no remaining references. dryer reported 0 pairs; gpu-gates was excluded, so the changed hunk was checked manually.
Complexity: crapper flagged Gate::template_file (9 → 14), ds41::run (60 → 64), and render_chat (27 → 29). These increases predate this increment; it adds no branches.
Silent failure: 0 added sites. Failed assertions still propagate through the gate's boolean accumulator.
Tests: no tests added or changed. A static truth-table check confirmed equivalence for Glm and Ds41; unknown families are rejected by the parser.
Gates: no assertions, cases, thresholds or pins changed.
Escape catalog: no C1–C4 patterns matched.
Performance: only gate code changed; no inference hot path changed.
Notes
GPU gates were not run. The PR carries Mac checks but no card gate evidence meeting CONTRIBUTING's evidence list.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_serve_start.rs, crates/gpu-gates/src/bin/shared/serve_seats/ds41.rs, crates/gpu-gates/src/bin/shared/serve_seats/glm.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
…erve's v41 module) #595 added one glm line to gate_serve_start (s5 asks which seat serves the file's template by default) and `pub mod v41` to serve's lib.rs, the V4.1 encoding module beside glmxml and qwenxml. check-model-tax failed on both, so contrib-check t0 has been red on main since the merge. Each row carries PIN(2026-10-21) and its reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The V4.1 seat now renders prompts the way DeepSeek's official encoding does, so tool calls, tool results,
tool_choiceandresponse_formatreach the model in the markup it was trained on.crates/serve/src/v41.rs+templates/v41-official.jinja: the official template and a request preparation (tool arguments as strings, tool results ordered,tool_choice/response_formatas template vars).serve::ChatPreparation: a generic hook a seat hands the server with its template.Nonekeeps today's rendering exactly (testa_server_without_a_preparation_ignores_the_tool_choice_and_the_response_format). No family name inapi.rs.--chat-template-fileis given, and prints aV41_OFFICIALline.crates/serve/tests/fixtures/v41-official/: 26 cases from the official encoder; 25 byte-equal (prefix continuation is not expressible in a chat request).Open question before merge: thinking defaults to on for the official template (the official default; the V4 template defaulted to off). A required tool choice in thinking mode is rendered, not refused.
Checks (Mac):
cargo test -p bloomery-serve335 passed;just mac-checkrc 0;cargo fmt --checkrc 0;tools/check-comments.shrc 0. Both special tokens (<|System|>,<|latest_reminder|>) are in the V4.1 GGUF vocab (checked on the box).Written with AI help (Claude Code); reviewed and checked by the maintainer.
🤖 Generated with Claude Code