Skip to content

fix(ai): keep tool history native when a chat-completions request offers no tools - #206864

Merged
obviyus merged 5 commits into
openclaw:mainfrom
zsicheng0214:fix/strip-bracketed-tool-frames-205127
Nov 27, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
zsicheng0214:fix/strip-bracketed-tool-frames-205127

Conversation

@zsicheng0214

@zsicheng0214 zsicheng0214 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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:

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.

@clawsweeper

clawsweeper Bot commented Nov 27, 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 P2 Normal backlog priority with limited blast radius. impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR hides echoed bracket-style tool calls and results through the existing shared assistant-text filter.

Example: A reply contains Recovered summary. followed by [tool call id=call00_1 name=exec] {"cmd":"ls"} and its result frame.

  • Before: The summary, tool arguments, and result payload appear in chat.
  • After: Only Recovered summary. remains visible.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful, focused repair with one blocking parser defect and no qualifying after-fix product proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Users see internal tool-call arguments and result payloads in assistant replies.
Reason: The change repairs an evidenced presentation gap using its existing owner; the linked issue also includes DSML leakage outside this PR's stated scope.

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: 37ea0e90be7349415b5e8dc55f92477c51b040bb

Before merge

  • Add real behavior proof - After-fix evidence consists of reported unit, lint, and format checks; the inspected linked screenshot shows the original leak, so the contributor still needs shipped Gateway or channel evidence and should 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.
  • Classify replay headers independently of colons inside call IDs (P2) - For [tool call id=read:0 name=read] {"path":"notes.txt"}, the new regex accepts the replay header, but match[0].includes(":") selects the legacy branch. That branch only consumes payloads prefixed by Arguments, so it removes the header and leaves {"path":"notes.txt"} visible. The serializer preserves ordinary colon-bearing IDs, and existing transport coverage exercises read:0. Identify the matched header alternative, or inspect the delimiter immediately after Tool Call, and add a regression for this input.

Findings

  • [P2] Classify replay headers independently of colons inside call IDs — src/shared/text/downgraded-tool-call-text.ts:82

Tests

  • Missing end-to-end proof: Provide redacted after-fix Gateway or channel output showing mixed replay frames removed in streamed and final replies with literal examples preserved; base-red regression execution is also not shown.
Agent review details

How this fits together

The 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]
Loading

Technical review

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

  • [P2] Classify replay headers independently of colons inside call IDs — src/shared/text/downgraded-tool-call-text.ts:82
    For [tool call id=read:0 name=read] {"path":"notes.txt"}, the new regex accepts the replay header, but match[0].includes(":") selects the legacy branch. That branch only consumes payloads prefixed by Arguments, so it removes the header and leaves {"path":"notes.txt"} visible. The serializer preserves ordinary colon-bearing IDs, and existing transport coverage exercises read:0. Identify the matched header alternative, or inspect the delimiter immediately after Tool Call, and add a regression for this input.
    Confidence: 0.99

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 a3954edd50a5.

Provenance checked

  • Code-preserving downgraded-frame filtering keeps the original intent (8416d71: Carry presentation filtering through shared delivery while preserving literal code, attachment facts, and reply intent.)
  • Streaming checkpoints keeps the original intent (c6a601f: Bound repeated streaming work while retaining canonical output when incomplete markers or Markdown ownership change.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • pnpm vitest run src/shared/text/assistant-visible-text.test.ts src/shared/text/assistant-visible-text.streaming-work.test.ts src/agents/embedded-agent-utils.test.ts
  • pnpm exec oxlint src/shared/text/downgraded-tool-call-text.ts src/shared/text/assistant-visible-text.test.ts
  • pnpm exec oxfmt --check src/shared/text/downgraded-tool-call-text.ts src/shared/text/assistant-visible-text.test.ts

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c6a601f adds src/shared/text/downgraded-tool-call-text.ts:73 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c6a601f68e74; files: src/shared/text/downgraded-tool-call-text.ts)

PR surface

Source +17, Tests +26. Total +43 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 33 16 +17
Tests 1 26 0 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 59 16 +43

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.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • 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 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
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Proof lines for head 27cb1a07da98 (production code identical to the proven c5e36a1934f2; only a test row changed).

