Skip to content

fix(deepseek): doubled-bar DSML tool calls are delivered as text and never executed - #128882

Merged
steipete merged 3 commits into
openclaw:mainfrom
sashankh:sashankh/fix-deepseek-doubled-bar-dsml
Aug 29, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
sashankh:sashankh/fix-deepseek-doubled-bar-dsml

Conversation

@sashankh

@sashankh sashankh commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #128858

What Problem This Solves

Fixes an issue where DeepSeek users see doubled-fullwidth DSML tool markup in a reply while the requested tool never runs. This also affects Code Mode when the recovered call is exec.

Why This Change Was Made

Recovery and visible-text filtering now share one internal delimiter grammar: the existing ASCII/fullwidth single bars and the observed doubled-fullwidth form. Each invocation, parameter, and suppressed block must close with its opening marker. The scanner carries the exact pending invocation close instead of independent mode/sentinel state and redundant close-token lists.

This maintainer revision preserves @sashankh's fix and credit while consolidating the implementation and extending existing fixtures. It does not add unobserved doubled-ASCII syntax, configuration, public exports, storage, retries, or a provider fallback. The 256 KB buffer cap, nested-wrapper rejection, and stop/length/refusal authorization boundary remain intact.

User Impact

Recognized doubled-bar tool calls execute normally and their markup does not leak into replies. Malformed mixed markers and foreign closing tags cannot authorize a tool invocation. Single-bar output keeps working.

Evidence

On baseline bcac331e0746, the new/extended tests produce 11 intended failures: eight recovery/transport failures and three text-filter failures. On this revision, all 821 tests across 52 transport/filter files pass. Coverage includes character-by-character chunks, real HTTP/SSE, successful stop versus length/content-filter terminals, existing buffer/nesting/surrogate limits, and malformed delimiter rejection. Fresh independent Codex autoreview found no actionable findings at its P0 threshold.

Production LOC: +60/-71 (net -11). Tests: +99/-55 (net +44). This replaces duplicated delimiter policy and scanner state rather than adding a second parsing path.

The official DeepSeek V4 encoder uses single fullwidth bars; the doubled form is the reporter's observed provider output, not a claim about the documented encoder. Final-effect proof used real HTTP/SSE through an isolated built Gateway, the managed DeepSeek transport, Code Mode, and the real write handler. Before the patch, doubled bars leaked and wrote nothing; an asymmetric inner invocation wrongly wrote the nonce file. After the patch, single/doubled forms each execute exactly once with the exact nonce file, while mismatched/asymmetric forms execute zero tools and create no file. No DSML appears in the delivered reply. The provider socket is synthetic in this deterministic reproduction, not presented as an actual DeepSeek emission.

Authenticated deepseek/deepseek-v4-flash through the same Gateway also completed read/calculate/write/readback, background process polling, three yields, caught and uncaught errors, sixteen-call fan-out, and timer/catalog composition. The completed seven-model stress results are recorded below. We did not observe the intermittent doubled-bar emission from the real provider in this sample.

Local full compilation completed, but its postbuild checker hit stale workspace-package exports in the borrowed dependency tree. An isolated runtime linked to this checkout's freshly built packages passed the same canonical native control-plane check (49 modules) and served the live proofs. The shared dependency tree was not modified. Hosted changed checks passed; all final-head CI checks passed before the native prepare/merge flow.

Provenance: the single-bar filter originated in @samzong's #78331 (merged by @steipete, May 9); recovery originated in @steipete's #88946 (also merged by @steipete, June 2). The August #122122 split carried the assumption forward rather than introducing it. GitHub timelines show no recorded automerge enablement/trigger for the original merges.

Review follow-through: the prior review's boundary-proof and exact-head-CI requests remain landing gates. Its production-growth concern is resolved by the net-negative consolidation. The automated persistent-data warning is inapplicable: only transient parsing and tests change; no SQLite/schema/state format changes. Native Codex's separate V8/freeform protocol is untouched; OpenClaw's managed completions transport owns this fix.

