Repository navigation
improve: reduce CPU work for long CLI reasoning streams - #152191
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: needs maintainer review before merge. Reviewed September 18, 2026, 6:11 PM ET / 22:11 UTC. ClawSweeper reviewWhat this changesThe PR reduces repeated parsing during long Claude CLI reasoning streams while preserving buffered text and callback delivery. Merge readiness✅ Ready for maintainer review Keep open: the optimization remains useful, is absent from fetched main and the latest release, and introduces no identified correctness defect. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s CLI output parser receives structured records from external CLI backends and separates reasoning from visible answers. The changed router buffers leading reasoning tags before forwarding the resulting text to agent callbacks. flowchart TD
A[Claude CLI records] --> B[JSONL parser]
B --> C[Leading reasoning buffer]
C --> D{Open block and no unfinished tag?}
D -->|Chunk has no opening bracket| C
D -->|Possible tag or finalization| E[Existing tag parser]
E --> F[Reasoning callbacks]
E --> G[Visible answer callbacks]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +10, Tests +12. Total +22 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the existing parser authoritative and bypass only scans whose pending result cannot change. Do we have a high-confidence way to reproduce the issue? Yes, from source: a long unclosed leading reasoning block makes current main scan the growing buffer on every text chunk. The PR supplies measured parser-boundary results; this review did not execute benchmarks. Is this the best way to solve the issue? Yes. The shortcut reuses an existing lexical fact without replacing parsing policy, changing callback boundaries, or adding configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 52e409a739b1. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…pr-149099-main-20260918 * commit '795e460278d4f8f41545dc8b4a66da1d12defd90': (1902 commits) refactor(slack): share Markdown preparation (#149129) fix(tooling): release completed PR operations with exited loaders (#152209) fix(release): allow stable npm bootstrap under an operator soak waiver (#152206) fix(daemon): avoid false restart timeouts during slow startup (#151387) feat: read agent documents from a host-owned workspace (#150584) improve(startup): skip redundant single-agent directory checks (#152192) test(ui): await board widget readiness before size reports (#152198) perf(browser): move dashboard event discovery to SQLite worker (#151952) improve(auth): reduce pauses during concurrent credential reads (#152140) improve(ui): load older chat history in smaller pages (#152093) fix(release): reject incomplete legacy npm install trees (#152186) refactor: share current-conversation binding row serialization (#152134) test(tooling): preserve Node and terminal fixture ownership under Bun (#152187) fix(sqlite): service worker admission through retained path aliases (#152190) improve: reduce CPU work for long CLI reasoning streams (#152191) chore(ui): refresh control ui locales (#152196) test(subagents): align lifecycle retries with durable completion owners (#152184) perf(gateway): defer participant maps for owned sessions (#152097) refactor(stream): share auxiliary queue overflow handling (#149282) fix(test): execute CLI fixture preloads on Node and Bun (#152076) ...
What Problem This Solves
Long Claude CLI reasoning streams spend increasing CPU time reparsing buffered text before the answer becomes visible.
User Impact
Long tagged reasoning streams require less parser work while preserving visible text, reasoning callbacks and their delivery boundaries. No configuration or transcript-format changes are required.
Why This Change Was Made
The existing lexical parser records whether reasoning is open with no unfinished tag. In that state, an appended chunk without
<cannot change the pending decision. The router retains every raw chunk and skips that redundant scan; chunks containing<and finalization still use the original parser. Partial tags, malformed recovery, Markdown code ownership, consecutive blocks, native-thinking deduplication and later literal tags retain their existing behavior.Evidence
a85fe70bed9a8e851c0e080b7d28ee1628576031. ClawSweeper also completed with no findings.createCliJsonlStreamingParserboundary with synthetic Claude JSONL records: 19 correctness cases and eight workload scenarios preserve complete callback payloads, per-push output/error/terminal state and final output against separate same-runtime baseline captures.The table shows median paired percentage changes, after taking each process's three-block median. Negative is faster. Sizes are UTF-16 code units; chunks contain 64 or 128 units.
All 36 pairs for the 16/64/256 Ki tagged streams improved both wall time and CPU. Median paired CPU savings per stream were approximately 278 microseconds, 1.51–6.83 milliseconds and 93.8–99.8 milliseconds, respectively.
Small and control cases are mixed: all six Node 24 plain-text CPU pairs regressed (median approximately 1.92 microseconds), and Node 26 multiline pair 3 regressed 30.26% wall/54.45% CPU. These results are retained, not retried or excluded. Mean process peak RSS fell 18.66 MiB on Node 24 and 41.68 MiB on Node 26, but those peaks include all scenarios and proof retention; they do not measure per-case heap or allocation savings.
This measures JSONL decoding, fresh parser construction, pushes, callbacks and finish/getOutput, excluding provider latency, process spawning and downstream delivery. Oracle work is outside the timed interval but can affect later GC. The result supports the long tagged-prefix path, not a universal, end-to-end, cold-start or statistical-significance claim. Production workload frequency was not measured.
Independent saved-data recomputation matched all 96 scenario pairs and 16 summaries, verified raw hashes/order/full parity/checksums, and recomputed baseline-only sizing. Retained audit SHA-256:
ef4f6f82612ae4b5f15ad4c5f3c514db5e4b376456e8bbf28b1b00bb365a7c94.