Repository navigation
Conversation
A streaming delta ending in a partial ordinary tag prefix such as <p still triggered findCodeRegions() on the whole accumulated reply. Hold the unresolved prefix in the streaming projector until it resolves, while keeping fences and ambiguous Markdown on the canonical resolver. Fixes openclaw#180720
|
🦞👀 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. |
A literal tool-call tag protected inside Markdown code no longer disables the partial-prefix hold for the rest of the stream. Add a deterministic regression for a fenced <tool_call> example followed by ordinary HTML.
|
Codex review: needs maintainer review before merge. What this changesThis PR avoids repeated Markdown parsing for unresolved streamed HTML prefixes while preserving canonical code ownership and tool-call stripping. Example: A 65,536-byte HTML reply arrives through the built Gateway in four-character provider deltas.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a concrete performance defect still present on current main. The prior completed-line ownership finding is fixed, and this review found no further actionable code defects. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherProvider text enters the shared assistant-visible-text projection pipeline; its XML filter hides tool scaffolding while Markdown Core protects literal code, then visible text reaches Gateway clients. flowchart LR
A[Provider text deltas] --> B[Assistant text projection]
B --> C[XML candidate scanner]
C --> D[Carried protection state]
C --> E[Canonical Markdown ownership]
D --> F[Visible text projection]
E --> F
F --> G[Gateway client delivery]
Technical reviewBest possible solution: Land the focused XML-owner optimization with its work-budget and code-ownership regressions once the exact-head merge gates pass. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the reported repeated parsing path, and the linked issue supplies deterministic four-character chunk reproduction; this read-only review executed no target code. Is this the best way to solve the issue? The patch fixes the existing XML projection owner, reuses its shared protection scanner and conditional projector, and preserves canonical parsing whenever ownership is uncertain. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 88380613fb52. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +155. Total +155 across 2 files. Added test files: 0. View PR surface stats
Review metrics
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 (1 earlier review cycle)
Reviewed October 23, 2026, 12:09 AM ET / 04:09 UTC (Revision 2). |
Classify unfinished lines with the shared protection scanner before withholding a trailing prefix. Keep uncertain ownership canonical and retain prefixes in the existing projector instead of a second buffer. Replace the separate fence scan and cover every split of 54 adversarial inputs, including unfinished indented code and list continuation fences. Co-authored-by: JasonBuildAI <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Keep partial-prefix shortcuts within the current unfinished line so a trailing newline cannot discard literal indented code. Sweep LF, CRLF, and blank-line suffixes at every chunk split.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
What Problem This Solves
Fixes: a long streamed ordinary HTML reply can still spend 4.8-5.2 seconds of blocking Gateway CPU at a delta boundary that leaves a partial tag prefix such as
<p, delaying every channel, session, cron turn, and tool call in the same process. Fixes #180720.This is a follow-up to #175472 and its source report #175439. The merged optimization skips complete ordinary tags and partial prefixes inside settled fences. Outside those cases,
<pis still a prefix of<parameter>, so every four-character delta that ends there sends the whole accumulated reply through the canonical Markdown ownership resolver again.User Impact
User impact: long HTML, JSX, XML, SVG, and comparison-heavy answers no longer stall unrelated Gateway work at partial tag boundaries. On a 64 KB fixture streamed in four-character deltas, the shipped
createAssistantVisibleStreamText()path drops from 4,840.5 / 5,175.8 ms to 655.0 / 631.0 ms (multiline / single-line) on the same Windows host. The deterministic 16 KB regression drops from 5,417,280 parsed characters against a 31,980-character budget (169x over) to within budget. Tool-call stripping, fenced-code ownership, and one-shot output remain unchanged.Why This Change Was Made
Streaming mode now holds only an unresolved tag prefix just long enough to see whether the next delta completes it. Ordinary markup is released to the existing projector; a completed tool-call candidate still goes through the canonical resolver. The carried protection scan disables holding for fences, ambiguous paragraph ownership, and structural uncertainty, preserving the existing Markdown semantics.
The fast path also disables itself permanently once any complete tool-call candidate is found, so later deltas cannot hide or reorder tool-call XML.
Evidence
Pre-fix regression on upstream code:
Post-fix regression and the same real-entry probe on final head
093313d4b43(rebased tobee83199e15):The same probe on the pre-fix code produced:
Validation run on final head:
<tool_call>example permanently disabled the fast path. The new regression failed first withexpected 5447844 to be less than 32082, then passed after the fix in093313d4b43.pnpm tsgo:coreexited 0.node scripts/run-format.mts --check src/shared/text/tool-call-xml.ts src/shared/text/tool-call-xml.streaming-work.test.ts:All matched files use the correct format.git diff --check upstream/main...HEAD: no output, exit 0.node scripts/run-oxlint.mjs ...exited 0.Validation gap: targeted oxlint used the wrapper-supported
OPENCLAW_OXLINT_SKIP_PREPARE=1path because this Windows host timed out while generating plugin-SDK boundary declarations at both 300 seconds and 900 seconds. The same declaration preparation completed successfully before the rebase, and the rebase did not touch either target file. PR CI will rerun the full declaration and lint lanes.AI disclosure: this change was drafted with AI assistance at my request, under my direction and review.
Maintainer follow-up
The unfinished-indented-line regression is fixed at the XML projection owner. The final implementation classifies a copy of the current protection state before retaining a trailing prefix, and only takes that shortcut when the candidate lies on the unfinished current line, so literal indented/inline/fenced code keeps canonical ownership. It retains prefixes in the existing conditional projector and removes the second output buffer and separate fence scan. Ambiguous Markdown continues through the canonical resolver. The generic projector is unchanged; the broader hold API proposed in #180775 is not needed and was not merged.
The bounded regression covers 236 adversarial variants (59 seeds with unchanged, LF, CRLF, and double-LF endings) in both modes, every two-chunk split (including empty chunks), and one-character/four-character streams: 15,414 schedules and 46,620 prefix comparisons, with delta reconstruction checked as well. It covers indentation/tabs/list continuation, fences, inline code, HTML blocks/tags, partial
<p/<pre/tool/function tags, entities, references, malformed adjacent candidates, and CRLF. The committed sweep took 4.068 s; the complete owner file passed 9 tests in 14.308 s wall time. A standalone run of the same corpus took 1.313 s. Two larger independent diagnostics against the actual production source performed 1,226,506 prefix checks with zero divergences (separate 4.799 s and 28.248 s runs; these are not added to CI). The original regressions were red against both original owners: main fails the work budgets and list/fence parity; contributor093313d4b43loses<pfrom<p. The expanded table also reproduced the later completed-line finding on205117ed252:<\nlost its literal prefix. All are green with this repair.Local validation: 240 targeted tests passed, including the visible-text projection and embedded-agent delivery consumers (consumer run: 129.928 s wall across three shards). Core and shared-test typechecks, scoped type-aware lint, formatting, max-lines, line-cap, assertion-safety, timeout-race, mock-export, config-doc and plugin-inventory checks pass. Source +28/-28 (net 0); tests +155/-0, relative to the tested main base
87aada17522b.Built Gateway proof used the same 65,536-byte HTML fixture in 16,384 four-character provider SSE deltas per request, through the public
/v1/chat/completionsendpoint in separate clean builds of baseline87aada17522band final headfa146ed3293. Source, streamed delivery, and batch delivery match byte-for-byte on both heads (SHA-2560f7afdd7770dca424be28c5353056d58fe9f0132122a5101d7fd00f19ee6d7c1). Across each stream/batch pair:This is 28.84% less ownership-parser input through the built delivery path, including deliberately ambiguous Markdown that still uses canonical parsing. In-memory instrumentation counted the resolver and actual parser across the Gateway and its workers without modifying source or build artifacts. Both runtimes verified Node 26.12.1. Final build passed in 12m53s wall time. Instrumented request samples were 68.043s / 9.541s baseline and 31.071s / 8.389s final (streamed / batch); these include Gateway/session/provider overhead on a shared host and are not an isolated projector benchmark. The final receipt contains complete timings and provider request metadata.
Final-head Qwen HTML smoke: failed. The exact built Gateway routed to native Ollama
qwen2.5-coder:1.5b-instruct(requested and response model verified, HTTP 200). The first final-head control delivered 1,913 bytes / 416 SSE frames in 41.244 s, but they contained repetitive pseudo-tool JSON rather than the requested paragraph/preformatted HTML. A single sampling-control retry verified nativeoptions.temperature=0; it again emitted pseudo-tool JSON, then exhausted the Gateway's visible-answer continuation and ended in an SSE internal error. Both runs retained three advertised tools despite deny-all/code-mode-off configuration. No further model retries or production changes were made. An earlier205117ed252literal-HTML control delivered 112 HTML bytes successfully, while two earlier prompts failed similarly; this model-control variability remains a limitation, and no final-head HTML-smoke pass or tool-free-provider claim is made.Fresh Codex branch autoreview on the final follow-up returned scoped-clean: no actionable P0–P2 findings with the complete owning modules supplied. The separate full-module review and executed parity tests provide additional coverage.
The existing contributor commits are preserved, with JasonBuildAI credited in the maintainer commit. This is a macOS arm64 / Node 26.12.1 proof; request timings are instrumented, single cold/warm samples on a shared host, and include Gateway/session/provider overhead. Work counts and exact delivered bytes are the primary comparison. Conservatively unclassified Markdown still uses full ownership parsing.