#205127 / PR #206864 — tool frames in replies after settled-turn finalization
Root cause: packages/ai/src/transports/openai-completions-params.ts:302 built an empty declaredToolNames for a request that offers no tools, so openai-completions-messages.ts:189 replayed every historical tool call/result as assistant-role "[tool call id=...]" / "[tool result id=...]" text; the tool-free settled-turn finalization request (disableTools) then showed the model its own turn in that format and the model copied it into the reply.
Regression: 8fc3509a66ad (#174797).

Unit red/green (vitest-source, ocx test)
  base f77ce263f6a1 (merge base): openai-completions-replay.test.ts "keeps history native when the request offers no tools" ({"tools":[]}) FAIL, ({}) FAIL; openai-completions-params.test.ts "shapes message content and keys for restrictive backends" FAIL (3 failed | 79 passed)
  candidate 27cb1a07da: same 3 cases pass (82 passed)

E2E (tier: source; `ocx src` Gateway, isolated HOME/OPENCLAW_HOME/config, --profile p205127base|p205127cand, openai-completions provider on loopback fixture.mjs that records request shapes; scripted model echoes frames from the last assistant text when a request offers no tools, else "Summary: done.")
  harness: proofs/205127/run.sh <root> <label> <gwport> <fixport>; fixture: proofs/205127/fixture.mjs
  base f77ce263f6a1: runs/base-20261128T003945
  cand c5e36a1934f2 (production code identical to head 27cb1a07da; only a test row changed): runs/cand-20261128T002408

Turn: P205127-FINALIZE -> two exec calls -> empty `stop` -> "settled post-tool turn lacked a final answer ... running isolated finalization" (both)
  base finalization request: tools field absent, messages: user, user, assistant text-frames:[tool call id=callp2051271 name=exec][tool call id=callp2051272 name=exec][tool result id=callp2051271 name=exec][tool result id=callp2051272 name=exec], user
  base reply (agent --json and chat.history): "[tool call id=callp2051271 name=exec] {"command":"echo one"}\n[tool call id=callp2051272 name=exec] {"command":"echo two"}\n[tool result id=callp2051271 name=exec] one\n[tool result id=callp2051272 name=exec] two"
  cand finalization request: tools field absent, messages: user, user, assistant tool_calls[exec,exec], tool tool_call_id=callp2051271, tool tool_call_id=callp2051272, user
  cand reply (agent --json and chat.history): "Summary: done."
  Note: the empty tools list is dropped for loopback/proxy-like endpoints (existing behavior, openai-completions-params.ts usesExplicitProxyLikeEndpoint), so "tools" is absent rather than [] on both sides.

Controls (same runs)
  1 denied tool (P205127-DENY1 exec, restart with tools.deny ["exec"], P205127-DENY2): request tools [15] without exec; exec history = assistant text-frames on base AND cand (#174797 kept)
  2 supportsTools:false model (P205127-NT2 --model mock/p205127-nt): tools absent; exec history = assistant text-frames on base AND cand (unchanged)
  3 Tool Search directory mode (SEARCH-PLEASE -> web_search via SearXNG fixture, then P205127-AFTER): web_search not in tools; history assistant tool_calls[web_search] + tool on base AND cand (#202436 kept)

Not run: real deepseek-v4-flash. No DeepSeek key in Bitwarden (openclaw-bws-secretref: OPENCLAW-DEEPSEEK-API-KEY NOT_FOUND).
strictMessageKeys: no bundled provider or catalog sets it; user opt-in only (models.providers.<p>.models[].compat.strictMessageKeys, docs/gateway/local-models.md).

@obviyus obviyus changed the title fix: hide echoed bracketed tool call and tool result frames from chat replies fix(ai): keep tool history native when a chat-completions request offers no tools Nov 27, 2026
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Rejected review findings:

  • [P2] Preserve complete history for strict-message backends (openai-completions-params.ts:302-308): rejected. On a compat.strictMessageKeys: true backend, history is already sent as native calls and then reduced to role/content on every normal turn that offers tools, so the tool name and arguments are dropped there today. This PR gives the no-tools request the same projection, which is what it had before fix(ai): replay unavailable historical tools as text #174797. Keeping text only for strict backends would add a special case that makes the tool-free request differ from every other turn on that backend. No bundled provider sets strictMessageKeys; it is a user opt-in for local servers. If strict backends need readable tool history, that change belongs to the strict-keys projection for all turns, not to this fix.
  • [P2] Pass the required options argument in the regression test: fixed in f865f4d.

- 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.
@obviyus
obviyus merged commit 5218d21 into openclaw:main Nov 27, 2026
99 checks passed
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

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 [tool call id=… name=…] text, so the model no longer copies those frames into your reply. Thanks @ningchen-2333 for the detailed report in #205127 and @zsicheng0214 for the PR; we replaced the display-filter change with a fix where the frames are produced, in commits on top of yours. DeepSeek's own DSML closers are tracked separately in #198042.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

[Bug]: 2026.11.7: interrupted-reply recovery emits raw tool-call frames as message text

2 participants