Repository navigation
fix: reduce repeated scans in assistant prose streams - #183345
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: blocked before merge. What this changesReuse incremental paragraph results after duplicate prose appears, retaining canonical Markdown protection when code syntax becomes possible. Example: Two identical opening paragraphs followed by 128 distinct paragraphs stream in four-character chunks.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains This PR provides a focused, useful optimization with no actionable code findings; explicit performance-owner acceptance of the reported tradeoffs remains outstanding. Priority: P2 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherProvider text enters the shared assistant visibility and sanitization pipeline, which emits visible reply text and correction deltas for delivery. flowchart LR
A[Provider text deltas] --> B[Assistant visibility filters]
B --> C[Duplicate paragraph projector]
C --> D[Markdown ownership guard]
D --> E[Incremental prose state]
D --> F[Canonical code protection]
E --> G[Visible text and deltas]
F --> G
Technical reviewBest possible solution: Retain the existing-owner optimization if the performance owner explicitly accepts its recorded memory and latency tradeoffs. Do we have a high-confidence way to reproduce the issue? Current-main source exposes accumulated-text reconciliation after duplicate paragraphs, and the supplied base-red regression records excessive scan work; this read-only review executed no target code. Is this the best way to solve the issue? The smallest complete fix reuses the existing incremental paragraph state while its Markdown guard proves code absence, preserving canonical protection without another parser or collapse owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fd611c760e08. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +9, Tests +20, Other +79. Total +108 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReviewed October 27, 2026, 5:22 PM ET / 21:22 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Retain incremental duplicate-paragraph results until code syntax needs the canonical owner. Keep fixed workload measurements and late code-ownership regressions. Co-authored-by: liqiang2 <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Integrate current main while preserving CRLF separators and canonical code protection. The bounded prose probe avoids repeated scans without changing visible text or correction deltas. Co-authored-by: liqiang2 <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
Reuse the existing incremental paragraph state after duplicate prose instead of repeatedly scanning the accumulated stream. Preserve canonical fallback, overlap handling, and CRLF behavior. Validated with the base scan-budget regression, 76 focused tests, targeted checks, and exact output/delta benchmark comparison. Benchmark scans fell from 708,144 to 11,012; control remained 10,923. Historical owner measurements reported roughly 3% higher RSS. No fresh Gateway proof was run. CI completed with the five unrelated UI eslint(curly) diagnostics also present on scheduled main run 40578163761; those inherited failures are retained under the authorized exception. Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: liqiang2 <[email protected]>
What Problem This Solves
Fixes repeated full-reply scans while a long assistant answer streams after an early duplicate paragraph.
User Impact
Long prose replies use less projection CPU while retaining the same visible text, correction deltas, code protection, and raw conversation history. The measurements below retain the observed memory and tail-latency tradeoffs.
Why This Change Was Made
Once a duplicate appeared, each subsequent paragraph boundary reran canonical collapse on the growing reply. Reuse the existing incremental paragraph state while the existing Markdown guard proves code is absent, then retain canonical protection for ambiguous syntax. A three-character tail detects split indentation. The broad channel-benchmark extension was removed; a fixed owner benchmark remains with no new CLI options.
Production: +9 lines (+10/-1); tests: +20; benchmark: +79. The two state fields and bounded probe preserve late code ownership without a new parser, cache, or duplicated collapse implementation.
Evidence
12bb61686cc7: the final-answer stream preserved expected text and delta reconstruction but scanned 505,518 Markdown characters against a 127,488 budget (one intended failure, 52 skipped; 9 seconds Vitest / 13.11 seconds wrapper).node scripts/run-vitest.mjs src/shared/text/assistant-visible-text.streaming-work.test.ts src/shared/text/text-projection.test.ts --maxWorkers=1: all 76 tests passed after integrating current main (29.40 seconds Vitest / 31.19 seconds wrapper). This covers late fenced and indented code across every split; the merge preserves current CRLF paragraph separators. The new bounded-work case takes 13 ms.The current-main acceptance rule was recorded before these measurements: fixed 128-paragraph input plus no-duplicate control, four-character chunks, five interleaved base/head processes; exact output/delta reconstruction, approximately linear scan work, at least 75% fewer scanned characters, and no unexplained material projector regression. Run
node --import ./scripts/tsx.mjs scripts/bench-duplicate-paragraphs.mts. Node v26.12.1, host load 26.8–29.3. RSS is captured before separate scan-count instrumentation. First projection and warmed projection are reported separately; this does not measure cold Gateway startup.All ten processes preserved exact text and delta reconstruction. Duplicate workload correction count stayed one; control stayed zero. Scan work at 128 paragraphs fell 98.44%.
Times are median / empirical p95 (maximum of five), milliseconds:
Thread CPU medians: duplicate first 29.655 → 21.758 ms, warm 35.515 → 17.079; control first 9.464 → 8.919, warm 9.685 → 9.316. Process peak RSS median 246,688 → 254,080 KiB (+3.0%); sample maximum 257,376 → 257,360 KiB. The memory median moved adversely despite the flat maximum.
Historical contributor built-Gateway/QA-transport proof at
d9e4bb4ceeeccompleted 110 total base/candidate turns using a local Responses fixture: exact delivered text, one final outbound per turn, unchanged request counts, and raw provider bytes retained in history. It also measured Gateway cold RSS median +12.57%, warmed final-outbound p95 +2.52%, and no-duplicate projector warm-wall p95 +6.07%. Those measurements are retained as historical evidence, not silently superseded by this owner benchmark. A fresh integrated-head Gateway/channel run was not repeated because rebuilding that harness exceeds the bounded live-proof budget.Original contribution by @gdpu11. Co-authored-by: liqiang2 [email protected]
A fresh base/head run of the committed workload on the integrated source preserves exact output and reconstruction, with one correction for the duplicate workload and zero for the no-duplicate control. At 128 paragraphs, scanned characters remain 708,144 → 11,012; the control remains 10,923 → 10,923. This single pair verifies correctness and work counts; the timing/RSS study above remains the earlier five-pair measurement.
CI note: exact-head run 40584258320 is complete. Only check-lint-core-4 and the resulting CI gate failed. Its five
eslint(curly)errors in two unrelated UI browser tests exactly match scheduled main run 40578163761, check-lint-core-4. This PR changes neither UI file. The automatic report leaves attribution unknown because selected scopes differ. No unrelated UI repair or CI rerun was made.