Skip to content

perf(plugins): reduce repeated stream payload inspection - #160208

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-plugin-sdk-boundary-per-stream-event-20260919
Sep 29, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-plugin-sdk-boundary-per-stream-event-20260919

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Nested plugin stream boundaries repeatedly walk the same event payload during a single value read, increasing allocation and garbage-collection pressure during streamed replies.

User Impact

Reduces stream-boundary allocation without changing the Plugin SDK, configuration, event identity, or lifecycle behavior. Arbitrary mutable payloads still require an initial classification, and iterator calls retain their scope and authority checks. Live Gateway impact has not been measured.

Why This Change Was Made

Carry a completed data classification through one synchronous chain of branded iterator-result readers. Discard it after that read and before executable fallbacks. Later reads reclassify mutations, and callable chunks still receive each consumer's lifecycle fence. No persistent object cache or new invalidation owner is introduced. Production growth is 24 net lines.

Register bench:plugins:stream as the benchmark's runnable package command so dependency analysis recognizes its real entrypoint.

Evidence

Synthetic provider fixture: 2,000 events (4,157-byte base payload plus a sequence field) and one 204,934-byte tool result, with zero or five additional managed forwarding layers. Five timing samples per scenario; V8 allocation sampling at 512 bytes, including collected objects. Run with pnpm bench:plugins:stream.

Refreshed comparison on Node v24.19.0, pinned main baseline b884d2a10f77 versus candidate af98c7c11a29, on Blacksmith Testbox lease tbx_01m3n4c1cs5x93c6md18n7kkzm (run):

Six boundary layers Before After
Sampled allocated bytes/event 422,332 191,694
Median ms/event 0.1586 0.0954

Allocation fell 54.6% and median time/event fell 39.9% in the refreshed comparison, consistent with the earlier 54–55% allocation reduction. The single-boundary control measured 0.02160 → 0.02228 ms/event and 65.2 → 65.5 KB/event. Timing varies between runs; this is a bounded improvement, not O(1) processing.

Previous unchanged-production proof: the regression failed on baseline with two payload walks instead of one, and verifies that methods added between reads receive the outer consumer's fence. SDK/embedded-runner coverage passed 7,525 tests in 654 files, with 13 existing skips. The changed test file passed 28 tests in 17.13 s wrapper wall (15.04 s Vitest, mostly cold transformation). The original proof and final measurement used Blacksmith Testbox leases tbx_01m3k6mb08pcy8xer43epf7d2x and tbx_01m3k8favfbew8b9ekbtpcm6g2 (run).

CI repair attribution

The interrupted integration of main was completed without changing the production optimization, regression, or benchmark bytes.

  • check-dependencies / job 109032564584: Knip reported scripts/bench-plugin-stream.ts as its sole unused file. Fixed by registering the package command; no ignore or budget exception was added.
  • check-source-contracts / job 109032562718: nine daemon CLI export collisions, reported before the successful SQLite schema check. Incorporated main's 385ac2893544 and f010fc0b5790 (fix(tooling): stop reporting lazy imports as duplicate exports #160558), which repair the forwarder/export scanner behavior. These paths are outside this PR's diff.
  • checks-node-changed-compact-small-40 / job 109032573990: the large piped JSON case in help-exit.process.test.ts timed out after 100000 ms. Main's 2ca9f7b710f7 applies the shared child-process/V8 policy. The original hang was not reproduced and its cause remains unresolved; this is not a claim that a passing replay proves a fix.
  • checks-ui-e2e (4/9) / job 109032562633: Markdown table landscape width was 350 instead of 892. This PR changes no UI files. The exact test passed in 4125 ms on main run 36486479600, SHA a46cde88785d, job 109144735009; all 11 tests in its file passed. No speculative UI change was made.

The same main run also passed source-contracts job 109144734974 and compact-small-40 job 109144738667.

Refreshed remote validation