Named follow-up: historical/imported transcript stripping in src/hooks/bundled/session-memory/transcript.ts independently recognizes single-bar DSML. This transport repair prevents new doubled-bar leakage but does not rewrite or repair historical transcript projections. General malformed proxy output (#114888) remains separate.

CI follow-up at fa78b88a7422: await the stream factory's declared sync/async union in the HTTP fixture (the runtime result was already synchronous and passing), and correct one inherited Twitch test assertion to expect the resolved default account. The two Twitch failures came from #132226 normalizing account identity after #131689 introduced the fixture. Request omission remains tested; only the downstream expected resolved account changes. All 128 gateway-send tests pass. Fresh autoreview of both fixture corrections is clean. No production behavior changed after the live Gateway build.

Stress result: 77 primary live cases across OpenAI GPT-5.6 Luna/Terra/Sol, Claude Sonnet 4.6/Haiku 4.5, Gemini 3.5 Flash, and DeepSeek V4 Flash; plus 14 concurrent sessions. All returned HTTP 200. Strict transcript/file verification found three model adherence failures (Haiku shell sessionId passed to outer wait; Gemini shadowed text(); DeepSeek omitted return), preserved as failures rather than counted as runtime passes. Explicit corrected code passes for Gemini and DeepSeek. Haiku background recovery remains an open product case tracked by #128859/#128886. File outcomes, yield chains, bounded errors, pending-call rejection without writes, and post-timeout recovery are inspected independently of final response prose. Where nested readback/process receipts are absent, proof is labeled partial rather than inferred.

Final CI stability follow-up: the unrelated portal refusal fixture released its target port before allocating the Gateway. A controlled real-socket reproduction forcing reuse produced a successful connection and one readiness frame (the same unexpected resolved outcome as CI); allocating the Gateway first produces ECONNREFUSED and zero readiness frames. The test now allocates the Gateway first. This is a test-only setup reorder, no production change; all23 portal/stream sibling tests and fresh autoreview pass. The CI log lacks port identities, so attributing that particular run to reuse remains an inference; the underlying fixture race is directly reproduced and removed. Test LOC includes an additional +11/-11 move (discounted as a pure move, net0).

Landed as 8af1b4aceeab. Final head a382bf8 passed CI; the hosted changed-file check passed exit0. The merged production files were compared byte-for-byte with the live-tested build and are identical. #128858 is closed as completed.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 4:09 AM ET / 08:09 UTC.

ClawSweeper review

What this changes

The PR recognizes uniform doubled DeepSeek DSML delimiters, binds closing tags to their opening delimiter, and adds SSE-to-agent-handler regression coverage.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking source finding on the reviewed head. The paired delimiter grammar repairs the reported recovery gap across scanning, parsing, filtering, and agent dispatch; retain this PR for exact-head CI and normal merge review.

Priority: P1
Reviewed head: 4288096672689faaefb8b87e0bf53ba03e75be37

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused boundary repair and handler-level proof are good; exact-head CI remains the normal merge gate.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR supplies current-head terminal proof through real loopback SSE, the production completions transport, the real agent loop, and an observed registered-handler result, including malformed-delimiter rejection before handler execution.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR supplies current-head terminal proof through real loopback SSE, the production completions transport, the real agent loop, and an observed registered-handler result, including malformed-delimiter rejection before handler execution.
Evidence reviewed 7 items Provider routing: The bundled DeepSeek model catalog uses the OpenAI completions transport, placing this behavior on the reported provider path.
Canonical delimiter and close pairing: The recovery scanner, parser, and invoke-close derivation share one uniform delimiter list; parser and scanner bind an invoke close to the captured opener delimiter.
Visible-text sibling: The text filter derives its pending close token from the matching opening token, preventing a foreign delimiter or kind from ending a filtered block early.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/agents/deepseek-dsml-tool-authority.test.ts

Result: FAIL (partial) — step 2 expect_output recovered DeepSeek DSML tool authority: expected terminal output was not visible within 30 seconds: "recovered DeepSeek DSML tool authority"

pnpm test src/agents/deepseek-dsml-tool-authority.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128882-k5t0AV/target$ pnpm test src/agents/deepseek-dsml-tool-authority.test.ts
$ node --import tsx scripts/test-projects.mts src/agents/deepseek-dsml-tool-authority.test.ts
pnpm test src/agents/deepseek-dsml-tool-authority.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128882-k5t0AV/target

 ✓  agents-core  src/agents/deepseek-dsml-tool-authority.test.ts (3 tests) 524ms
     ✓ runs the real tool handler for a well-formed doubled-bar call  324ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  08:10:05
   Duration  3.81s (transform 2.49s, setup 741ms, import 2.27s, tests 524ms, environment 0ms)

[test] passed 1 Vitest shard in 8.24s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128882-k5t0AV/target$ pnpm test src/agents/deepseek-dsml-tool-authority.test.ts
$ node --import tsx scripts/test-projects.mts src/agents/deepseek-dsml-tool-authority.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128882-k5t0AV/target

 ✓  agents-core  src/agents/deepseek-dsml-tool-authority.test.ts (3 tests) 481ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  08:10:14
   Duration  2.19s (transform 877ms, setup 347ms, import 1.19s, tests 481ms, environment 0ms)

[test] passed 1 Vitest shard in 6.58s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128882-k5t0AV/target$



















Assertions:

  • FAIL expect_output: recovered DeepSeek DSML tool authority

How this fits together

DeepSeek’s OpenAI-compatible stream turns SSE text into assistant text or recovered tool calls. Recovered calls enter the agent loop and can invoke registered tools, while residual DSML text is filtered before channel delivery.

flowchart LR
A[DeepSeek SSE response] --> B[DSML scanner]
B --> C[DSML parser]
C --> D[Recovered tool call]
D --> E[Agent loop]
E --> F[Registered tool handler]
B --> G[Text filter]
G --> H[Visible assistant text]
Loading

Before merge

  • Resolve merge risk (P1) - The change expands provider text recognized as executable tool calls; delimiter-pairing coverage reduces that boundary risk, but exact-head required checks should complete before merge.
  • Resolve merge risk (P1) - Production code is net +33 lines; the added shared delimiter grammar and close-pairing state are justified by the recovery and authorization boundary, but the local snapshot could not independently compare current main.
  • Complete next step (P2) - No discrete mechanical repair remains; wait for normal exact-head CI and maintainer merge review.
Agent review details

Security

None.

PR surface

Source +33, Tests +419. Total +452 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 76 43 +33
Tests 3 419 0 +419
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 495 43 +452

Review metrics

Metric Value Why it matters
Production versus test LOC production +76/-43 (net +33); tests +419/-0 The positive production delta centralizes delimiter parsing and close pairing; most added lines are focused regression and transport-to-handler proof.

Stored data model

Persistent data-model change detected: persistent cache schema: packages/ai/src/transports/openai-completions-dsml.recovery.test.ts, serialized state: packages/ai/src/transports/openai-completions-dsml.recovery.test.ts, serialized state: packages/ai/src/transports/openai-completions-dsml.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128858
Summary: This PR is the candidate fix for the linked well-formed doubled-bar DSML recovery failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Require exact-head boundary checks (recommended)
    Merge after the PR head’s required checks validate both delivery filtering and the malformed-delimiter rejection path.

Technical review

Best possible solution:

Land the single shared delimiter grammar only after exact-head checks confirm the transport, filter, and agent-loop regressions; do not add provider-specific fallback paths.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: doubled-bar DSML reaches the recovery scanner on the DeepSeek completions path, and the current-head SSE-to-agent-loop test defines the focused reproduction without requiring external credentials.

Is this the best way to solve the issue?

Yes: one shared uniform delimiter grammar with opener-bound closes fixes the scanner, parser, and text-filter invariant; separate hardcoded doubled-bar cases would recreate drift.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b5e8460912af.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies current-head terminal proof through real loopback SSE, the production completions transport, the real agent loop, and an observed registered-handler result, including malformed-delimiter rejection before handler execution.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR supplies current-head terminal proof through real loopback SSE, the production completions transport, the real agent loop, and an observed registered-handler result, including malformed-delimiter rejection before handler execution.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported default bundled-provider path can turn intended tool actions into visible text and silently skip execution.
  • merge-risk: 🚨 message-delivery: The PR changes which streamed DSML blocks are filtered versus delivered as assistant text.
  • merge-risk: 🚨 security-boundary: The PR changes provider text that may become executable tool calls, so mismatched delimiters must remain rejected before handler invocation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR supplies current-head terminal proof through real loopback SSE, the production completions transport, the real agent loop, and an observed registered-handler result, including malformed-delimiter rejection before handler execution.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies current-head terminal proof through real loopback SSE, the production completions transport, the real agent loop, and an observed registered-handler result, including malformed-delimiter rejection before handler execution.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the split that created the current DSML recovery module in the available feature history. (role: transport-module introducer; confidence: medium; commits: fe4cff7a6b24; files: packages/ai/src/transports/openai-completions-dsml.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-08-24T22:20:08.248Z sha 827f0b0da3b34d1a7f60d20de168f48e93cbdc2a :: needs real behavior proof before merge. :: [P2] Align mixed-width delimiter matching with the scanner
  • reviewed 2026-08-24T23:02:57.792Z sha 827f0b0da3b34d1a7f60d20de168f48e93cbdc2a :: needs real behavior proof before merge. :: [P2] Use the scanner’s delimiter grammar in the parser
  • reviewed 2026-08-25T00:37:20.459Z sha d3bec629d9a2317ccb352961ad0b57015f1ea181 :: needs real behavior proof before merge. :: [P1] Reject mismatched invocation closing delimiters
  • reviewed 2026-08-25T00:51:13.671Z sha d3bec629d9a2317ccb352961ad0b57015f1ea181 :: needs real behavior proof before merge. :: [P1] Match the invocation close delimiter to its opening delimiter
  • reviewed 2026-08-25T03:41:06.019Z sha b070ebc658fee4f1490fef3e62d3f1874d24a99b :: needs real behavior proof before merge. :: [P2] Bind the text-filter close delimiter to its opener
  • reviewed 2026-08-25T04:17:29.648Z sha 79bcdcf123b38650bca13f16332ae725a72c994d :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-25T04:36:27.513Z sha 79bcdcf123b38650bca13f16332ae725a72c994d :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-25T07:15:45.269Z sha 81fde9abcf4bc2563999c96cddf451bc64c84b57 :: needs real behavior proof before merge. :: none

@sashankh
sashankh force-pushed the sashankh/fix-deepseek-doubled-bar-dsml branch from 827f0b0 to d3bec62 Compare August 25, 2026 00:31
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Aug 25, 2026
@sashankh
sashankh force-pushed the sashankh/fix-deepseek-doubled-bar-dsml branch from d3bec62 to b070ebc Compare August 25, 2026 03:34
@sashankh
sashankh force-pushed the sashankh/fix-deepseek-doubled-bar-dsml branch from b070ebc to 08c77d5 Compare August 25, 2026 04:00
@sashankh
sashankh requested a review from a team as a code owner August 25, 2026 07:50
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L and removed size: M labels Aug 25, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@steipete steipete self-assigned this Aug 29, 2026
Share the observed delimiter grammar between recovery and filtering, and bind each closing tag to its opener.

Co-authored-by: sashankh <[email protected]>
@steipete
steipete force-pushed the sashankh/fix-deepseek-doubled-bar-dsml branch from 4288096 to 53dfb34 Compare August 29, 2026 06:01
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

Maintainer revision at 53dfb34 consolidates the shared grammar and exact closing-tag ownership, preserves contributor credit, removes unobserved doubled-ASCII widening, and extends existing tests. Production is net -11 lines. Baseline/fixed proof: 11 intended failures become 821 passing transport/filter tests. Real Gateway and multi-provider stress proof is in progress; exact-head CI remains required before landing. The updated body distinguishes current evidence from the superseded revision.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 29, 2026
@steipete
steipete merged commit 8af1b4a into openclaw:main Aug 29, 2026
201 of 202 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
…never executed (openclaw#128882)

* fix(deepseek): recover paired doubled DSML markers

Share the observed delimiter grammar between recovery and filtering, and bind each closing tag to its opener.

Co-authored-by: sashankh <[email protected]>

* test: honor stream and resolved account contracts

* test: prevent portal fixture from reusing its refused port

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: sashankh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DeepSeek V4 Flash doubled-bar DSML (<||DSML||…) bypasses recovery; tool calls delivered as text and never executed

2 participants