Repository navigation
Conversation
Some models leak raw DSML tool-call markup into the reply text. It then shows up in chat, in batch replies and in streamed replies. The visible-text filters now hide DSML tool envelopes. Code examples, inline and fenced, are kept. An envelope split across stream chunks is hidden once it is complete. An unfinished envelope hides the rest of the text. The transport code that recovers real tool calls is not changed.
|
🦞👀 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 strips leaked DSML tool envelopes from assistant replies while preserving code examples. Example: A reply contains
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 5 items remain This PR addresses a real sanitizer gap, but its new filter introduces repeated whole-reply parsing and leaves supported DSML payloads exposed. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherShared text sanitizers receive assistant text from delivery, streaming, and history consumers and produce visible text without executing tool calls. flowchart LR
A[Provider text] --> B[Agent reply preparation]
B --> C[Shared visible text filters]
C --> D[Streaming projection]
C --> E[Final delivery and history]
D --> F[User visible reply]
E --> F
Technical reviewBest possible solution: Keep DSML presentation filtering in the shared sanitizer, cover the established grammar and invocation boundaries, and preserve bounded streaming work. Do we have a high-confidence way to reproduce the issue? Source traces the leakage and new parsing defects through the production sanitizer; no current-main runtime reproduction was executed. Is this the best way to solve the issue? The shared sanitizer is the appropriate owner, but its new grammar omits established forms and its activation bypasses existing streaming safeguards. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 05b455331de7. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +66, Tests +137. Total +203 across 6 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. Review metrics
LabelsLabel changes: No label 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 12, 2026, 9:33 PM ET / November 13, 2026, 02:33 UTC. |
…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]>
…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]>
Related: #169728, #175058 (these fix transport parsing only; this PR does not touch transport)
What Problem This Solves
Fixes: raw DeepSeek DSML tool-call markup shows up in the visible assistant reply when a model leaks it as text, in both batch and streamed replies.
Example reply text:
Let me check. <|DSML|tool_calls>...rm -rf /tmp/x...</|DSML|tool_calls> Done.User Impact
Users no longer see raw tool-call markup, or the command inside it, in chat replies. Code examples that show DSML tags in backticks or code fences are still shown as written.
Why This Change Was Made
#169728 and #175058 recover real tool calls in the transport. They do not clean the final visible text, so any leaked envelope still reaches the reader. Upstream
mainhas no DSML handling insrc/shared/text.The visible-text filters now hide DSML envelopes (
tool_calls,tool_call,function_calls,tool_use_error;|,|and||delimiters).Evidence
Tests, in
src/shared/text:main(5cbed85): 20 new tests fail (19 inassistant-visible-text.test.ts, 1 inassistant-internal-scaffolding.test.ts).pnpm test src/shared/textpasses, 226 tests in 5 files.tsgo:core,oxfmt --checkandoxlinton the 6 touched files are clean.Real built modules (
pnpm build, then a small script imports the built visible-text and text-projection chunks fromdistand feeds them leaked text). No model, gateway or provider was run.Let me check. <DSML envelope with exec command> Done.Let me check. Done.Let me check.thenLet me check. Done.In the stream case, the first chunk can show a partial opener (
<|DS) until the next chunk arrives.Raw output
Before:
After:
Environment: Linux, Node v26.13.1, build of 5cbed85 (before) and 128f37a (after).
Not tested: a live gateway or channel with a real DeepSeek model, and the full
pnpm lintand full test suite (left to CI).