Provider blacksmith-testbox, profile openclaw-check, lease tbx_01m3n4c1cs5x93c6md18n7kkzm. The native sync checkout has its own Git checkpoint; all four candidate file hashes were verified before execution. Missing dependencies were installed once with pnpm install --frozen-lockfile. No local suites, typechecks, or builds ran.

  • node scripts/run-vitest.mjs src/plugins/plugin-instance src/plugins/runtime/gateway-request-scope --reporter=dot: 75 tests in four files passed, 27.09 s wrapper wall.
  • node scripts/run-vitest.mjs src/plugins/plugin-instance-{iterables,constructors,callbacks,arguments,reflection,invocation,registry,error}.test.ts --reporter=dot: 259 tests in eight files passed, 12.58 s wrapper wall. Combined focused proof: 334 tests / 12 files.
  • node --expose-gc --import ./scripts/tsx.mjs scripts/bench-plugin-stream.ts: baseline and candidate both completed on the same lease; baseline used a detached temporary worktree, removed afterward. Results above.
  • node --import ./scripts/tsx.mjs scripts/check-export-name-collisions.mts: passed.
  • pnpm deadcode:unused-files: both production and full-tree scans passed with zero entries.
  • node scripts/check-changed.mjs --base b884d2a10f77d9fb53ee385abb959b525e7232ea -- package.json scripts/bench-plugin-stream.ts src/plugins/plugin-instance-iterables.test.ts src/plugins/plugin-instance-value-views.ts: conflict markers, line-cap, and max-lines checks passed; its embedded environment-count check failed because the existing budget is 476 while both baseline and candidate have exactly 477 names. An independent baseline/candidate comparison found no added or removed names. No budget exception was added.

The existing completed review at bc1081a956a7 has no actionable findings; the production, test, and benchmark bytes remain identical, so that review is retained for the mechanical integration. Fresh autoreview attempts did not produce a report: one exited with an engine failure and two stalled and were stopped. They are not counted as passing reviews.

Initial lease tbx_01m3n3sjte3zmdnnr7f70jmtmk was stopped after native full synchronization hit the five-minute completion watchdog; no validation ran there. The replacement synchronized successfully. No live Gateway was modified or profiled.

The 35 remaining leaf checks from the changed-check plan were then run serially on the same lease: 34 passed, including core types (68.62 s), all 26 core-test type groups (1287.84 s), script types (49.50 s), SDK surface/exports/boundaries, script lint, dead exports, and the remaining architecture guards. Broad pnpm lint:core failed on unchanged line-limit violations: src/gateway/worker-environments/node-launch-adapter.test.ts (1009/1000), src/gateway/talk/relay/session-create.ts (702/700), src/commands/doctor/shared/missing-configured-plugin-install.repair.ts (746/700), and src/config/config-env-vars.ts (798/700). The four files and .oxlintrc.json were verified identical to the pinned main baseline. No suppressions or baseline increases were added.

node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/plugins/plugin-instance-iterables.test.ts src/plugins/plugin-instance-value-views.ts passed with zero warnings/errors in 5.9 s. Final candidate hashes still matched. Both lane leases are stopped.

Final hosted CI

CI run 36501433313 completed successfully for af98c7c11a298810bff2b75cf7d9ded484f4d478, with no failed jobs. Source contracts, dependencies, all Node shards, UI shard 4/9, both core-lint jobs, baseline ratchets, Docker seed E2E, and openclaw/ci-gate passed. The earlier pinned-baseline failures remain documented above.

GitHub auto-merge completed at 2026-09-29 00:34 UTC as fd17d340ad9e69e4fcecd9c2be2931657eed29de.

Share data classification only within one synchronous iterator-result read. Preserve mutation rechecks and nested consumer admission while reducing repeated payload walks. Add an old-code-failing regression and a reproducible streaming allocation benchmark.
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Sep 28, 2026
@steipete
steipete marked this pull request as ready for review September 28, 2026 06:33
@steipete
steipete enabled auto-merge (squash) September 28, 2026 06:34
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 8:13 PM ET / September 29, 2026, 00:13 UTC (Revision 5).

ClawSweeper review

What this changes

The branch shares plain-data classification during one synchronous plugin stream result read and adds a regression test and runnable allocation benchmark.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still repeats payload classification across nested plugin stream readers. The branch has measured benefit and no identified blocking defect; the linked CI repairs address separate failures.

