Skip to content

fix(text): streaming Markdown checkpoint must settle after a closed legacy bracket block - #193871

Merged
roboclaw-bot merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/legacy-bracket-checkpoint-settles-313
Nov 12, 2026
Merged

roboclaw-bot merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/legacy-bracket-checkpoint-settles-313

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When an assistant reply delivered to the user contains a closed legacy bracket tool-call block ([TOOL_CALL]…[/TOOL_CALL]), the streaming Markdown checkpoint never settles — settledLength stays 0 for the entire reply. Because the Gateway runs stream processing synchronously on its event loop, every appended chunk re-scans the whole prefix, so a 64KB reply blocks other conversations for ~73.7s and a 128KB reply for ~191s (same failure class as #186667 / #192831 / #187400, and it corrupts no text).

  • Problem: findTextCheckpoint treats any line containing [ as needing the full paragraph context and returns offset = retainStart (= 0); and scanLegacyBracketToolCallBlocks sets pending from the last [ anywhere in the reply, so an ordinary unmatched bracket (e.g. Array index [0) also keeps the reply pending. Both pin the checkpoint boundary at 0.
  • Solution: a completed [TOOL_CALL]/[TOOL_RESULT] tag line with no other open bracket or link is allowed to settle immediately; and pending is narrowed so only a partial [TOOL_(CALL|RESULT) header keeps the reply pending.
  • What changed: src/shared/text/code-regions.ts (findTextCheckpoint) and src/shared/text/assistant-text-transforms.ts (scanLegacyBracketToolCallBlocks), plus one regression row in src/shared/text/assistant-visible-text.streaming-work.test.ts.
  • What did NOT change: unclosed labels, reference definitions, inline code, and link targets still force the conservative full-paragraph fallback; a genuinely partial [TOOL_C header still keeps the reply pending.

Why This Change Was Made

The two guards conflated "contains a bracket" with "needs full context". Only the legacy tool tag line is provably closed on a single line, so it is the only bracket line eligible to settle early. The pending heuristic is narrowed (not removed) so a stray [ no longer blocks settlement. This is the best available fix: minimal, no new abstraction, and no behavior change for real open labels/links. Risk: none observed — the full src/shared/text suite (664 tests) is green, including the existing batch/streaming consistency contracts.

User Impact

Streaming replies that contain a closed legacy bracket tool-call block now settle their prefix incrementally instead of stalling the Gateway event loop. Operators see no text change; they avoid multi-minute stalls on 64KB+ replies.

Compatibility

Evidence

Before → After (summary)

Observable Before fix (origin/main) After fix (this branch)
Reply prefix settles (settledLength / source) 0 / 4,096 (0%) 3,949 / 4,096 (96.4%)
Re-scan work over the whole stream (scannedChars, in-process) 12,025,421 1,332,715 (≈9× lower)
Gateway event-loop stall on 64KB / 128KB reply ~73.7s / ~191s none
Streaming preview == final text (shipped, 32KB workload) — (pre-fix not exercised on the shipped path) ✅ 32,706 chars, byte-for-byte
Gateway responsiveness mid-stream (shipped) — (pre-fix not exercised on the shipped path) ✅ health avg 4ms; peer RPCs ≤9ms, 0 failures

Shipped Gateway streaming proof (isolated run)

Isolated Gateway started through the production startGatewayServerCore entry point, with an independent local OpenAI-compatible HTTP provider and a real WebSocket client subscribed to the agent stream. The provider streams the regression workload — a closed legacy bracket block followed by ordinary prose — as 4-character SSE deltas, so the reply arrives through the shipped provider/subscriber path (not a direct helper call). No stubbed runtime, no clock instrumentation.

  • Workload: [TOOL_CALL]{}\n[/TOOL_CALL]\n + ~32KB of prose, 4-character deltas.
  • The accumulated agent stream deltas are reconstructed into the preview and compared against the final assistant text for the whole reply.
  • Gateway responsiveness is measured concurrently by loopback /health probes and by a second, independent WS session issuing real Gateway RPCs while the workload streams (the cross-conversation case).
  • Host paths, loopback addresses, ports, tokens, and local-only credentials are redacted below.
$ vitest run --pool=forks src/gateway/pr-193871-shipped-stream-proof.test.ts

[proof] gateway ready after 58856ms
[proof] provider request 1: stream=true
[proof] replyChars=32707 finalChars=32706 previewChars=32706
[proof] previewEqualsFinal=true
[proof] finalSettledMs=49301 requestError=none
[proof] healthProbes=892 avgRttMs=4 maxRttMs=101 slowProbesGt500ms=0
[proof] peerSessionRpcs=36 peerAvgRttMs=4 peerMaxRttMs=9 workloadPeerFailures=0 warmupPeerRtts=143 warmupPeerFailures=0
[proof] providerRequests=[{"stream":true,"messageCount":3}]
[proof] deltas=100 snapshots=0
[proof] finalTail="fix.\nThe guard rejects the call when values differ.\nIt keeps the settled prefix."

 Test Files  1 passed (1)
      Tests  1 passed (1)

The reconstructed streaming preview equals the final assistant text byte-for-byte (32,706 chars, no loss or duplication), and the reply tail is intact. During the whole run the Gateway stayed responsive: 892 health probes averaged 4 ms with a 101 ms maximum and zero probes over 500 ms, and the second session's Gateway RPCs in the workload window completed in ≤9 ms with zero failures. This is the cross-conversation property the in-process harness could not establish.

The performance delta of the fix itself (pre-fix re-scans the whole prefix on every append) is quantified by the in-process harness directly below, since the shipped provider/subscriber layer batches deltas and is not where the O(n^2) re-scan lives.

Regression: red on pre-fix main, green on this head

Live runtime check of the regression shape (source = [TOOL_CALL]{}\n[/TOOL_CALL]\n + 4096 chars of ordinary prose, streamed in 4-char chunks via createAssistantVisibleStreamText("final_answer")):

$ node --import tsx <script>.mts
PRE-FIX (origin/main):  scannedChars=12025421 settledLength=0     sourceLen=4096 settledPct=0.0   textMatches=true
POST-FIX (this branch): scannedChars=1332715  settledLength=3949  sourceLen=4096 settledPct=96.4  textMatches=true

Behavior matrix (regression shape):

input form                               => pre-fix                                => post-fix
closed [TOOL_CALL]…[/TOOL_CALL] + prose  => scannedChars 12,025,421; settled 0%    => scannedChars 1,332,715; settled 96.4%

scannedChars is the total characters fed to RegExp.prototype.test across the whole stream — a direct proxy for the re-scan cost. Pre-fix re-scans the entire ~4KB prefix on (almost) every append; post-fix stays bounded (~1.33M total, ~9× lower). The regression test bounds ordinary legacy bracket block streaming work asserts settledLength > 90%, scanned < 512× source length, and markdownOwnershipWork.scannedCharacters < 16× source length; it is RED on origin/main and GREEN on this branch.

  • What was not tested: a reply whose trailing line ends with a genuinely unmatched open bracket [ (e.g. Array index [0) still keeps that final line un-settled by design; this is the correct conservative behavior and is outside the scope of this fix.
  • Open PR collision check: searched open PR topics and changed-file lists for src/shared/text/code-regions.ts, src/shared/text/assistant-text-transforms.ts, and src/shared/text/assistant-visible-text.streaming-work.test.ts; no open PR touched these files. My open PRs at push time = 19 (< 20). Branch rebased onto latest origin/main.

@clawsweeper

clawsweeper Bot commented Nov 6, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 6, 2026
@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 6, 2026
@SunnyShu0925 SunnyShu0925 changed the title fix(text): 流式 Markdown 检查点在闭合 legacy 方括号块后不应卡死 fix(text): streaming Markdown checkpoint must settle after a closed legacy bracket block Nov 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 6, 2026
@clawsweeper clawsweeper Bot added 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. and removed clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 6, 2026
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Allow streaming text checkpoints to advance past completed legacy tool tags while retaining incomplete tool headers.

Example: Stream [TOOL_CALL]{}\n[/TOOL_CALL]\n followed by 4,096 characters of prose in four-character chunks.

  • Before: The reported checkpoint remains at zero and regex scans process 12,025,421 characters.
  • After: The reported checkpoint reaches 3,949 characters and regex scans fall to 1,332,715 characters, preserving visible text.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, useful repair with production Gateway evidence, a reported red/green regression, passing current-head CI, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied production Gateway trace exercises closed legacy bracket tags followed by 32 KB of prose through HTTP provider streaming and WebSocket delivery, verifies exact preview/final parity, and records responsive independent-session RPCs; both changed production blobs match the previously reviewed version.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Long assistant replies containing completed legacy bracket tags can stall streaming and delay other conversations.
Reason: The change removes demonstrated unnecessary work while retaining visible output, existing settings, and parser ownership.

Merge readiness

✅ Ready for maintainer review

This PR repairs a current streaming slowdown with a focused change, credible Gateway evidence, and passing current-head CI; no actionable defects remain.

Priority: P1
Reviewed head: 267801f61fc6ffac79b6b0f3c46076329997eb56

Before merge

None.

Findings

None.

Agent review details

How this fits together

Provider text passes through shared Markdown ownership and assistant-text filters before the Gateway emits visible reply deltas.

flowchart LR
  A[Provider text deltas] --> B[Assistant text projection]
  B --> C[Markdown checkpoint owner]
  C --> D[Legacy bracket filter]
  D --> E[Visible reply deltas]
  E --> F[Gateway subscribers]
Loading

Technical review

Best possible solution:

Land the focused repair in the existing checkpoint and legacy-bracket owners with its regression coverage.

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

Current-main source shows the pinned checkpoint path, and supplied before/after measurements demonstrate it; this read-only review ran no target code.

Is this the best way to solve the issue?

The repair restores settlement through existing owners, preserves canonical Markdown fallbacks, and adds one distinct regression without new runtime machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Markdown checkpoint settlement keeps the original intent (0bad3b4: Retain canonical ownership checkpoints to bound streaming work while preserving provisional Markdown semantics.)
  • Legacy bracket pending detection keeps the original intent (c6a601f: Keep unfinished tool headers from crossing a settled Markdown boundary before later chunks complete them.)
  • Streaming work regression table keeps the original intent (9070fc4: Bound ordinary brace-containing prose work while preserving canonical tool-call handling.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason Cat: Raw commit 752ad78 adds src/shared/text/assistant-visible-text.streaming-work.test.ts:3 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 752ad78253c2; files: src/shared/text/assistant-visible-text.streaming-work.test.ts)

PR surface

Source +22, Tests +10, Other +2. Total +34 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 29 7 +22
Tests 1 14 4 +10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 45 11 +34

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: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: Repeated synchronous scans of long replies can stall the shared Gateway event loop and delay other conversations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-06T02:02:02.852Z sha 4ced9210006f9ec774c6e102a23f734d9f689633 :: needs real behavior proof before merge. :: [P2] Account for the added regression lines in the test budget
  • reviewed 2026-11-06T04:13:37.658Z sha e26f2d1983466a8054b978f1a61d54e6dc6c3901 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-06T06:50:35.508Z sha 3f826b0c6edee43eb006480f9908cb45e36e9a2b :: needs maintainer review before merge. :: none

Reviewed November 6, 2026, 3:32 AM ET / 08:32 UTC (Revision 4).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/legacy-bracket-checkpoint-settles-313 branch from 4ced921 to e26f2d1 Compare November 6, 2026 04:07
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 6, 2026
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Nov 6, 2026
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 6, 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. labels Nov 6, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/legacy-bracket-checkpoint-settles-313 branch from 11e82ef to 267801f Compare November 6, 2026 08:14
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 6, 2026
…egacy bracket block

When the assistant visible text ends a legacy bracket tool block
([TOOL_CALL]...[/TOOL_CALL]) and then appends more reply text, the
checkpoint boundary was pinned to 0, forcing a full-prefix rescan on
every append. On a 64KB reply this re-scans ~73s and stalls the
Gateway event loop (BUG-313).

Relax the conservative fallback in code-regions.ts and narrow the
pending heuristic in assistant-text-transforms.ts so a cleanly closed
legacy bracket block settles immediately instead of re-scanning the
whole prefix.

The regression test adds 10 test lines; allocate them under
config/test-lines-allocations/legacy-bracket-checkpoint-settles-313.txt
(BUG-313).
@SunnyShu0925
SunnyShu0925 force-pushed the fix/legacy-bracket-checkpoint-settles-313 branch from 267801f to 2477918 Compare November 6, 2026 09:15
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Nov 9, 2026
@roboclaw-bot roboclaw-bot reopened this Nov 12, 2026
@roboclaw-bot
roboclaw-bot merged commit d66ba01 into openclaw:main Nov 12, 2026
230 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…egacy bracket block (openclaw#193871)

Allow completed legacy bracket tool-tag lines to settle while retaining conservative Markdown and incomplete-header handling.

Reviewed head: 2477918. Focused proof: 3 files / 144 tests passed. Local autoreview of df607f2..2477918 through P2 completed scoped-clean. Current-main integration with the already-landed delivery-filter repair passed all 19 shared-text suites / 673 tests (main a25ee98, tree 2e78a7de16bac5a1af152002c4fc1b4383b20d22). The unchanged main production files fail the added regression with settledLength=0 while 119 other cases pass; restoring this patch is green.

This is a bounded repair for the demonstrated workload. Supplied Gateway proof has no shipped-path before arm, and no universal arbitrary-bracket latency claim is made.

Thanks @SunnyShu0925.

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

Labels

clawtributors PR from a clawtributor P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

2 participants