Repository navigation
fix(ai): keep tool history native when a chat-completions request offers no tools - #206864
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR hides echoed bracket-style tool calls and results through the existing shared assistant-text filter. Example: A reply contains
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 2 items remain This PR addresses a real gap on current main and contains useful focused work, but one parsing defect blocks merge. Reviewed head: Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe shared presentation filters receive assistant text and produce sanitized streaming, final-delivery, and history projections without executing tool calls. flowchart LR
A[Stored tool history] --> B[Provider request serializer]
B --> C[Model response text]
C --> D[Shared presentation filters]
D --> E[Streaming projection]
D --> F[Final reply and history]
Technical reviewBest possible solution: Keep the existing presentation owner and classify replay headers by their syntax so valid call IDs cannot leave arguments exposed. Do we have a high-confidence way to reproduce the issue? Source establishes the serializer/filter mismatch and the colon-ID failure path; no target code or current-main end-to-end reproduction was run during this read-only review. Is this the best way to solve the issue? Extending the existing shared filter is appropriately scoped, but header classification must distinguish syntax independently of characters inside IDs. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a3954edd50a5. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +17, Tests +26. Total +43 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 27, 2026, 1:16 PM ET / 18:16 UTC. |
- The frames come from the request builder; the producer fix follows. - Restores src/shared/text to the merge base.
…ers no tools - With no tools offered there is no catalog to reconcile history against, so calls and results stay native tool_calls/tool messages instead of assistant bracket text the model imitates. - Denied or removed tools in a non-empty catalog still replay as text (openclaw#174797); supportsTools=false models unchanged. Fixes openclaw#205127
|
Proof lines for head |
|
Rejected review findings:
|
- Reads the inventory once through the tool projection, so an unreadable inventory is not re-read. - The request builder is the only owner of the declared catalog; convertMessages no longer derives one from context.tools.
|
Landed in 5218d21. After a cut-off tool-heavy turn, the tool-free "write the final answer" request now keeps the turn's tool history as native tool calls instead of rewriting it as |
…ers no tools (#206864) Root cause: `packages/ai/src/transports/openai-completions-params.ts:302` built an empty `declaredToolNames` set when a Chat Completions request offers no tools, so `packages/ai/src/openai-completions-messages.ts:189` turned every earlier tool call and result into assistant-role `[tool call id=… name=…]` / `[tool result id=… name=…]` text. The tool-free request that writes the final answer after a cut-off tool turn then showed the model its own turn in that format, and the model copied it into the reply. Fixes #205127 Thanks @ningchen-2333 for the report and screenshot, and @zsicheng0214 for the first fix and for pinning down the exact frame format. This PR keeps their commit and builds on it. ## What Problem This Solves When a tool-heavy turn ended without a final answer, OpenClaw sent one more request with tools turned off to get the answer. Since #174797 (`8fc3509a66ad`), that request sent the turn's tool calls and results as plain assistant text. The model (DeepSeek in the report, and our scripted model) copied that text, so the user got `[tool call id=… name=exec] {…}` and `[tool result id=…]` lines instead of an answer. ## Fix A request that offers no tools has no tool list to check history against, so its history now stays in normal `tool_calls` + `tool` messages, as it did before #174797. The change is about 5 production lines in the two files above. Unchanged: - A tool that was denied or removed, in a request that still offers other tools, is still replayed as text (#174797). - Models with `compat.supportsTools: false` still get text. - Tool Search directory tools such as `web_search` stay native (#202436). The first commit removes the display filter change from this PR's original approach. It hid the lines after the model had already written them, so the user still got no real answer, and it had an open edge case with ids like `read:0`. Not in this PR: orphan DeepSeek DSML closing tags (`</||DSML|| parameter>`) are tracked in #198042 / #198043. ## Evidence Gateway from source with isolated state. An openai-completions provider points at a loopback fixture that records each request. The scripted model makes two `exec` calls, then sends an empty `stop` reply so the final-answer request runs. When a request offers no tools, the model repeats any bracket frames in the last assistant text, otherwise it says "Summary: done." | | base `f77ce263f6a1` | this PR | |---|---|---| | final-answer request history | assistant text with 4 `[tool call/result id=…]` frames | `assistant tool_calls[exec,exec]`, 2× `tool` | | reply and `chat.history` | the 4 frames with the `exec` arguments and output | `Summary: done.` | | control: `exec` denied after use | history as text | history as text | | control: `supportsTools: false` model | history as text | history as text | | control: Tool Search `web_search` | native | native | Unit: the new case in `openai-completions-replay.test.ts` (tools `[]` and absent) and the restored pre-#174797 expectation in `openai-completions-params.test.ts` fail on base and pass here. Proof lines: #206864 (comment) Not run: a real `deepseek-v4-flash` session (no DeepSeek key is available to us). `strictMessageKeys`: no bundled provider sets it. It is a user opt-in for local servers. Such backends get `role`/`content` only, as before #174797, which is what they get on every normal turn with tools. Merge danger: two-way door. No stored state, config or published contract changes, and a revert restores the current text projection. Blast radius: Chat Completions requests with tool history and no tools (the final-answer request after a cut-off turn, `/btw`, keep-warm forks). A provider that rejects `tool_calls` history without a tools list would now see it again; that was the shipped behavior before 2026.11.6. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 5218d21)
…ers no tools (openclaw#206864) Root cause: `packages/ai/src/transports/openai-completions-params.ts:302` built an empty `declaredToolNames` set when a Chat Completions request offers no tools, so `packages/ai/src/openai-completions-messages.ts:189` turned every earlier tool call and result into assistant-role `[tool call id=… name=…]` / `[tool result id=… name=…]` text. The tool-free request that writes the final answer after a cut-off tool turn then showed the model its own turn in that format, and the model copied it into the reply. Fixes openclaw#205127 Thanks @ningchen-2333 for the report and screenshot, and @zsicheng0214 for the first fix and for pinning down the exact frame format. This PR keeps their commit and builds on it. ## What Problem This Solves When a tool-heavy turn ended without a final answer, OpenClaw sent one more request with tools turned off to get the answer. Since openclaw#174797 (`ddca1ffc7df8`), that request sent the turn's tool calls and results as plain assistant text. The model (DeepSeek in the report, and our scripted model) copied that text, so the user got `[tool call id=… name=exec] {…}` and `[tool result id=…]` lines instead of an answer. ## Fix A request that offers no tools has no tool list to check history against, so its history now stays in normal `tool_calls` + `tool` messages, as it did before openclaw#174797. The change is about 5 production lines in the two files above. Unchanged: - A tool that was denied or removed, in a request that still offers other tools, is still replayed as text (openclaw#174797). - Models with `compat.supportsTools: false` still get text. - Tool Search directory tools such as `web_search` stay native (openclaw#202436). The first commit removes the display filter change from this PR's original approach. It hid the lines after the model had already written them, so the user still got no real answer, and it had an open edge case with ids like `read:0`. Not in this PR: orphan DeepSeek DSML closing tags (`</||DSML|| parameter>`) are tracked in openclaw#198042 / openclaw#198043. ## Evidence Gateway from source with isolated state. An openai-completions provider points at a loopback fixture that records each request. The scripted model makes two `exec` calls, then sends an empty `stop` reply so the final-answer request runs. When a request offers no tools, the model repeats any bracket frames in the last assistant text, otherwise it says "Summary: done." | | base `92610aca7d2c` | this PR | |---|---|---| | final-answer request history | assistant text with 4 `[tool call/result id=…]` frames | `assistant tool_calls[exec,exec]`, 2× `tool` | | reply and `chat.history` | the 4 frames with the `exec` arguments and output | `Summary: done.` | | control: `exec` denied after use | history as text | history as text | | control: `supportsTools: false` model | history as text | history as text | | control: Tool Search `web_search` | native | native | Unit: the new case in `openai-completions-replay.test.ts` (tools `[]` and absent) and the restored pre-openclaw#174797 expectation in `openai-completions-params.test.ts` fail on base and pass here. Proof lines: openclaw#206864 (comment) Not run: a real `deepseek-v4-flash` session (no DeepSeek key is available to us). `strictMessageKeys`: no bundled provider sets it. It is a user opt-in for local servers. Such backends get `role`/`content` only, as before openclaw#174797, which is what they get on every normal turn with tools. Merge danger: two-way door. No stored state, config or published contract changes, and a revert restores the current text projection. Blast radius: Chat Completions requests with tool history and no tools (the final-answer request after a cut-off turn, `/btw`, keep-warm forks). A provider that rejects `tool_calls` history without a tools list would now see it again; that was the shipped behavior before 2026.11.6. Co-authored-by: Ayaan Zaidi <[email protected]>
…ers no tools (#206864) Root cause: `packages/ai/src/transports/openai-completions-params.ts:302` built an empty `declaredToolNames` set when a Chat Completions request offers no tools, so `packages/ai/src/openai-completions-messages.ts:189` turned every earlier tool call and result into assistant-role `[tool call id=… name=…]` / `[tool result id=… name=…]` text. The tool-free request that writes the final answer after a cut-off tool turn then showed the model its own turn in that format, and the model copied it into the reply. Fixes #205127 Thanks @ningchen-2333 for the report and screenshot, and @zsicheng0214 for the first fix and for pinning down the exact frame format. This PR keeps their commit and builds on it. When a tool-heavy turn ended without a final answer, OpenClaw sent one more request with tools turned off to get the answer. Since #174797 (`8fc3509a66ad`), that request sent the turn's tool calls and results as plain assistant text. The model (DeepSeek in the report, and our scripted model) copied that text, so the user got `[tool call id=… name=exec] {…}` and `[tool result id=…]` lines instead of an answer. A request that offers no tools has no tool list to check history against, so its history now stays in normal `tool_calls` + `tool` messages, as it did before #174797. The change is about 5 production lines in the two files above. Unchanged: - A tool that was denied or removed, in a request that still offers other tools, is still replayed as text (#174797). - Models with `compat.supportsTools: false` still get text. - Tool Search directory tools such as `web_search` stay native (#202436). The first commit removes the display filter change from this PR's original approach. It hid the lines after the model had already written them, so the user still got no real answer, and it had an open edge case with ids like `read:0`. Not in this PR: orphan DeepSeek DSML closing tags (`</||DSML|| parameter>`) are tracked in #198042 / #198043. Gateway from source with isolated state. An openai-completions provider points at a loopback fixture that records each request. The scripted model makes two `exec` calls, then sends an empty `stop` reply so the final-answer request runs. When a request offers no tools, the model repeats any bracket frames in the last assistant text, otherwise it says "Summary: done." | | base `f77ce263f6a1` | this PR | |---|---|---| | final-answer request history | assistant text with 4 `[tool call/result id=…]` frames | `assistant tool_calls[exec,exec]`, 2× `tool` | | reply and `chat.history` | the 4 frames with the `exec` arguments and output | `Summary: done.` | | control: `exec` denied after use | history as text | history as text | | control: `supportsTools: false` model | history as text | history as text | | control: Tool Search `web_search` | native | native | Unit: the new case in `openai-completions-replay.test.ts` (tools `[]` and absent) and the restored pre-#174797 expectation in `openai-completions-params.test.ts` fail on base and pass here. Proof lines: #206864 (comment) Not run: a real `deepseek-v4-flash` session (no DeepSeek key is available to us). `strictMessageKeys`: no bundled provider sets it. It is a user opt-in for local servers. Such backends get `role`/`content` only, as before #174797, which is what they get on every normal turn with tools. Merge danger: two-way door. No stored state, config or published contract changes, and a revert restores the current text projection. Blast radius: Chat Completions requests with tool history and no tools (the final-answer request after a cut-off turn, `/btw`, keep-warm forks). A provider that rejects `tool_calls` history without a tools list would now see it again; that was the shipped behavior before 2026.11.6. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 5218d21) Companion audit: 7b82c14 no-empty-tools is present in stable and must be preserved; ac3a457 tool-schema strictness is independent. Release adaptation: Adapt stable paired result classification as well as tool call classification. Keep omitted request tools and results with a declared catalog unchanged. Co-authored-by: RomneyDa <[email protected]>
Root cause:
packages/ai/src/transports/openai-completions-params.ts:302built an emptydeclaredToolNamesset when a Chat Completions request offers no tools, sopackages/ai/src/openai-completions-messages.ts:189turned every earlier tool call and result into assistant-role[tool call id=… name=…]/[tool result id=… name=…]text. The tool-free request that writes the final answer after a cut-off tool turn then showed the model its own turn in that format, and the model copied it into the reply.Fixes #205127
Thanks @ningchen-2333 for the report and screenshot, and @zsicheng0214 for the first fix and for pinning down the exact frame format. This PR keeps their commit and builds on it.
What Problem This Solves
When a tool-heavy turn ended without a final answer, OpenClaw sent one more request with tools turned off to get the answer. Since #174797 (
8fc3509a66ad), that request sent the turn's tool calls and results as plain assistant text. The model (DeepSeek in the report, and our scripted model) copied that text, so the user got[tool call id=… name=exec] {…}and[tool result id=…]lines instead of an answer.Fix
A request that offers no tools has no tool list to check history against, so its history now stays in normal
tool_calls+toolmessages, as it did before #174797. The change is about 5 production lines in the two files above.Unchanged:
compat.supportsTools: falsestill get text.web_searchstay native (fix: keep web_search via Tool Search working on chat-completions providers that reject assistant prefill #202436).The first commit removes the display filter change from this PR's original approach. It hid the lines after the model had already written them, so the user still got no real answer, and it had an open edge case with ids like
read:0.Not in this PR: orphan DeepSeek DSML closing tags (
</||DSML|| parameter>) are tracked in #198042 / #198043.Evidence
Gateway from source with isolated state. An openai-completions provider points at a loopback fixture that records each request. The scripted model makes two
execcalls, then sends an emptystopreply so the final-answer request runs. When a request offers no tools, the model repeats any bracket frames in the last assistant text, otherwise it says "Summary: done."f77ce263f6a1[tool call/result id=…]framesassistant tool_calls[exec,exec], 2×toolchat.historyexecarguments and outputSummary: done.execdenied after usesupportsTools: falsemodelweb_searchUnit: the new case in
openai-completions-replay.test.ts(tools[]and absent) and the restored pre-#174797 expectation inopenai-completions-params.test.tsfail on base and pass here.Proof lines: #206864 (comment)
Not run: a real
deepseek-v4-flashsession (no DeepSeek key is available to us).strictMessageKeys: no bundled provider sets it. It is a user opt-in for local servers. Such backends getrole/contentonly, as before #174797, which is what they get on every normal turn with tools.Merge danger: two-way door. No stored state, config or published contract changes, and a revert restores the current text projection. Blast radius: Chat Completions requests with tool history and no tools (the final-answer request after a cut-off turn,
/btw, keep-warm forks). A provider that rejectstool_callshistory without a tools list would now see it again; that was the shipped behavior before 2026.11.6.