Repository navigation
Conversation
Share lazy ownership within candidate classification and carry paragraph settlement through incoming chunks before the first candidate. Preserve literal code, promotion, and event replay while avoiding redundant full parses. Add work-count regressions and a real-normalizer allocation/CPU benchmark.
|
🦞👀 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 lazy Markdown protection within candidate classification and lets the existing fence scanner settle preceding paragraphs before checking candidates. Example: Stream 7,040 characters of literal call-like prose in 16-character chunks.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes measurable parsing waste still present on main, and no concrete introduced correctness or security defect was found; required CI remains unresolved. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe shared tool-call repair package receives provider events and cumulative assistant snapshots, preserves literal Markdown examples, and emits scrubbed text or recoverable tool-call events for agent consumers. flowchart LR
A[Provider stream events] --> B[Stream normalizer]
B --> C[Candidate scan view]
C --> D[Canonical call grammar]
C --> E[Markdown protection]
B --> F[Snapshot projection]
F --> G[Agent stream consumers]
B --> G
Technical reviewBest possible solution: Keep lazy protection in the existing candidate view and reuse the existing fence scanner while preserving canonical fallback for uncertain ownership. Do we have a high-confidence way to reproduce the issue? Current main eagerly resolves Markdown separately during candidate and trailing-prefix scans and declines unfinished-line admission; the supplied benchmark and reported base-failing regressions target those paths, but this review executed no target code. Is this the best way to solve the issue? The defect is repeated ownership parsing; the invariant is identical literal text, scrubbing, promotion, and replay, and sharing one lazy scan view while extending the existing conservative fence scan is a small, coherent repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 64b382cf3d73. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -4, Tests +18, Other +231. Total +245 across 6 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:
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, 4:01 AM ET / 09:01 UTC. |
…95136) Share lazy ownership within candidate classification and carry paragraph settlement through incoming chunks before the first candidate. Preserve literal code, promotion, and event replay while avoiding redundant full parses. Add work-count regressions and a real-normalizer allocation/CPU benchmark.
What Problem This Solves
Streaming plain-text tool-call repair repeatedly parses accumulated Markdown when literal call-like prose arrives in small chunks, creating avoidable CPU and allocation pressure.
User Impact
Literal Markdown, tool-call promotion, and event replay stay byte-for-byte equivalent in the exercised streams while inline-code prose and false call prefixes allocate substantially less. No configuration, dependency, schema, or public API change.
Why This Change Was Made
One candidate scan view now owns lazy code protection for sequence and trailing-prefix classification. Invalid prose no longer eagerly asks for Markdown ownership; already-resolved code ranges still skip grammar work. The existing carried fence scanner can reach a blank paragraph boundary before judging the first candidate, and can judge an unambiguous unfinished line without reparsing all prior output.
This does not replace the canonical Markdown parser or add a cross-delta cache. Cumulative snapshot scrubbing and real-call payload ownership still perform full parses. Runtime production code is net −4 lines; the two regression cases add 18 test lines with a matching scoped allocation, and the rerunnable benchmark adds 229 lines.
Evidence
Baseline:
60b66097c5a6b39f40924a081e20c16842e11dc5. Committed workload:scripts/perf/tool-call-markdown-measure.ts, using the real normalizer, real promotion/scrubbing, canonical mdast resolver, 40 tool names, 16-character deltas, cumulative partials, authoritative text end, and terminal snapshots.Acceptance before measurement: exact replay, lower parsed characters/allocation on the affected workload, and no >20% CPU regression. Five interleaved fresh processes per side × five measured streams for each fixture; timing and allocation runs separate. Allocation uses the inspector sampler at 4 KiB with objects collected by major and minor GC included. MB below is decimal sampled allocation per complete stream, not retained heap.
For the 7,040-character literal-prefix stream, parsed work falls 441,616 → 227,712 characters, allocation 46.8%, and median CPU 45.1%. The admission fallback contributes no full parses after the fix; 64 cumulative-snapshot parses remain. The larger 28,160-character version still has superlinear snapshot work (6,835,264 → 3,614,208 parsed characters), with roughly 2.09 s → 1.14 s CPU. This is a bounded waste-removal change, not a claim of fully incremental parsing.
Tradeoff: the 28 KiB fenced-example workload is about 8% slower in CPU (roughly 52 → 56 ms); the 7 KiB fenced case improves. The larger-case cost is disclosed, stays inside the prewritten CPU limit, and is not called a universal speedup. True-call allocation is +0.54% with overlapping sampled ranges; its parse work is unchanged.
A/A controls covered all five fixtures. The unchanged false-prefix controls were 144.991 / 143.977 ms CPU and 542.00 / 541.92 MB allocation. One small-sample candidate true-call tail reached 8.458 ms CPU; separate quiet 250-stream controls gave median/p95 2.908/3.897 → 2.928/3.885 ms and max 4.384 → 4.701 ms. An initial +9.7% fenced-allocation regression was diagnosed and removed before this final measurement.
Validation: both new real-stream regressions fail on the exact base (18 unwanted Markdown parses versus zero; three same-text parses versus two), then pass. 254 focused package/provider/agent tests passed, with the final three owner suites rerun (89 tests). Independent synthetic replay matched all 4,164 streams, including code, malformed calls, reference/image ownership, reordered content blocks, thinking events, and stop/length/error/EOF. Selected browser tests (3) and streaming E2E tests (8) passed. Knip production/full-tree unused-file scans passed.
pnpm check:changedcompleted with one inherited failure, and every other selected check passed: changelog attribution rejects 20 historical credit lines. It reproduces using changelogs archived from exact base60b66097c5a6; #194364 (266a7aa0fe69) added the offending forbidden-handle exclusions without reconciling historical records. Examples:CHANGELOG/records/2026.6.8.md:71andCHANGELOG/records/2026.10.6.md:254. This is an unresolved main regression, not a passing check.Fresh Codex autoreview of the complete final staged change against the pinned base: scoped-clean through P2, no accepted/actionable findings. No live deployment or production data was accessed; this is synthetic owner-boundary proof, not a full Gateway/database load test. The owner performs no database or workspace I/O, so those inventory sizes are not fixture inputs.
Reproduce a fixture with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/tool-call-markdown-measure.ts --kind false-prefix --paragraphs 128 --turns 5; repeat with--mode allocation, and compare a pinned package source using--owner <baseline>/packages/tool-call-repair/src/index.ts. Run exact event comparison separately with--compare-ownerso loading both implementations does not perturb timing.Requested outcome: ready PR, not merged.