Repository navigation
fix: reduce repeated parsing in streamed final answers - #175328
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 changesThis PR reuses Markdown ownership across streamed chunks and refreshes it when appended syntax can change code protection. Example: A final answer streams an unfinished [tool:write] JSON payload containing 4,096 characters in four-character chunks.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a verified streaming-performance defect that remains on current main. The previous wrapper-inventory finding is fixed, and this review found no remaining actionable defect; exact-head CI is still pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherAssistant response deltas enter the shared text projector, which uses canonical Markdown ownership to hide tool-call syntax while preserving literal code and emitting append or replacement deltas. flowchart TD
A[Provider response deltas] --> B[Assistant stream subscriber]
B --> C[Shared text projection]
C --> D[Markdown ownership parser]
D --> E[Stream-local ownership reuse]
E --> F[Tool-call filtering]
F --> G[Visible text and replacement deltas]
Technical reviewBest possible solution: Land the stream-local ownership reuse with canonical invalidation after the required exact-head checks pass. Do we have a high-confidence way to reproduce the issue? Current-main checkpoint code confirms the repeated whole-buffer parsing path described in #175264, and the supplied base-versus-head work regression demonstrates it; this read-only review ran no target code. Is this the best way to solve the issue? The change addresses the repeated parsing at the existing owners, preserves canonical output and replacement behavior, and keeps the model-token consumer on fresh ownership rather than sharing incompatible cached text spans. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ac9e4bc784d6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +557, Tests +466, Other +763. Total +1786 across 13 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 (13 earlier review cycles; latest 8 shown)
Reviewed October 23, 2026, 12:49 AM ET / 04:49 UTC (Revision 14). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
What Problem This Solves
Fixes streamed final answers exposing tool-call text when a supported inline-link title closes across chunks, including titles after balanced or multiline destinations.
Fixes #175264
Why This Change Was Made
The stream reuses parsed Markdown ownership across appended chunks and refreshes it when link titles, image descriptions, reference definitions, GFM table delimiters, or indentation can change code ownership. HTML invalidation was removed because the canonical parser disables HTML flow and text nodes.
User Impact
Tool-call syntax stays hidden as Markdown syntax completes, while literal examples in indented, list, and fenced code remain visible.
Evidence
2c5b726and head2d394cf: the sameopenclaw agent execloopback Responses SSE proof matched canonical output, hid resolved tool calls, and preserved literal code. It recorded 351 ms on the base and 49 ms on the head for one run.AI-assisted: built with Codex
Maintainer follow-up
The open-table checkpoint returned before applying canonical Markdown retention. An earlier image description could therefore be settled as literal code before a later reference definition revoked that code ownership, leaving a tool marker visible. The follow-up takes the earliest of the table boundary, canonical image/title retention, and long-label retention. This keeps the mutable-image/reference intent of #172832 (
a8a67b01) intact instead of weakening literal-code preservation. Contributor commits and @sunlit-deng's ownership are preserved.The added eight-case table-driven regression checks every two-chunk split, one-character and four-character chunkings, canonical output at each prefix, and delta reconstruction. It fails on the original production code in the three image/table cases and passes with the fix. The broader lane-only deterministic sweep covers escaped brackets and backslash runs, nested labels, one-to-three-backtick spans, reference titles, images, angle destinations, tables, ordinary/list/tilde/four-backtick fences, CRLF, tool markers, model control tokens, and long normalized labels: 439 documents, 37,836 chunkings, 119,743 prefix checks, zero divergences, 88.484 seconds. The original contributor head produced 418 divergences on that corpus.
Validation on macOS:
pnpm buildpassed in 49m33s on the shared Mac.pnpm openclaw --profile projection-table agent execsent one streaming Responses request (seven SSE events), produced the exact expected sanitized final output, and preserved fenced tool/model-control examples (103.584s, including startup). This checks transport/final rendering; the production-projector differential sweep checks prefix/delta parity.openclaw agent execwith native Ollamallama3.2:latestreturned the exact requested text in 106.530s, including startup. The first control with minimal tools instead returned a tool error; the recorded passing control uses the documented deny-all tool policy and exact-text assertion. Ollama is an unphased control, not a reproduction of Responsesfinal_answerphase handling.Follow-up LOC: production +2/-5 (net -3), tests +37. Full PR relative to current main: runtime production +615/-22, tests +499/-48, existing proof script/inventory +762. The contributor's cache machinery accounts for the production growth and avoids repeatedly parsing settled Markdown while retaining canonical invalidation.
Remote check follow-up
CI run 39892893645 passed the text checks and baseline ratchets, but
checks-ui-e2e (6/9)failedchat-image-lightbox.e2e.test.ts:402: navigating back toafter.pngrecorded a duplicate 1920px rendition request. The aggregateopenclaw/ci-gateremains red. The entire UI and media-core source trees are unchanged from merged main87aada17522b; the test routes all media requests (Playwright documents that routing disables HTTP cache), while the gallery retains the loaded URL through this navigation. The focused local scenario passed (10.423s test, 173.22s Vitest duration), which does not prove a CI repair. CI’s automatic pre-existing label names a main run with a different failure, so it is not matching-signature evidence; this remains an inherited-source UI/harness limitation for maintainer review. No retry or test weakening was used.ClawSweeper re-review was requested after the push. After the requested 15-minute polling window, its published review still names the prior
2d394cf75428head; no exact-head ClawSweeper verdict is available yet.Maintainer follow-up: main merge
Merged main through
e7c1640eed231b250c43166840a2ed6615f3704dwithout rebasing or replacing @sunlit-deng's commits. The conflict resolution keepstextSpans,unsettledDefinitionStarts, andunresolvedImageCodeStart. The semantic audit confirms that the model-token filter obtains fresh text spans; the ownership caches remain private to their checkpoint and tool-call consumers.The required mixed-corpus proof exposed an additional defect already present on that main: an unfinished table delimiter could split a paragraph containing multiline code, then an ordinary appended character invalidated the table without restoring the literal control token. The canonical Markdown owner now retains that preceding paragraph until the delimiter settles. The checkpoint consumes that boundary directly, removing its duplicate table scanner. The small table-retention helper keeps the parser within its existing line cap. Three regression cases covering LF, CRLF, and CR failed before the fix and pass afterward, including full final-answer delivery and replacement deltas.
Validation on macOS, Node 26.12.1:
Fresh
pnpm build runtimepassed in 537.883s wall. Builtpnpm openclaw --profile projection-merge agent execsent one streaming loopback Responses request with eight SSE events, matched the exact expected final output, stripped image-alt controls, restored literal controls after table invalidation, and preserved fenced examples (37.977s). Native Ollamallama3.2:latestreturned exactlyLOCAL_MODEL_CONTROL_OKthrough the same real CLI (22.491s). The CLI checks transport/final rendering; prefix and delta parity are established by the sweeps. Ollama is an unphased local-model control. Local proof is macOS-only; no operator Gateway or shared model state was changed.Owner follow-up: production +24/-61 (net -37), tests +15. Full PR against merged main: production +579/-22, tests +514/-48, existing proof script/inventory +762. The retained production growth is the contributor's stream-local ownership reuse and invalidation machinery; this follow-up removes duplicate table policy. Contributor history and credit are preserved. No new configuration, dependency, or public contract is introduced.
CI follow-up: wrapper inventory
CI run 39900038625 on
f447065f0c4failed the two PR-wrapper import-closure scenarios because the newly extractedtable-code-retention.tswas omitted from the wrapper's source inventory. Both failures reproduced locally. Commit010a449ef62e66b3e9f288f5709d2bb82fb077efadds that one inventory entry; the same two tests then passed in 93.65s wall. This also addresses ClawSweeper's sole P2 finding onf447065f0c4.No runtime code or test expectation changed in this follow-up. The semantic sweeps, 449 focused tests, build, and built-CLI/Ollama proof above remain applicable to the identical runtime tree. Full PR totals are production +579/-22, tests +514/-48, and proof/inventory +763. The inventory-only commit also passed focused Codex autoreview through P2 with no findings.
Final main-merge verification
Head
010a449ef62e66b3e9f288f5709d2bb82fb077ef: CI run 39901607679 passed, includingopenclaw/ci-gate(52 successful jobs). The broader check rollup is green, including security and dependency reviews. ClawSweeper's exact-head review reports no findings, no before-merge items, and sufficient proof. Its earlier pending-CI note is superseded by the completed successful run. Ready for maintainer review; not merged.