Repository navigation
perf(plugins): reuse bound model stream iterator methods - #183875
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
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. |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Model stream diagnostics repeatedly look up the provider iterator's
nextmethod for every streamed event, including plugin-bound iterators whose method is already prepared.User Impact
Streaming keeps the same events, result, diagnostics and plugin authority checks while allocating about 1.83% fewer bytes per model call in the measured owner workload. No configuration or public API changes.
Why This Change Was Made
Capture
nextonce, with its original receiver, in the existing iterator loop. Each call still enters the current transport context and invokes the original plugin-wrapped method; no invocation frame or live-authority check is removed. Iterator cancellation and final-result settlement are unchanged. Production LOC delta: zero.Evidence
Five alternating pairs on Node 26.12.1, using the real diagnostic wrapper and real
PluginInstancebindings around a synthetic provider. Each call produces 100 text deltas, a terminal event and EOF. The benchmark now exposes--plugin-boundand main-thread CPU measurement; usage is in its header.Allocation fell in every pair: −1.76%, −1.82%, −2.13%, −1.69%, −1.75% (paired mean −1.83%). Heap-sampling observations: 1,003,013 baseline and 984,550 candidate.
Timing is inconclusive. Four identical-source A/A controls produced main-thread CPU differences of +12.28%, +14.23%, −3.82%, −4.05%, and large GC/latency swings. No timing improvement or regression is claimed. Candidate GC rose only +0.006351 ms/call in absolute terms. This PR is justified by the consistent small allocation improvement and unchanged behavior, not timing percentages.
The count probe observed
nextproperty reads 102 → 1 per model call, with 102 iterator calls and one final-result call on both sides. Owner probes preserve exact event/result identity, diagnostic byte/usage/completion metrics, interleaved request identities, and exact plugin invocation frames across asynchronous work.The focused regression extends the existing frozen-stream test: one
nextproperty read, two actual calls including EOF, and the original receiver. Baseline must fail at the property-read assertion; fixed source must pass. Existing tests retain cancellation, error, result-first and transport-context coverage.Validation: direct real-owner regression probe failed on baseline (
2040 !== 20next-property reads) and passed on the fix (20 reads, 2,040 iterator calls, 20 identical results/completions). Formatting and changed-file core/scripts lint passed. Independent subagent review (autoreview route unavailable): no actionable P0–P2 findings. The only later edit renames the captured binding to avoid shadowing.Exact-head PR CI passed: run 40237037577, including the CI gate, lint, production/test types, guards, prompt snapshots, security and selected test shards. The embedded-run shard passed 91 tests across 5 files, including all 28 cases in
attempt.model-diagnostic-events.test.ts(the changed frozen-stream regression passed) and all 38 cases inattempt.model-diagnostic-lifecycle.test.ts. The shared run integration file passed 156 tests. The automated code review on this head also completed without findings.Local Vitest gap: attempted the single changed test file using both the default Bun route and the documented
OPENCLAW_VITEST_RUNTIME=noderoute. Both prepared their worker caches but stalled before assertions; both were stopped through their wrapper. These are setup/tooling failures, not product test failures or passing tests. PR CI subsequently ran and passed the committed regression. No full suite or full local typecheck was run. Measurements above compare the same production delta on baselinee0c6d5e91545fe3923d601ddb9ac1ac7922a1e4f; the affected owner remained unchanged when rebased. This is an owner benchmark, not a full Gateway/provider-network latency claim.Per-pair GC, event-loop tails and controls
GC kinds: 1 minor, 4 major, 8 incremental. Major tails below 50 samples and p99 below 1,000 samples are context only. All pauses are included.
Per-event follow-up (not included)
A separate long-stream profile used the real plugin binding, diagnostic run owner and session watchdog: 1,000,001 emitted events, 1,314 CPU samples. Exclusive samples were 24.89% in
AsyncContextFrame, 7.76% in the plugin binding callback, 6.70% inobserve, and 6.24% in response observation. Capturing the complete async context once would risk restoring stale plugin authority, so this PR preserves per-invocation frames and transport context.A scratch timestamp-handoff candidate removed one clock read per event while preserving tested event/result identity, bytes, usage, watchdog callbacks and frames. It is not included because its wall-time result exceeded the A/A wall variation:
Five alternating pairs plus one predeclared extra mixed-sign pair are all retained. Allocation improved in all five pairs (paired mean −0.844%); CPU is inconclusive. Signed mean wall delta is +0.499541 ms/call (+31.21% of mean baseline), versus four A/A pairs averaging −0.063393 ms/call, with individual A/A wall deltas −14.37%, −0.10%, −1.61%, +5.39%. GC's +0.126070 ms/call absolute rise is below the +1 ms/op materiality floor and is not the rejection reason. The largest concerning pause pair was 12.787 → 200.398 ms; all pauses were retained. These separate workloads must not be compared as if they measured the same event count.
After deploy, look for a small reduction in allocation normalized by streamed-event count, with stable response bytes, completions, cancellation/error behavior and plugin authority. No production latency improvement is established. The published benchmark's plugin-bound count smoke passed 20 calls, 2,040 iterator calls and 20 completions with all identity and diagnostic assertions.