Priority: P2
Reviewed head: af98c7c11a298810bff2b75cf7d9ded484f4d478

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused production code, a baseline-failing regression, and measured production-boundary execution provide strong confidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): On a Node 24 Testbox, the runnable benchmark fed synthetic events through the changed production PluginInstance reader and reported improved six-layer allocation and timing after the fix. Focused tests cover mutation and consumer closure; live Gateway impact remains unmeasured. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): On a Node 24 Testbox, the runnable benchmark fed synthetic events through the changed production PluginInstance reader and reported improved six-layer allocation and timing after the fix. Focused tests cover mutation and consumer closure; live Gateway impact remains unmeasured. No stored-data contract changes.
Evidence reviewed 10 items Current-main behavior: Fetched main still calls plain-data classification on each projected result read and has no shared synchronous read fact.
Introduced optimization: The new per-read fact passes through branded nested readers; each reader still checks its active lease, and executable fallback clears the fact.
Regression coverage: The added test checks one payload traversal during a nested read, reclassification after mutation, and rejection of a callable after consumer release.
Findings None None.
Security None None.

How this fits together

OpenClaw wraps plugin-produced stream events before host consumers read them. The plugin instance classifies payloads and enforces the consuming plugin lease before returning data or scoped callable views.

flowchart LR
A[Plugin stream event] --> B[Plugin instance wrapper]
B --> C[Iterator result reader]
D[Consumer lease] --> C
C --> E{Plain data?}
E -->|Yes| F[Host receives payload]
E -->|No| G[Scoped plugin access]
G --> F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +24, Tests +37, Config +1, Other +95. Total +157 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 32 8 +24
Tests 1 37 0 +37
Docs 0 0 0 0
Config 1 1 0 +1
Generated 0 0 0 0
Other 1 95 0 +95
Total 4 165 8 +157

Review metrics

Metric Value Why it matters
Six-layer allocation 422,332 → 191,694 sampled bytes/event The reported same-environment comparison measures a 54.6% reduction on the nested stream path.
Runtime growth and proof runtime +24 net; regression +37; benchmark +95 The runtime growth stays in the existing reader and has focused correctness and performance evidence.

Technical review

Best possible solution:

Keep classification scoped to one synchronous result read while preserving fresh mutation checks and every consumer lease check.

Do we have a high-confidence way to reproduce the issue?

Yes. Current-main source shows repeated classification across projected nested result reads, and the PR supplies a baseline comparison; this read-only review did not execute the benchmark.

Is this the best way to solve the issue?

Yes. The change stays in the existing plugin instance reader, shares only a synchronous fact, and adds no persistent cache or public SDK surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3ea44e871e1a.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a measured plugin-stream efficiency improvement with limited user-facing blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): On a Node 24 Testbox, the runnable benchmark fed synthetic events through the changed production PluginInstance reader and reported improved six-layer allocation and timing after the fix. Focused tests cover mutation and consumer closure; live Gateway impact remains unmeasured. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. On a Node 24 Testbox, the runnable benchmark fed synthetic events through the changed production PluginInstance reader and reported improved six-layer allocation and timing after the fix. Focused tests cover mutation and consumer closure; live Gateway impact remains unmeasured. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-28T06:35:37.778Z sha 64405cf :: needs changes before merge. :: none
  • reviewed 2026-09-28T07:17:10.667Z sha 64405cf :: blocked before merge. :: none
  • reviewed 2026-09-28T08:40:20.654Z sha 8406e46 :: blocked before merge. :: none
  • reviewed 2026-09-28T16:52:58.137Z sha bc1081a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@steipete
steipete merged commit fd17d34 into main Sep 29, 2026
227 of 229 checks passed
@steipete
steipete deleted the steipete/perf-micro-plugin-sdk-boundary-per-stream-event-20260919 branch September 29, 2026 00:34
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…0208)

Share data classification only within one synchronous iterator-result read. Preserve mutation rechecks and nested consumer admission while reducing repeated payload walks. Add an old-code-failing regression and a reproducible streaming allocation benchmark.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant