Repository navigation
perf(plugins): compose async runtime scopes - #152602
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 19, 2026, 4:22 AM ET / 08:22 UTC (Revision 4). ClawSweeper reviewWhat this changesCombines plugin invocation, metadata, cache, and runtime context into one async frame, reducing scope-entry overhead while preserving independent cleanup. Merge readiness✅ Ready for maintainer review The optimization remains distinct from current main and the latest release. No actionable correctness or security findings remain in the reviewed head. Priority: P3 Review scores
Verification
How this fits togetherPrepared plugin generations supply metadata, caches, and registries to agent and plugin execution. Request-local scope carries those facts alongside Gateway caller context through asynchronous work. flowchart TD
A[Prepared plugin generation] --> C[Compose execution frame]
B[Gateway caller context] --> C
C --> D[One async scope]
D --> E[Plugin and agent execution]
E --> F[Independent scope cleanup]
F --> G[Restore enclosing context]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +92, Tests +63, Other +1. Total +156 across 16 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use one internal execution frame while retaining the existing scope readers, ownership checks, and independent cleanup contracts. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a performance refactor, not a defect report; source confirms the repeated scope entries and the body supplies before/after measurements. Is this the best way to solve the issue? Yes: composing the existing context owners removes redundant async entries without adding a competing cache, lifecycle owner, or public plugin API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ab0433dedc8d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
f9b66fe to
24e871a
Compare
24e871a to
7d79019
Compare
|
Merged via squash.
|
What Problem This Solves
Prepared plugin invocations repeatedly enter four nested async scopes to carry the same generation's registry, metadata, and cache.
User Impact
No user-visible behavior change. Plugin generation scope setup uses less CPU while preserving caller identity, generation selection, cache ownership, and independent cleanup. No configuration changes or migration are required.
Why This Change Was Made
Compose the generation's fields before entering the existing plugin invocation frame. Remove the three separate async stores while retaining each scope owner's readers, parent chains, and independent exit behavior.
The runtime frame keeps Gateway and registry types behind the existing typed frame boundary. Core scope updates copy through that owner, preserving runtime fields without introducing type-level import cycles. Scope contracts live in leaf type modules, the compaction harness's explicit metadata mock follows the new frame-builder API, and the trusted wrapper inventory includes the runtime frame module.
This remains a marginal microbenchmark win. The final correction adds 99 net production/tooling lines, primarily type contracts and typed frame copying; it introduces no new lifecycle or cache owner.
Evidence
Fresh local macOS measurements compare main at
90ab8619b3ec616db61c916dd850d5876d9f42c9with the final candidate using real metadata, cache, registry, and Gateway scope readers. The affected baseline scope modules are unchanged from the PR base. Each runtime/mode uses 10 warmup batches, followed by 31 alternating baseline/candidate sample pairs of 10,000 generation entries. Async mode awaitsPromise.resolve()inside each entry. Values are medians; CPU usesprocess.threadCpuUsage().Generation scope entries fall from 4 to 1. Measurements came from a shared host; no live Gateway profile or aggregate CPU reduction is claimed.
node scripts/check-changed.mjspassed, including formatting, production and test typechecks, targeted lint, dead-export scans, and runtime import-cycle checks.git diff --checkpassed.The local checks and review preceded the mechanical rebase onto
88a48ac42f4e6400bd3d06d7bdedf8de030c4696. Its only conflict resolution moved main's existingsignalandhasCurrentClientAuthoritydeclarations into the extracted scope type without changing them. Exact-head CI passed after the rebased push and wrapper inventory correction.The wrapper archive correction also passed a fresh P2 autoreview, the extracted dependency-context test, and four native provisioning checks. The corresponding main checks passed too; the Linux-only filesystem case is deferred to hosted CI on this macOS host.
The
observeandcompareDeletelifecycle-custody cases insrc/plugin-state/plugin-state-worker.test.tsfailed withStateDatabaseCoordinatorContentionErroron both CI and clean main at88a48ac42f4e6400bd3d06d7bdedf8de030c4696(2 failed, 10 passed). That baseline failure is outside this PR and remains unchanged. Exact-head CI passed for7d79019a5dcc7791dd9b20c3475bf4945ec21afd, includingopenclaw/ci-gate; the previously failing state-worker shard passed without state-code changes. The early security-review job only reported that CI was not yet complete; its current dependency and security-sensitive review statuses are successful.