Skip to content

fix(agents): cap DeepSeek DSML recovery buffer at 256 KB - #117175

Merged
vincentkoc merged 6 commits into
openclaw:mainfrom
SebTardif:fix/dsml-recovery-buffer-cap-90015
Aug 2, 2026
Merged

vincentkoc merged 6 commits into
openclaw:mainfrom
SebTardif:fix/dsml-recovery-buffer-cap-90015

Conversation

@SebTardif

@SebTardif SebTardif commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #90015

Recreates closed #86637 (barnacle inactivity auto-close) on current main.

What Problem This Solves

DeepSeek-compatible providers can stream textual DSML tool-call markup. An unterminated outer DSML block previously grew the recovery buffer without a bound, allowing a buggy or hostile stream to consume memory for the lifetime of the response.

Why This Change Was Made

The DSML recovery owner now enforces a 256 KB UTF-8 limit, matching the existing native tool-call argument and post-tool text limits.

  • Closing-token search resumes from the unscanned suffix instead of rescanning the accumulated block on every streamed chunk.
  • A block over the limit fails immediately with Exceeded DeepSeek DSML recovery buffer limit.
  • Outer wrapper kinds must close exactly, and nested wrappers fail closed before any tool event is authorized.
  • Complete invoke bodies remain opaque to structural wrapper scanning, while nameless or malformed invokes cannot expose nested executable calls.
  • Overflow cannot authorize a later textual tool call.
  • DSML-looking text inside a valid parameter value remains payload data rather than parser structure.
  • Split surrogate pairs retain exact UTF-8 byte accounting without leaking accounting state across emitted text.

The explicit transport error is intentional: it gives the operator and retry layer a visible outcome instead of silently discarding the remainder of the response or guessing where nested recovery can resume.

No config, protocol, or public API surface changes.

User Impact

Malformed or malicious DeepSeek DSML streams can no longer grow recovery memory without bound. Valid DSML calls at or below the limit continue to recover normally. Valid textual DSML blocks above 256 KB now fail visibly; maintainers accept that compatibility tradeoff because it matches the existing native tool-call safety envelope.

Evidence

Exact repaired head: 440804456395c8bbcfb319e93c4cccc9e3d86e11

Sanitized exact-head AWS proof

$ pnpm test src/agents/openai-transport-stream.deepseek-and-shaping.test.ts src/agents/deepseek-text-filter.test.ts
Test Files  2 passed (2)
Tests       65 passed (65)

The standalone script used createOpenAICompletionsTransportStreamFn() directly against a loopback OpenAI-compatible SSE endpoint, without Vitest or test-support imports:

{"exactHead":"440804456395c8bbcfb319e93c4cccc9e3d86e11","oversized":{"terminal":"error","reason":"error","errorMessage":"Exceeded DeepSeek DSML recovery buffer limit","toolEvents":0},"nested":{"terminal":"error","reason":"error","errorMessage":"Nested DeepSeek DSML recovery wrappers are not supported","toolEvents":0},"namelessInvoke":{"terminal":"done","reason":"stop","toolEvents":0},"valid":{"terminal":"done","reason":"toolUse","toolName":"message","arguments":{"text":"literal <|DSML|tool_calls> marker"}}}

Coverage includes:

  • a 256,001-byte block whose closing token arrives in the cap-crossing chunk
  • multibyte overflow and exact-cap split-surrogate accounting
  • a later textual call after overflow remaining unauthorized
  • nested wrappers, mismatched closes, malformed invoke prefixes, and nameless-invoke nesting remaining unauthorized
  • valid raw parameter and JSON payloads containing DSML-looking markers
  • character-by-character canonical full-width DSML fragmentation
  • production HTTP/SSE transport error propagation
  • existing ordinary, split, repeated, malformed, native-call, text-filter, and terminal-safety behavior

Review and static proof

  • git diff --check: pass
  • oxfmt --check on both changed files: pass
  • fresh exact-head autoreview: clean, patch correct, confidence 0.99
  • production delta from the original uncapped parent: +195/-17 (+178 net); tests: +363/-28

The positive production delta is the bounded structural scanner and byte-accounting owner needed to prevent provider text from crossing into executable tool-call events through malformed wrapper boundaries.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 1, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 10:56 AM ET / 14:56 UTC.

ClawSweeper review

What this changes

Caps DeepSeek textual DSML recovery at 256 KB, rejects unsafe wrapper boundaries, and adds stream-level regressions for overflow and valid recovery.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR remains necessary: current main still buffers an unclosed DeepSeek textual-DSML block without a DSML-specific byte cap. The proposed owner-boundary fix and exact-head runtime proof are strong, with no concrete patch defect found; merge should wait for explicit acceptance of the intentional compatibility change for valid textual DSML blocks above 256 KB.

