Repository navigation
perf(streaming): defer partial HTML tag prefixes - #180775
xiaopan-xydt wants to merge 2 commits into
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: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
Hold unresolved tool-tag prefixes until they resolve instead of emitting and retracting them, and keep inline-code candidates on the canonical resolver because later references can revoke their ownership. Track prefix holds by length so the ordinary-HTML fast path stays linear.
|
Addressed both P2 projection regressions in a3962c2:
Verification: the full The live Gateway/client proof requested in the first checklist item is still outstanding. |
|
The canonical fix landed in #180765 at edbe9a2. It handles partial HTML prefixes in the XML projection owner, preserves unfinished and completed-line code ownership, and keeps the generic projector API unchanged. Thank you @xiaopan-xydt for investigating this and proposing a fix. Leaving this draft for you to manage. |
|
Closing as superseded. Main now handles the unresolved-prefix stream path in #180765 (edbe9a2), including prefix holding, the fence fast path, and chunk-boundary parity coverage. That implementation explicitly avoids the broader hold API proposed here, and its tests cover the scenarios added by this PR. The branch also conflicts with the newer |
Fixes #180720
What Problem This Solves
A long ordinary HTML answer could still make the Gateway pause while it streamed because every partial tag such as
<ptriggered a full Markdown parse of the entire growing reply. Partial prefixes are now carried as an unscanned tail until a later chunk proves they belong to a tool-call tag; normal HTML remains a cheap pass-through.toolCallXmlTextFilter(..., true)deferred a partial prefix only when it was inside a settled fenced block. Outside that case,<p,<param, and similar ordinary HTML prefixes calledfindCodeRegions()and then transformed the whole accumulated reply. Four-character chunks repeatedly landed on these prefixes, producing superlinear work.src/shared/text/tool-call-xml.tsnow treats partial prefixes as pending text. The work-budget fixture was changed from fenced JSX to 16 KB of ordinary unfenced HTML whose chunk boundaries land on partial tags.Why This Change Was Made
A partial prefix cannot be stripped before it is complete, so parsing the whole document to decide ownership is wasted work. Deferring it preserves the exact canonical decision for the later delta that completes the tag, while a prefix that resolves to ordinary HTML never needs the resolver at all.
User Impact
Long HTML, JSX, XML, and comparison-heavy replies no longer monopolize the shared Gateway event loop at every chunk that ends inside a tag name. Users see the same visible text, but unrelated sessions and scheduled work can continue responding while the answer streams.
Evidence
Shipped
createAssistantVisibleStreamText()path, 65 KB HTML, four-character chunks, fresh Node process:The issue's pre-fix measurements for the same fixture were
4840.5 msand5175.8 ms; visible text and character counts remain unchanged.Deterministic base-red on the new unfenced 16 KB HTML work-budget fixture, before changing the production filter:
After the filter change:
Broader projection regression run:
What was not tested: a live multi-session Gateway under sustained 64 KB HTML output. The probe calls the shipped projection entry point and the tests cover the filter composition path. Full TypeScript checking with the repository's
tsgorunner was unavailable on this host because its downloaded Linux binary requires a newer glibc than the host provides; CI will run the repository type checks.AI Assistance
This PR is AI-assisted. Used
rg,git diff, the existing streaming work-budget test, focused Vitest runs, and a fresh-process probe through the shipped visible-stream API to locate the residual parse path and verify the result. The implementer understands the code: an incomplete tag prefix is deferred without ownership parsing, while a completed tool-call tag still takes the canonical resolver.