Skip to content

fix: leaked DSML tool markup shows in visible assistant replies - #198043

Open
Grynn wants to merge 1 commit into
openclaw:mainfrom
Grynn:fix/visible-dsml-leak
Open

Grynn wants to merge 1 commit into
openclaw:mainfrom
Grynn:fix/visible-dsml-leak

Conversation

@Grynn

@Grynn Grynn commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

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 main has no DSML handling in src/shared/text.

The visible-text filters now hide DSML envelopes (tool_calls, tool_call, function_calls, tool_use_error; |, | and || delimiters).

  • Code spans, fenced blocks and indented code are left alone.
  • Quoted JSON inside an envelope cannot end it early.
  • An envelope split over stream chunks is hidden once it is recognized.
  • An unfinished or mismatched envelope hides the rest of the text, so private payload is not shown.
  • Nothing is executed or recovered here.

Evidence

Tests, in src/shared/text:

  • On plain main (5cbed85): 20 new tests fail (19 in assistant-visible-text.test.ts, 1 in assistant-internal-scaffolding.test.ts).
  • With this change: pnpm test src/shared/text passes, 226 tests in 5 files.
  • tsgo:core, oxfmt --check and oxlint on the 6 touched files are clean.

Real built modules (pnpm build, then a small script imports the built visible-text and text-projection chunks from dist and feeds them leaked text). No model, gateway or provider was run.

Input Before (main) After (this PR)
Batch: Let me check. <DSML envelope with exec command> Done. envelope and command shown Let me check. Done.
Stream, envelope split over 4 chunks full envelope shown Let me check. then Let me check. Done.
Batch and stream: code example in backticks kept kept

In the stream case, the first chunk can show a partial opener (<|DS) until the next chunk arrives.

Raw output

Before:

batch   delivery | leaked envelope: "Let me check. <|DSML|tool_calls><|DSML|invoke name=\"exec\"><|DSML|parameter name=\"command\" string=\"true\">rm -rf /tmp/x</|DSML|parameter></|DSML|invoke></|DSML|tool_calls> Done."
stream  chunk 2 | envelope split across chunks: "Let me check. <|DSML|tool_calls><|DSML|invoke name=\"exec\">"
stream  chunk 4 | envelope split across chunks: "Let me check. <|DSML|tool_calls>...</|DSML|tool_calls> Done."
batch   delivery | code example: "Use `<|DSML|tool_calls>example</|DSML|tool_calls>` literally."

After:

batch   delivery | leaked envelope: "Let me check.  Done."
stream  chunk 1 | envelope split across chunks: "Let me check. <|DS"
stream  chunk 2 | envelope split across chunks: "Let me check."
stream  chunk 3 | envelope split across chunks: "Let me check."
stream  chunk 4 | envelope split across chunks: "Let me check.  Done."
batch   delivery | code example: "Use `<|DSML|tool_calls>example</|DSML|tool_calls>` literally."
stream  chunk 2 | code example split across chunks: "Use `<|DSML|tool_calls>example</|DSML|tool_calls>` literally."

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 lint and full test suite (left to CI).

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.
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR strips leaked DSML tool envelopes from assistant replies while preserving code examples.

Example: A reply contains Before. &lt;|DSML|tool_call>{"command":"pwd"}&lt;/|DSML|tool_call> After.

  • Before: The user sees the envelope and command.
  • After: The user sees Before. After.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful scope and shared ownership, with three actionable defects and no qualifying shipped-entry-point proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Users can see leaked DSML tool envelopes and their arguments in assistant replies.
Reason: Removing internal tool markup fits the existing sanitizer contract, but this implementation leaves documented DSML forms uncovered.

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
Reviewed head: 128f37add524e51721f22fb8ba2d43083e735a68

Before merge

  • Add real behavior proof - Supplied built-module output demonstrates sanitizer and projection behavior in one process, but bypasses the shipped Gateway and channel entry points; the contributor should supply output from that path and redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Keep ordinary DSML mentions off cumulative Markdown parsing (P2) - Streaming DSML uses \tags`.\n\n` followed by a long answer permanently activates this filter. It has neither a custom projector nor a checkpoint, so createActivatedProjector calls stripDeepSeekDsmlToolCallBlocks with the entire accumulated reply on every append. The backticks make findCodeRegions invoke the Markdown parser each time, producing quadratic work on the Gateway thread even without a DSML envelope. Reuse bounded activation and the existing projection/checkpoint mechanisms; the same failure class was repaired in fix(text): gate delivery filters on real tag shape, not bare mentions #196624.
  • Recognize the established calls and separator-space forms (P2) - The new regex leaves Before &lt;||DSML|| calls>hidden&lt;/||DSML|| calls> After visible, as well as compact &lt;|DSML|calls> blocks and spaced tool_calls blocks. These are observed forms already represented by deepseek-dsml-grammar.ts and repaired in fix(deepseek): recover calls markup instead of leaking tool payloads #169728. Neither the later model-token filter nor generic XML stripping recognizes these DSML envelopes. Align the presentation grammar with the established wrapper vocabulary while retaining code protection.
  • Protect quoted JSON inside DSML invocation bodies (P2) - For &lt;|DSML|tool_calls>&lt;|DSML|invoke name="write">{"content":"&lt;/|DSML|tool_calls>TAIL"}&lt;/|DSML|invoke>&lt;/|DSML|tool_calls>, the outer payload starts with an invoke tag, so isInsideQuote is undefined. The regex does not track invoke boundaries and treats the closing-token literal inside the JSON string as the real outer close, exposing TAIL and the remaining argument text. JSON invocation bodies are supported by the existing DSML parser. Track their payload ownership before accepting an outer closing tag, using the existing quote scanner.
  • Explain or restore the original intent of Selective streaming activation - 1274f85: Keep ordinary tag-name mentions from permanently activating whole-reply sanitizer scans.