Priority: P1
Reviewed head: 440804456395c8bbcfb319e93c4cccc9e3d86e11
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong exact-head runtime proof and focused regression coverage support the patch; an intentional compatibility tradeoff still requires owner acceptance.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body includes exact-head sanitized loopback OpenAI-compatible SSE output showing oversized and nested cases terminate without tool events while a valid payload still recovers.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes exact-head sanitized loopback OpenAI-compatible SSE output showing oversized and nested cases terminate without tool events while a valid payload still recovers.
Evidence reviewed 6 items Current main still lacks the requested safety bound: The current DeepSeek recoverer keeps a string buffer but no DSML byte counter or maximum; sibling post-tool and native tool-call paths define 256,000-byte caps.
The branch enforces the bound at the recovery owner: The proposed recoverer tracks UTF-8 bytes across chunks, rejects oversized incomplete and complete blocks, and structurally scans markup before parsing recovered tool calls.
Existing transport error handling receives the recovery failure: Recovered pieces enter the output-event helpers, and the enclosing transport catches errors and finalizes the response with an error stop reason.
Findings None None.
Security None None.

How this fits together

The OpenAI-compatible completions transport turns provider SSE content into agent text and tool-call events. For DeepSeek-compatible models, textual DSML markup passes through a recovery stage before it can emit a recovered tool call.

flowchart LR
  A[Provider SSE content] --> B[Completions transport]
  B --> C[DeepSeek DSML recovery]
  C --> D{Bounded valid markup?}
  D -->|yes| E[Recovered tool-call events]
  D -->|no| F[Text or transport error]
  E --> G[Agent output]
  F --> G
Loading

Decision needed

Question Recommendation
Should OpenClaw intentionally make otherwise valid textual DeepSeek DSML blocks above 256 KB terminate with a transport error in exchange for the shared bounded-memory safety envelope? Accept the 256 KB terminal-error contract: Merge the bounded fail-closed path, aligning textual DSML recovery with the existing native tool-call and post-tool stream limits.

Why: The implementation is coherent with sibling stream caps, but whether existing oversized textual DSML responses may fail visibly is a product and upgrade compatibility choice.

Before merge

  • Resolve merge risk (P2) - Merging intentionally changes valid DeepSeek-compatible textual DSML blocks above 256 KB from recoverable tool-call content into a visible terminal transport error; existing oversized workflows may therefore stop at runtime.
Agent review details

Security

None.

PR surface

Source +192, Tests +396. Total +588 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 211 19 +192
Tests 1 396 0 +396
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 607 19 +588

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #90015
Summary: This PR is the candidate fix for the open unbounded DSML recovery-buffer report.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept the common safety envelope (recommended)
    Merge after Vincent Koc confirms that visible failure for valid textual DSML over 256 KB is the intended upgrade behavior.
  2. Revise the overflow policy
    Pause the PR for a different bounded behavior if preserving oversized textual DSML responses takes precedence over matching sibling stream limits.

Technical review

Best possible solution:

Keep a single bounded recovery path before tool-event authorization, and merge it only after the transport owner explicitly accepts the 256 KB terminal-error compatibility contract.

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

Yes: current main constructs a DeepSeek DSML recoverer that accumulates an unterminated DSML block without a byte cap; the branch adds direct overflow cases at that owner boundary.

Is this the best way to solve the issue?

