Repository navigation
perf(ai): keep streaming responsive while large tool call arguments assemble - #128166
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 11:30 AM ET / 15:30 UTC. ClawSweeper reviewWhat this changesThis PR refreshes parsed previews of streamed tool-call arguments at geometric size checkpoints across AI transports, proxy streaming, and worker inference, while preserving exact terminal arguments. Merge readinessKeep open for maintainer review. The patch appears to repair the repeated full-buffer parsing path, but it intentionally makes interim parsed argument snapshots stale between checkpoints; the MEMBER-authored, Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherModel providers emit tool-call JSON in chunks. AI transports plus the proxy and worker adapters assemble those chunks for progress events, then validate the complete arguments before a tool call becomes executable. flowchart LR
A[Provider stream] --> B[Tool argument chunks]
B --> C[Transport or adapter accumulator]
C --> D[Geometric preview checkpoint]
D --> E[Interim stream events]
C --> F[Terminal argument validation]
F --> G[Executable tool call]
Decision needed
Why: The implementation changes observable preview timing across several stream surfaces; source proves final execution correctness but cannot establish every external consumer's compatibility expectation. Before merge
Agent review detailsSecurityNone. PR surfaceSource +164, Tests +300. Total +464 across 14 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep raw deltas and terminal parsing authoritative, and merge only once maintainers confirm that checkpointed parsed previews are compatible with the stream-consumer contract. Do we have a high-confidence way to reproduce the issue? Yes — source-reproducible: current main reparses the growing argument buffer for every streamed delta in the affected transport path. Is this the best way to solve the issue? Yes, subject to the preview-compatibility decision: one shared geometric schedule at the accumulators removes quadratic preview work while existing terminal validation preserves executable arguments. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c4e0c003a406. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…hedule Every input_json_delta re-parsed the entire accumulated argument buffer (quote scan, strict parse attempt, repair scan, partial parse), making assembly quadratic in argument size. A 128KB tool call spent ~1.2s of CPU on re-parsing alone while blocking token delivery; previews are preview-only by contract since the terminal parse re-reads the full buffer authoritatively at content_block_stop. Refresh previews on a geometric length checkpoint instead: bounded staleness, linear total work. Applied across every accumulating packages/ai transport/provider surface sharing the invariant. (hook bypassed per run-node-tool.sh contract: no local node_modules in this worktree and pnpm install is out of scope; oxfmt --check green on all staged files via sibling checkout binary.)
2fbc4b2 to
3579980
Compare
|
Land-ready verification on head
Known proof gap: no live external-provider run; this deterministic member-authored performance repair is covered by owner-boundary regressions, benchmark evidence, and exact-head CI. |
|
Merged via squash.
|
…ssemble (openclaw#128166) * perf(ai): refresh streamed tool-call argument previews on a length schedule Every input_json_delta re-parsed the entire accumulated argument buffer (quote scan, strict parse attempt, repair scan, partial parse), making assembly quadratic in argument size. A 128KB tool call spent ~1.2s of CPU on re-parsing alone while blocking token delivery; previews are preview-only by contract since the terminal parse re-reads the full buffer authoritatively at content_block_stop. Refresh previews on a geometric length checkpoint instead: bounded staleness, linear total work. Applied across every accumulating packages/ai transport/provider surface sharing the invariant. (hook bypassed per run-node-tool.sh contract: no local node_modules in this worktree and pnpm install is out of scope; oxfmt --check green on all staged files via sibling checkout binary.) * perf(agents): throttle proxied tool argument previews * fix(agents): preserve terminal-only proxy tool calls
What Problem This Solves
Fixes an issue where agents emitting large tool calls could stall streaming and consume excessive CPU while arguments were still arriving. Each argument delta re-parsed the complete accumulated JSON, making assembly cost grow quadratically.
Refs #113124, Closes #121770
Why This Change Was Made
Parsed mid-stream arguments are previews; terminal parsing remains authoritative. This change refreshes previews at geometric length checkpoints across the accumulating provider, transport, proxy, and worker paths, keeping total parse work linear while preserving exact completed arguments. Proxy calls that legitimately contain no argument deltas retain
{}attoolcall_end.The OpenAI Responses stream contracts were moved to a focused internal type module so the runtime implementation remains below the 700-line limit without suppressions. The Bedrock plugin has a similar per-delta pattern but requires a separate Plugin SDK boundary decision and is not changed here.
User Impact
Large tool calls continue streaming responsively instead of spending progressively more CPU on argument previews. Completed arguments remain exact, and terminal-only empty tool calls continue to work.
Evidence
Anthropic Messages benchmark:
stopReason: "error"; it passes after preserving{}fortoolcall_start → toolcall_endwith no deltas.OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs src/agents/runtime/proxy.test.ts src/worker/inference-stream.runtime.test.ts packages/ai/src/transports/anthropic-transport-stream.test.ts packages/ai/src/transports/openai-responses-stream-parity.test.ts packages/ai/src/transports/openai-responses-stream-terminal-recovery.test.ts— 190 tests passed across both shards.node scripts/check-changed.mjs— passed all selected format, typecheck, lint, max-lines, cycle, and architecture guards.pnpm build— passed with no ineffective dynamic-import warning..agents/skills/autoreview/scripts/autoreview --mode uncommitted— clean; no accepted or actionable findings.2fbc4b29398964af1e8992cf1634697d27b5aba3.max-linessuppression.