Findings

  • [P2] Keep ordinary DSML mentions off cumulative Markdown parsing — src/shared/text/assistant-visible-text.ts:201-204
  • [P2] Recognize the established calls and separator-space forms — src/shared/text/assistant-text-transforms.ts:10-11
  • [P2] Protect quoted JSON inside DSML invocation bodies — src/shared/text/assistant-text-transforms.ts:192-197

Provenance

  • Selective streaming activation changes intended behavior without addressing why it exists (1274f85: Keep ordinary tag-name mentions from permanently activating whole-reply sanitizer scans.)

Tests

  • Missing end-to-end proof: Provide redacted Gateway or channel output showing streamed and final DSML suppression alongside preserved code examples.
Agent review details

How this fits together

Shared 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
Loading

Technical review

Best 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:

  • [P2] Keep ordinary DSML mentions off cumulative Markdown parsing — src/shared/text/assistant-visible-text.ts:201-204
    Streaming DSML uses \tags`.\n\n` followed by a long answer permanently activates this filter. It has neither a custom projector nor a checkpoint, so createActivatedProjector calls stripDeepSeekDsmlToolCallBlocks with the entire accumulated reply on every append. The backticks make findCodeRegions invoke the Markdown parser each time, producing quadratic work on the Gateway thread even without a DSML envelope. Reuse bounded activation and the existing projection/checkpoint mechanisms; the same failure class was repaired in fix(text): gate delivery filters on real tag shape, not bare mentions #196624.
    Confidence: 0.99
  • [P2] Recognize the established calls and separator-space forms — src/shared/text/assistant-text-transforms.ts:10-11
    The new regex leaves Before &lt;||DSML|| calls>hidden&lt;/||DSML|| calls> After visible, as well as compact &lt;|DSML|calls> blocks and spaced tool_calls blocks. These are observed forms already represented by deepseek-dsml-grammar.ts and repaired in fix(deepseek): recover calls markup instead of leaking tool payloads #169728. Neither the later model-token filter nor generic XML stripping recognizes these DSML envelopes. Align the presentation grammar with the established wrapper vocabulary while retaining code protection.
    Confidence: 0.99
  • [P2] Protect quoted JSON inside DSML invocation bodies — src/shared/text/assistant-text-transforms.ts:192-197
    For &lt;|DSML|tool_calls>&lt;|DSML|invoke name="write">{"content":"&lt;/|DSML|tool_calls>TAIL"}&lt;/|DSML|invoke>&lt;/|DSML|tool_calls>, the outer payload starts with an invoke tag, so isInsideQuote is undefined. The regex does not track invoke boundaries and treats the closing-token literal inside the JSON string as the real outer close, exposing TAIL and the remaining argument text. JSON invocation bodies are supported by the existing DSML parser. Track their payload ownership before accepting an outer closing tag, using the existing quote scanner.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 05b455331de7.

Provenance checked

  • Shared batch and streaming sanitizer ownership keeps the original intent (712479e: Unify visible-text sanitization so tool markup is removed on the actual delivery path.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/shared/text/assistant-visible-text.test.ts src/shared/text/assistant-internal-scaffolding.test.ts src/shared/text/assistant-visible-text.streaming-work.test.ts --maxWorkers=1
  • pnpm test src/agents/embedded-agent-utils.marker-absence.test.ts --maxWorkers=1
  • Verify focused regressions fail on the reviewed head and pass after repair.
  • Run targeted core typecheck, lint, and format checks; resolve exact-head CI attribution before landing.

What I checked:

Likely related people:

  • SunnyShu: Raw commit 1274f85 adds src/shared/text/assistant-visible-text.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1274f85b7324; files: src/shared/text/assistant-visible-text.ts)

PR surface

Source +66, Tests +137. Total +203 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 66 0 +66
Tests 2 137 0 +137
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 203 0 +203

Preflight source

Source 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

Metric Value Why it matters
Production versus test growth Production +66/-0; tests +137/-0 The added grammar and profile wiring serve the stated fix without introducing a module or persistent state, but the streaming implementation needs repair.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a focused reply-sanitization repair with concrete correctness and streaming-work defects.
  • merge-risk: 🚨 availability: An ordinary DSML mention followed by a long Markdown reply causes cumulative parsing on the Gateway's streaming path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 12, 2026, 9:33 PM ET / November 13, 2026, 02:33 UTC.

obviyus added a commit that referenced this pull request Nov 27, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…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)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant