diff --git a/benchmarks/fixtures/responses/commentary-tool-prompt.json b/benchmarks/fixtures/responses/commentary-tool-prompt.json new file mode 100644 index 00000000..4ddefaf9 --- /dev/null +++ b/benchmarks/fixtures/responses/commentary-tool-prompt.json @@ -0,0 +1,40 @@ +{ + "provenance": "Pinned engine/strata/serve/chat_template.jinja rendered with Jinja2 3.1.6; sanitized fixture", + "request": { + "model": "strata-local", + "reasoning": { + "effort": "none" + }, + "input": [ + { + "role": "user", + "content": "Weather in Oslo?" + }, + { + "type": "reasoning", + "content": [ + { + "type": "reasoning_text", + "text": "Use the lookup." + } + ] + }, + { + "role": "assistant", + "content": "Checking. \n" + }, + { + "type": "function_call", + "call_id": "call_fixture", + "name": "lookup", + "arguments": "{\"city\":\"Oslo\"}" + }, + { + "type": "function_call_output", + "call_id": "call_fixture", + "output": "3°C" + } + ] + }, + "rendered": "<|im_start|>user\nWeather in Oslo?<|im_end|>\n<|im_start|>assistant\n\nUse the lookup.\n\n\nChecking.\n\n\n\n\nOslo\n\n\n<|im_end|>\n<|im_start|>user\n\n3°C\n<|im_end|>\n<|im_start|>assistant\n\n\n\n\n" +} diff --git a/control-plane/src/responses.rs b/control-plane/src/responses.rs index a88ae771..e4fb7bb4 100644 --- a/control-plane/src/responses.rs +++ b/control-plane/src/responses.rs @@ -885,7 +885,20 @@ fn render_request_prompt(request: &CreateRequest) -> Result { { owned.push((Role::Assistant, String::new(), Some(thought))); } - owned.push((role, content, reasoning.take())); + if role == Role::Assistant + && let Some((Role::Assistant, previous, thought)) = owned.last_mut() + { + if !previous.is_empty() && !content.is_empty() { + previous.push('\n'); + } + previous.push_str(&content); + if let Some(next) = reasoning.take() { + let current = thought.get_or_insert_with(String::new); + current.push_str(&next); + } + } else { + owned.push((role, content, reasoning.take())); + } } "function_call" => { if !outputs.is_empty() { @@ -985,7 +998,18 @@ fn render_request_prompt(request: &CreateRequest) -> Result { .map(|(_, value)| format!("\n{value}\n")) .collect::>() .join("\n"); - owned.push((Role::Assistant, call_text, reasoning.take())); + if let Some((Role::Assistant, content, thought)) = owned.last_mut() { + content.truncate(content.trim_end().len()); + if !content.is_empty() { + content.push_str("\n\n"); + } + content.push_str(&call_text); + if let Some(next) = reasoning.take() { + thought.get_or_insert_with(String::new).push_str(&next); + } + } else { + owned.push((Role::Assistant, call_text, reasoning.take())); + } owned.push((Role::User, output_text, None)); calls.clear(); outputs.clear(); @@ -2205,6 +2229,16 @@ mod tests { fs::remove_dir_all(root).unwrap(); } + #[test] + fn commentary_reasoning_and_tools_match_pinned_template_as_one_assistant_turn() { + let golden: Value = serde_json::from_str(include_str!( + "../../benchmarks/fixtures/responses/commentary-tool-prompt.json" + )) + .unwrap(); + let request: CreateRequest = serde_json::from_value(golden["request"].clone()).unwrap(); + assert_eq!(render_request_prompt(&request).unwrap(), golden["rendered"]); + } + #[test] fn console_late_approval_instructions_retain_authority_and_content() { let request = make_request(json!({"instructions":"Initial instructions", "input":[ diff --git a/docs/api-contract.md b/docs/api-contract.md index ebbb8925..a8b6a915 100644 --- a/docs/api-contract.md +++ b/docs/api-contract.md @@ -163,3 +163,9 @@ Approval/review requests can append developer messages after user input. The native adapter stably coalesces these instruction messages into the leading Qwen system section, preserving their content and order. It does not demote approval instructions to user messages or bypass the console's review step. + +Stateless replay keeps adjacent assistant commentary and function calls in one +assistant turn, with their reasoning content attached. The commentary-to-call +separator matches the pinned Qwen template, including trimming commentary's +trailing whitespace. The sanitized `commentary-tool-prompt.json` fixture checks +this against an independently rendered upstream template, byte for byte. diff --git a/docs/build-validation.md b/docs/build-validation.md index 0de88d92..bca42d8e 100644 --- a/docs/build-validation.md +++ b/docs/build-validation.md @@ -445,3 +445,21 @@ soak still remain; hosted Actions has not run. namespaced item identity, tool text-part replay, and late approval instructions. A fresh install into a temporary launcher copy matches the installed integration byte-for-byte; a second install is idempotent. +- The fresh console run after those fixes had no transport/protocol errors and + produced a game that passed 23/23 independent browser checks (all eight win + lines, locked terminal boards, restart, draw, occupied-cell handling, mobile + clicking/layout, and no page errors). However, the agent stopped while + preparing its own browser verification; its MCP task TEST-9 remained + incomplete. Exit code zero and `turn.completed` are not sufficient evidence + of task completion. No assistance or continuation prompt was supplied. +- That incomplete run took 452.02 s. The console reported 21,622 output tokens, + including 9,225 reasoning tokens. The engine recorded 24 requests including + approval reviews, 23,180 generated tokens and weighted decode 102.26 tok/s + (per-request median 103.75; p10–p90 70.0–129.75). These are diagnostic numbers + from an incomplete task, not a paired throughput improvement. +- Further prompt inspection found that commentary and a subsequent tool call + from the same response were replayed as separate assistant turns. They now + remain one turn, with reasoning retained and the pinned Qwen template's exact + spacing. A sanitized golden fixture was generated using the pinned local + template with Jinja2 3.1.6; native rendering matches it byte-for-byte. A fresh + independent run is needed to qualify this revision.