Repository navigation
fix: reduce Markdown reparsing during streamed tool-call checks - #195161
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR shares incremental Markdown code-region ownership across tool-call checks within each provider or embedded-agent stream. Example: Stream 512 paragraphs of literal call-like prose in 16-character deltas with cumulative snapshots.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses remaining repeated Markdown parsing on current main, preserves the existing parser contract, and has no identified introduced defects; CI admission remains unresolved. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherProvider events enter the shared tool-call normalizer, which uses canonical Markdown ownership to preserve literal examples while scrubbing or promoting genuine calls; normalized events and terminal messages leave it. flowchart TD
A[Provider stream] --> B[Provider or embedded wrapper]
B --> C[Shared tool-call normalizer]
C --> D[Per-stream code-region resolver]
D --> E[Canonical Markdown parser]
C --> F[Visible text and tool-call events]
C --> G[Terminal message]
Technical reviewBest possible solution: Retain one canonical-parser checkpoint resolver per stream across both wrappers, preserving exact output and fresh parsing after source replacement. Do we have a high-confidence way to reproduce the issue? Current-main wrappers repeatedly use the stateless resolver, and the supplied exact-parent regression and benchmark identify the excess parsing; no target code was executed during this review. Is this the best way to solve the issue? The change addresses repeated work at the shared ownership boundary without replacing the parser, and the existing richer ownership resolver does not provide this two-tail checkpoint contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cf376b0d000a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +48, Tests +63, Other +30. Total +141 across 7 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. Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed November 8, 2026, 5:13 AM ET / 10:13 UTC. |
…tooling-lint-selection-20261108 * commit 'b0e90e6a4b359fff7756698067fdce4758b1907b': (38 commits) fix(android): Talk button demands a realtime provider on a native Talk setup (#191194) chore: trace first-run Gateway work and verify later replies (#195185) fix(knowledge): keep deleted messages out of reply previews (#195126) fix(agents): preserve streamed replies across Gateway restarts (#195164) perf(ci): reuse SDK transport path boundaries (#195180) fix(sandbox): avoid pauses for unchanged command checkpoints (#195120) fix(test): make retention checks portable across runtimes (#195091) fix(knowledge): clarify temporal kind filters (#194995) improve: reduce Gateway allocation while draining SQLite receipts (#195129) fix: reduce streaming CPU after reply and voice directives (#195145) fix: reduce Markdown reparsing during streamed tool-call checks (#195161) fix: restore the main dead-export gate (#195158) improve(ci): pack small UI selections into fewer jobs (#195107) fix(muse): quota and sign-in failures end with no reply (#195148) fix: allow first release push with shipped patch bytes (#195174) fix(ci): narrow single-config tooling selections (#195147) fix(packaging): reject incompatible prepublish plugin cohorts (#195152) fix(ci): prepare verified Bun before parity checks (#195155) fix: Incognito agent turns stall before execution (#195005) fix: credentialed search and speech providers work without picking a provider (#195169) ...
What Problem This Solves
Growing stream snapshots repeatedly reparse settled Markdown while checking for plain-text tool calls. Follow-up to #195136.
User Impact
Reduces main-thread allocation and CPU during streaming while preserving text, protected code, tool-call promotion, terminal messages, and replay behavior. No configuration, dependency, schema, or public SDK changes.
Why This Change Was Made
Both stream wrappers now share one per-stream Markdown ownership resolver across pending classification, snapshot scrubbing, promotion, and final results. It carries the canonical parser's mutable-tail boundary forward and reuses settled ranges. Complete source-line boundaries preserve indentation; reference definitions retain their enclosing source context. Replaced or shortened snapshots take the canonical fresh-parse path.
Production delta is +48 lines (+59/-11): 42 lines establish the missing per-stream checkpoint owner and six net lines connect the two wrappers. This retains the existing parser and avoids a second Markdown grammar. Reference-bearing or unresolved blocks can still retain a large tail, and other grammar/snapshot work remains superlinear.
Evidence
Synthetic real-normalizer benchmark: 40 tools, 16-character deltas, cumulative snapshots; five alternating fresh-process pairs. CPU timing and GC-inclusive 4096-byte sampled allocation measured separately. Parent is merged #195136 (
306bf7730b01); candidate is this commit. Values are warm medians per complete stream; allocation uses decimal MB.The long snapshot fixture reduces CPU 89.6%, sampled allocation 93.0%, and parsed characters per delta from 2053.5 to 16.5. Long fences improve CPU 33.8%, recovering the previously reported regression by reusing identical terminal ownership (two full parses become one). Plain/inline medians rise 0.024/0.027 ms (1.9%/2.2%); their parser work remains zero. Unchanged A/A CPU medians vary −1.15% to +5.20%; allocation medians vary −2.24% to +0.29%. Contended samples were retained.
Each 128-paragraph side has 25 warm samples; each 512-paragraph side has five. Long-snapshot CPU p95: 1423.585 → 166.924 ms; long-fence p95: 72.882 → 38.877 ms. These are synthetic owner measurements, not a claim about total production allocation.
Reproduce with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/tool-call-markdown-measure.ts --kind false-prefix --paragraphs 512 --turns 5: stateless baseline by default, candidate with--incremental; repeat with--mode allocation. The normalizer package itself is unchanged from the pinned parent. Work counts wrap the installedfromMarkdowndependency rather than counting whole resolver inputs.The real embedded-agent wrapper regression fails on exact parent
306bf7730b0108e863a6ecfc549bc8289d9bddc7: 40,768 parsed characters exceed the 13,568 bound. The candidate passes while preserving streamed text, terminal output, andstream.result(). Review also exposed a nested-reference-definition context bug in the first candidate; its regression failed before the correction and passes now.187 focused tests passed; the affected 78 passed again on the final source. Browser Markdown tests: 3 passed. Streaming UI E2E: 8 passed. Independent comparison: 4,164 exact event replays, 40,451 canonical range queries, and 157,168 scrub projections all match. Codex autoreview is scoped-clean through P2.
The full
check:changedrun completed. After replacing external dependency symlinks with a private clone of the same installed dependencies, every typecheck and lint rerun passes. All other changed guards pass except the exact-parent failures detailed below. This is not a claim of an all-green check run.Exact-parent main regressions reproduced during changed checks
These remain unresolved main regressions; no check was weakened:
266a7aa0fe69).1595dd247707, +9 exports/+1 callable/+1 wildcard), feat(codex): use OpenClaw's base prompt for ordinary threads #191344 (94ba8aef4070, +1 export/+1 callable), feat(research): retain authorized browser research state #177231 (ecb716937da5, +1 export).NPM_EVIDENCE_FILEfrom fix: reduce repeated npm publication evidence requests #195099 (c9e6370bb191);canonicalizeForContainmentSync/UncanonicalReasonfrom fix: route path containment through one canonical spelling owner #195061 (ce840d8a8290);expectCollected,expectLiveObjects,forceFullGcfrom fix(test): expose full GC for portable retention checks #195064 (754b41c65df0).SDK/dead-export checks reproduced against byte-identical exact-parent source; changelog checks used an exact-parent archive. Introducing commits and raw-parent patches were inspected. These need separate owner repairs.
Ready for review; intentionally not merged.