Repository navigation
perf(markdown): reduce CPU work in streamed and chunked replies - #133152
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 3:47 AM ET / 07:47 UTC. ClawSweeper reviewWhat this changesThe PR reuses code-span indexes and already-rendered Markdown chunks during streamed replies and channel-size chunking, adds a boundary-annotation regression test, and updates the Markdown formatting guide. Merge readinessNo blocking correctness or security defect was found in the introduced patch. This is a focused behavior-preserving performance refactor that remains absent from the fetched current-main source, but it is maintainer-authored and carries the protected Priority: P3 Review scores
Verification
How this fits togetherOutbound reply text is parsed into Markdown IR, rendered for each transport, and split to that transport’s size limit. The agent stream path separately scans code fences and reasoning/final tags before it sends visible partial or block replies. flowchart LR
Reply[Assistant reply stream] --> Scan[Code and tag scanning]
Scan --> Visible[Visible streamed text]
Reply --> IR[Markdown intermediate representation]
IR --> Chunk[Rendered-size chunking]
Chunk --> Render[Channel-specific rendering]
Render --> Delivery[Outbound payload]
Decision needed
Why: The code review found no concrete blocker, but the PR is authored by a repository member and marked Before merge
Agent review detailsSecurityNone. PR surfaceSource +18, Tests +31, Docs +5. Total +54 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the one-way scanner and raw-IR/rendered-payload pairing, then land this focused optimization after exact-head checks finish green and a maintainer accepts the performance tradeoff. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes existing deterministic Markdown and stream-processing paths rather than fixing a separately reported user failure. Is this the best way to solve the issue? Yes. The change keeps parsing, renderer, and transport ownership intact, carries only prepared results within a call, and avoids a broader cache or duplicate rendering policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c04bee452e70. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
dae9afe to
576a7a2
Compare
|
Merged via squash.
|
Preserve literal final tags in delivered Markdown code examples while removing model final-answer markers outside code. Document the sanitization boundary and share it with reasoning cleanup. Refs #133152. Reviewed-by: @shakkernerd Co-authored-by: Shakker <[email protected]>
…#138989) Preserve literal final tags in delivered Markdown code examples while removing model final-answer markers outside code. Document the sanitization boundary and share it with reasoning cleanup. Refs openclaw#133152. Reviewed-by: @shakkernerd Co-authored-by: Shakker <[email protected]>
What Problem This Solves
Streamed replies and channel-sized Markdown chunks repeat parsing and rendering work. Code-heavy replies scan earlier fences at every character, unchanged text is indexed several times within one tag-filter call, accepted chunks are rendered again before delivery, and final-tag cleanup repeatedly copies the changing string.
Why This Change Was Made
Keep the existing parsing, rendering, and transport boundaries while carrying their prepared results forward:
No cross-call cache, provider policy, schema, configuration, persistence, or protocol change. The Markdown guide now distinguishes source-text and rendered-payload limits and removes an obsolete blanket claim about channels without IR styling.
User Impact
The same visible text, formatting, links, and streaming state require less CPU work. Exact nonmonotonic rendered-size search, surrogate boundaries, whitespace behavior, single-character escape behavior, and the uncapped path are preserved.
Production LOC: +67/−49 (net +18). Tests: +31. Docs: +17/−12. The growth retains the raw/prepared source distinction and measured payload through coalescing; it does not add a persistent cache or a second rendering policy.
Evidence
Paired, uninstrumented Node 26.8.1 measurements in two fresh processes with opposite starting orders; all raw samples and source hashes retained locally. Baseline owner source is
3afccb4e7f4bf5ef9737adb1edda2f3461d8dd58; the affected Markdown/shared-text/subscriber sources were unchanged when integrated onto357078cf7087534443dac92eb86e8aa32abb7b08.Long plain rendering and overflow-heavy marker rendering are effectively unchanged. Empty streaming controls vary by a few nanoseconds. These are owner-level measurements, not a claim about provider/network latency or a memory reduction.
The fresh candidate build at
dae9afedf9d70617410d8abb394be5874277eb16passed in 166.97 seconds. Its isolated real-OpenAI Gateway completed READY, sessions_list, web_fetch, and native web search; all 30 assertions across 14 read-only RPCs passed, including exact baseline titles/previews, tool inventories, and model catalog. CPU profiles and terminal/tool receipts were retained. These live timings are observational and do not establish a provider/network latency improvement.A fifth live literal-tag check failed: final delivery removes
<final>inside a code fence even though the raw assistant answer retains it. The delivery sanitizer and final-tag helper are byte-identical to the pre-PR baseline, and an actual-owner replay reproduces the loss. Named follow-up: preserve literal final tags through the final delivery sanitizer. This PR does not claim that existing behavior is fixed.ClawSweeper’s current-main/latest-review refresh request was completed: all six touched files remain unchanged on main
41dccabf179relative to the recorded base, and the latest review has no concrete source finding. The first hosted run inherited main’s stale side-effect-owner import. #133155 is now merged asbe5e79ca4713c33a11ccd56b2d728c19f0779f3d. The PR was rebased onto that repair as576a7a2dfaebd511df00ffef6366e9acdb748de2; its complete six-file patch is byte-identical to the locally tested/live-tested head above. Fresh exact-head CI is run 33299554989; landing remains gated on its result.The current head
576a7a2dfaebd511df00ffef6366e9acdb748de2has green exact-head CI (run 33299554989). The refreshed ClawSweeper review found no actionable defect; its rank-up request to finish checks and obtain maintainer acceptance is satisfied. Accepted for landing under the maintainer-authorized performance campaign. Native prepare gates passed.