Repository navigation
fix(text): streaming Markdown checkpoint must settle after a closed legacy bracket block - #193871
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesAllow streaming text checkpoints to advance past completed legacy tool tags while retaining incomplete tool headers. Example: Stream
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherProvider 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +22, Tests +10, Other +2. Total +34 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 6, 2026, 3:32 AM ET / 08:32 UTC (Revision 4). |
4ced921 to
e26f2d1
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
11e82ef to
267801f
Compare
|
🦞👀 Re-review progress:
|
…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).
267801f to
2477918
Compare
|
Merged via squash.
|
…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]>
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 —settledLengthstays 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).findTextCheckpointtreats any line containing[as needing the full paragraph context and returnsoffset = retainStart(= 0); andscanLegacyBracketToolCallBlockssetspendingfrom 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.[TOOL_CALL]/[TOOL_RESULT]tag line with no other open bracket or link is allowed to settle immediately; andpendingis narrowed so only a partial[TOOL_(CALL|RESULT)header keeps the reply pending.src/shared/text/code-regions.ts(findTextCheckpoint) andsrc/shared/text/assistant-text-transforms.ts(scanLegacyBracketToolCallBlocks), plus one regression row insrc/shared/text/assistant-visible-text.streaming-work.test.ts.[TOOL_Cheader 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
pendingheuristic 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 fullsrc/shared/textsuite (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
[TOOL_(CALL|RESULT)headers still keep the reply pending.<comparison re-parse the whole answer per delta (45 s at 128 KB) #187400 (streaming re-scan stalls), fixed at the checkpoint/legacy-bracket layer.[(e.g.Array index [0) still keeps that final line un-settled — that is intentional conservative behavior, not part of this fix.Evidence
Before → After (summary)
origin/main)settledLength/ source)scannedChars, in-process)Shipped Gateway streaming proof (isolated run)
Isolated Gateway started through the production
startGatewayServerCoreentry point, with an independent local OpenAI-compatible HTTP provider and a real WebSocket client subscribed to theagentstream. 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.[TOOL_CALL]{}\n[/TOOL_CALL]\n+ ~32KB of prose, 4-character deltas.agentstream deltas are reconstructed into the preview and compared against the final assistant text for the whole reply./healthprobes and by a second, independent WS session issuing real Gateway RPCs while the workload streams (the cross-conversation case).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 viacreateAssistantVisibleStreamText("final_answer")):Behavior matrix (regression shape):
scannedCharsis the total characters fed toRegExp.prototype.testacross 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 testbounds ordinary legacy bracket block streaming workassertssettledLength > 90%,scanned < 512× source length, andmarkdownOwnershipWork.scannedCharacters < 16× source length; it is RED on origin/main and GREEN on this branch.[(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.src/shared/text/code-regions.ts,src/shared/text/assistant-text-transforms.ts, andsrc/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 latestorigin/main.