Yes, pending compatibility acceptance: the cap and wrapper scan are placed at the DSML recovery owner before it can emit a tool call, rather than masking the condition downstream.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The PR repairs unbounded memory growth in an active agent provider-stream transport path.
  • merge-risk: 🚨 compatibility: Existing textual DSML payloads larger than 256 KB now end the response instead of being recovered.
  • merge-risk: 🚨 security-boundary: Provider-controlled DSML text is transformed into executable tool-call events, and the PR changes the authorization boundary.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes exact-head sanitized loopback OpenAI-compatible SSE output showing oversized and nested cases terminate without tool events while a valid payload still recovers.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes exact-head sanitized loopback OpenAI-compatible SSE output showing oversized and nested cases terminate without tool events while a valid payload still recovers.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Local blame attributes the current completions transport to Vincent Koc, who also authored the branch's boundary-validation and final test commits. (role: current transport owner and follow-up contributor; confidence: high; commits: ea3b5df17237, 85cf038446f0, 000f71553442; files: packages/ai/src/transports/openai-completions-transport.ts, src/agents/openai-transport-stream.deepseek-and-shaping.test.ts)
  • SebTardif: The first commit in the PR series introduced the 256 KB recovery cap and ties the branch to the open unbounded-buffer report. (role: initial defect-fix contributor; confidence: high; commits: ec465473677d; files: packages/ai/src/transports/openai-completions-transport.ts, src/agents/openai-transport-stream.deepseek-and-shaping.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Have vincentkoc explicitly accept the terminal-error behavior for valid textual DSML blocks above 256 KB.

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-01T02:44:37.547Z sha f4777ec1b73857b2a937b290b03331514ee6bea8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T03:10:41.412Z sha f4777ec1b73857b2a937b290b03331514ee6bea8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T05:59:38.296Z sha 85cf038 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T08:55:11.439Z sha 000f715 :: needs real behavior proof before merge. :: [P1] Track nested DSML wrappers before accepting a close token
  • reviewed 2026-08-01T09:02:59.543Z sha 000f715 :: found issues before merge. :: [P1] Reject nested DSML wrappers before recovering calls
  • reviewed 2026-08-01T09:25:08.395Z sha 359a6a4 :: needs real behavior proof before merge. :: [P1] Reject nested wrapper closes before recovering a tool call
  • reviewed 2026-08-01T09:48:44.059Z sha 4408044 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T10:04:35.606Z sha 4408044 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 1, 2026
@vincentkoc vincentkoc self-assigned this Aug 1, 2026
Unterminated DSML tool-call recovery buffered provider text without a
byte limit, so a malicious or buggy stream could grow gateway memory
without bound while waiting for a close token.

Add MAX_DSML_RECOVERY_BUFFER_BYTES (256_000), matching the existing
tool-call argument and post-tool text caps, and enforce it with
UTF-8 Buffer.byteLength accounting so multibyte payloads cannot
bypass a string-length check.

Fixes openclaw#90015

Signed-off-by: Sebastien Tardif <[email protected]>
@vincentkoc
vincentkoc force-pushed the fix/dsml-recovery-buffer-cap-90015 branch from f4777ec to ac5fe2b Compare August 1, 2026 05:19
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@openclaw-barnacle openclaw-barnacle Bot added triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the fix/dsml-recovery-buffer-cap-90015 branch from ac5fe2b to 85cf038 Compare August 1, 2026 05:23
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Aug 1, 2026
@clawsweeper clawsweeper Bot added 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 proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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: 🧂 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. labels Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer decision: accepted. The 256 KB cap intentionally trades recovery of exceptionally large textual DSML blocks for bounded gateway memory and deterministic failure. It matches the existing tool-call/post-tool buffer budget, rejects malformed or nested recovery structures, and preserves ordinary DeepSeek tool-call recovery. The remaining pathological 256k one-character streaming case is bounded and non-blocking; no broader parser rewrite is warranted for this fix.

@vincentkoc
vincentkoc merged commit b300a0c into openclaw:main Aug 2, 2026
208 of 218 checks passed
vincentkoc added a commit to yetval/openclaw that referenced this pull request Aug 2, 2026
* origin/main: (99 commits)
  test: consolidate agent tool suites (openclaw#117886)
  fix: remove duplicate plugin CLI registry mock (openclaw#117894)
  fix(gateway): resume shared terminal after slow viewer leaves (openclaw#117847)
  refactor(gateway): remove deferred channel load flag; 503 plugin routes until runtime ready (openclaw#117852)
  test(agents): consolidate OpenClaw tool suites (openclaw#117870)
  fix(ci): repair release validation regressions (openclaw#117723)
  fix(media): reject empty generated assets (openclaw#117875)
  fix: release channel delivery resources reliably (openclaw#117855)
  refactor(cli): unify config-guard policy across dispatch paths (openclaw#117880)
  test: consolidate WhatsApp monitor suites (openclaw#117854)
  fix(heartbeat): retain configured account for accountless commitments (openclaw#117521)
  fix(agents): cap DeepSeek DSML recovery buffer at 256 KB (openclaw#117175)
  [AI] fix(line): downgrade row-overflow tables to ordered bullet text (openclaw#117481)
  fix(agents): fallback after replay-safe silent errors (openclaw#117356)
  fix(telegram): serialize approval ingress sessions (openclaw#117861)
  fix(agents): report truthful embedded startup stages (openclaw#117879)
  test(sqlite): align flip-proof request budgets (openclaw#117878)
  fix(ui): advance gateway-owned channel setup progress (openclaw#117877)
  fix(media): preserve canonical attachment facts across every agent owner (openclaw#117841)
  test(protocol): consolidate validation fixtures (openclaw#117873)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DSML recovery buffer grows without bound on unclosed DSML blocks

2 participants