Repository navigation
fix: avoid Gateway stalls after streamed tool-call XML - #181397
Conversation
Reuse settled XML output only while the canonical parser and Markdown ownership evidence allow it. Track ownership for both the raw reply and the parameter-unwrapping input, since removing XML can expose new Markdown syntax. Keep truncated tags, payload prefixes, and parameter boundaries on the canonical path. Cover the original append transitions and assembled syntax, and add a bounded-work regression plus a reproducible isolated Gateway workload. Fixes #175156 Co-authored-by: JasonBuildAI <[email protected]>
Skip per-delta block snapshots when there is no block-delivery consumer. Retain canonical pre-trim XML projection state in the reply-directive resolver so whitespace restoration does not restart parsing. Keep active block delivery and terminal batch behavior unchanged. Cover missing consumers, held directive frames, and source replacements.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review SummaryThis 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. |
Adapt asynchronous HTTP handlers to the server callback contract and require a spawned Gateway PID before process-group cleanup. This resolves the scripts lint failures reported by CI.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb96942ca3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| execFileSync("lsof", ["-t", `-iTCP:${port}`, "-sTCP:LISTEN"], { encoding: "utf8" }).trim(), | ||
| ); | ||
| const initial = await snapshot(); | ||
| assert.equal(initial.node, "26.12.1"); |
There was a problem hiding this comment.
Allow every supported Node runtime in the proof script
Running this newly documented proof on Node 24.22.1+ or on any newer Node 26 patch aborts after starting the Gateway, even though package.json explicitly supports >=24.22.1 <25 || >=26.12.1. Record the runtime version or validate the supported range instead of requiring exactly 26.12.1, so maintainers can reproduce the benchmark on supported environments.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses settled XML sanitization results and removes unnecessary per-delta parsing from Gateway reply streaming. Example: A 32,768-character reply contains unfenced tool-call XML followed by prose streamed in four-character chunks.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a remaining current-main performance defect, and no actionable patch defects remain. Both prior findings are resolved by removing the one-off proof scripts, and the current-head CI gate passes. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherModel text enters the assistant message-update pipeline as snapshots and deltas; text projections remove internal tool markup, preserve Markdown examples, and produce visible replies and delivery metadata. flowchart LR
A[Model text deltas] --> B[Message update owner]
B --> C[Text projections]
C --> D[XML sanitizer]
D --> E[Markdown ownership]
C --> F[Reply directive resolver]
F --> G[Visible reply delivery]
Technical reviewBest possible solution: Reuse settled results within the existing XML and Markdown owners while preserving canonical fallback, pre-trim directive coordinates, and callback-driven block delivery. Do we have a high-confidence way to reproduce the issue? Current-main source establishes whole-reply parsing after activation, and the linked report supplies deterministic work-count reproduction; this read-only review ran no target code. Is this the best way to solve the issue? The patch fixes the measured owner and consumer costs without a parallel parser, preserves canonical invalidation, and removes the unnecessary proof scripts; no smaller complete repair was established. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3ff4a6cb2781. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +122, Tests +226. Total +348 across 8 files. Added test files: 1. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 HistoryReview history (1 earlier review cycle)
Reviewed October 23, 2026, 2:38 AM ET / 06:38 UTC (Revision 2). |
The one-off Gateway proof harness and its metrics helper were only used to produce the PR evidence; the committed streaming parity and work-count tests guard the behavior. Keep the harness with the proof artifacts instead of adding 543 lines of unowned scripts.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* fix: avoid repeated parsing after streamed tool-call XML Reuse settled XML output only while the canonical parser and Markdown ownership evidence allow it. Track ownership for both the raw reply and the parameter-unwrapping input, since removing XML can expose new Markdown syntax. Keep truncated tags, payload prefixes, and parameter boundaries on the canonical path. Cover the original append transitions and assembled syntax, and add a bounded-work regression plus a reproducible isolated Gateway workload. Fixes openclaw#175156 Co-authored-by: JasonBuildAI <[email protected]> * fix: reuse XML projections through Gateway streaming Skip per-delta block snapshots when there is no block-delivery consumer. Retain canonical pre-trim XML projection state in the reply-directive resolver so whitespace restoration does not restart parsing. Keep active block delivery and terminal batch behavior unchanged. Cover missing consumers, held directive frames, and source replacements. * fix: handle async errors in the XML stream proof Adapt asynchronous HTTP handlers to the server callback contract and require a spawned Gateway PID before process-group cleanup. This resolves the scripts lint failures reported by CI. * chore(text): keep the XML streaming proof harness out of tree The one-off Gateway proof harness and its metrics helper were only used to produce the PR evidence; the committed streaming parity and work-count tests guard the behavior. Keep the harness with the proof artifacts instead of adding 543 lines of unowned scripts. --------- Co-authored-by: JasonBuildAI <[email protected]>
…aming (#175472) fix(text): stop re-parsing streamed Markdown for ordinary HTML/JSX markup While a long reply streamed, the tool-call XML filter parsed the whole growing Markdown text for every ordinary less-than sign, so long HTML/JSX answers burned a lot of Gateway CPU. The Markdown ownership check now runs only for text that could start a tool-call tag. Thanks @JasonBuildAI. Release adaptation: the stable filter predates main's streaming-prefix hold (#174376), isToolCallTagPrefix, isInsideSettledBlockCode, and the protection fast-path scanner. Ported the fix logic onto the stable loop instead: the Markdown ownership parse (findCodeRegions) now runs only for a complete tool-call tag candidate, and an unfinished trailing tag name (e.g. "<p") is rescanned on the next append without any parse, which covers the partial-boundary stall fixed on main by edbe9a2 (#180765). Both outcomes previously returned false, so the projection output is unchanged. Ported the #175472 and #180765 work-count and chunk-boundary parity tests (without main's streaming flag). 37e5e6c (#181397, stall after a real tool-call XML activates the filter) is a separate bug that depends on main-only ownership reuse (#175328) and diverged stream handlers; not included. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 2ad3797) Includes fix logic from commit edbe9a2
* fix: avoid repeated parsing after streamed tool-call XML Reuse settled XML output only while the canonical parser and Markdown ownership evidence allow it. Track ownership for both the raw reply and the parameter-unwrapping input, since removing XML can expose new Markdown syntax. Keep truncated tags, payload prefixes, and parameter boundaries on the canonical path. Cover the original append transitions and assembled syntax, and add a bounded-work regression plus a reproducible isolated Gateway workload. Fixes #175156 Co-authored-by: JasonBuildAI <[email protected]> * fix: reuse XML projections through Gateway streaming Skip per-delta block snapshots when there is no block-delivery consumer. Retain canonical pre-trim XML projection state in the reply-directive resolver so whitespace restoration does not restart parsing. Keep active block delivery and terminal batch behavior unchanged. Cover missing consumers, held directive frames, and source replacements. * fix: handle async errors in the XML stream proof Adapt asynchronous HTTP handlers to the server callback contract and require a spawned Gateway PID before process-group cleanup. This resolves the scripts lint failures reported by CI. * chore(text): keep the XML streaming proof harness out of tree The one-off Gateway proof harness and its metrics helper were only used to produce the PR evidence; the committed streaming parity and work-count tests guard the behavior. Keep the harness with the proof artifacts instead of adding 543 lines of unowned scripts. --------- Co-authored-by: JasonBuildAI <[email protected]> (cherry picked from commit 37e5e6c) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes long streamed replies consuming quadratic parser work after a model leaks or quotes tool-call XML outside code.
Closes #175156. Thanks @JasonBuildAI for the report and transition regressions from #175161; the commit preserves contributor credit.
User Impact
Long replies continue streaming without repeatedly parsing their settled XML prefix. Literal code examples, partial payloads, and later Markdown corrections keep the canonical output.
Why This Change Was Made
The XML parser now records whether its current decisions are settled. Reuse also checks canonical Markdown ownership for both the raw reply and the input to parameter unwrapping, because removing XML can itself expose a link, image reference, or incomplete tag. Code-free continuations retain a bounded delimiter boundary instead of comparing the growing reply. New tags and unsettled ownership still take the canonical path.
Runtime: +202/-80 lines (net +122); regressions: +227/-1 (net +226); opt-in Gateway proof tooling: +543. The added runtime state preserves the existing parsing phases and pre-trim directive coordinates rather than introducing another parser or configuration surface. The Gateway also skips block snapshots when no block-delivery callback exists, and the reply-directive resolver retains canonical pre-trim XML projection state across appends and source replacements.
Evidence
openclaw/ci-gate.[re+f]: /u, truncated quoted attributes, assembled syntax after XML removal, nested lists/tables/quotes, and CRLF.Built isolated Gateway on port 19900, using a 32,768-character fixture in 8,192 four-character SSE chunks, five warm samples per head:
All ten measured fixture replies matched exactly, including fenced XML preservation. A real native Ollama
qwen2.5:7bturn through the same built Gateway returned the exact requested control text in 4.55 seconds; the proxy verified/api/chat, HTTP 200, streaming, and the model identity. These numbers came from a one-off Gateway proof harness that is kept with the proof artifacts rather than committed; the committedtool-call-xml.streaming-parityandtool-call-xml.streaming-worktests guard the behavior.The first candidate reduced parser work only partially: built call-stack evidence exposed unused block snapshots and repeated raw directive transforms. The final change removes both bypasses. Isolated Codex branch review of the final head is scoped-clean with no actionable P0–P2 findings.
Active callback-driven block-delivery snapshots retain canonical reconciliation. This change does not claim bounded parsing for that separate delivery path.
Proof is local macOS arm64 / Node 26.12.1. Baseline and candidate builds are sequential, not ABAB; Gateway CPU includes instrumentation and background work, so deterministic parser counts are the primary evidence. Ambiguous/new XML or mutable Markdown deliberately falls back to the canonical transform; this does not claim a universal bound for repeatedly changing syntax.