Skip to content

improve: reduce plugin invocation allocation overhead - #148080

Merged
steipete merged 1 commit into
mainfrom
codex/r21-plugin-scope-default
Sep 14, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/r21-plugin-scope-default

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin invocation scopes repeatedly construct the same stateless default callback, including when an inherited request callback immediately replaces it.

User Impact

No user-visible behavior changes. Request callbacks, registry selection, fresh mutable scopes, and plugin lifecycle checks retain their existing behavior.

Why This Change Was Made

The existing scope owner shares one private always-false callback across its three fallback sites. Inherited callbacks keep their exact identity.

Evidence

All 11 selected scope, invocation-isolation, and registry-adoption tests passed. Fresh independent P2 review found no actionable issues.

A four-process before/after/after/before comparison exercised the real wrapped plugin invocation path, with 100,000 calls per inherited/default mode after warmup. Both repetitions passed output, callback identity, sibling-scope isolation, and post-disposal checks. Mean sampled allocation fell 8.17% with an inherited callback and 10.18% with the default. The observation ran at an earlier author base with identical supplied owner/support bytes and fixed unrelated edits in both arms; the final 11 tests ran on this branch's base.

These are synthetic invocation-allocation results on a shared host, not whole-Gateway, retained-memory, RSS, or exact per-closure byte measurements. Every process group exited and temporary state was removed. No full local build was run; current-head hosted CI remains required before landing.

@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 14, 2026 08:03
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 4:17 AM ET / 08:17 UTC.

ClawSweeper review

What this changes

The PR reuses one private, stateless callback across three plugin invocation scope constructors to reduce temporary allocations.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a focused, behavior-preserving optimization that remains absent from current main. No actionable correctness or security findings were identified.

Priority: P3
Reviewed head: b4adc6c611feed4a466bede357ffa5f6b8918b7e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with preserved scope semantics and appropriately bounded performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer PR is exempt from the external-contributor proof gate, and this stateless callback reuse does not materially change authority. Its reported wrapped-invocation benchmark supports the narrow allocation claim, without proving whole-Gateway memory improvements.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer PR is exempt from the external-contributor proof gate, and this stateless callback reuse does not materially change authority. Its reported wrapped-invocation benchmark supports the narrow allocation claim, without proving whole-Gateway memory improvements.
Evidence reviewed 6 items Verified introduced change: The pinned merge-base-to-head diff only replaces three always-false closures with a private shared callback. Object creation, spread precedence, registry selection, and invocation handling remain unchanged.
Current-main necessity: Fetched main still constructs the three fallback closures at lines 249, 278, and 326; the proposed optimization remains distinct.
Latest-release comparison: The v2026.9.4 source also allocates separate fallback callbacks. REST source inspection succeeded after local release-object inspection failed.
Findings None None.
Security None None.

How this fits together

Plugin invocation scopes carry Gateway request context and plugin identity through asynchronous execution. Plugin wrappers create these scopes before invoking registered operations.

flowchart TD
  A[Plugin invocation] --> B[Read inherited request context]
  B --> C[Create fresh plugin scope]
  D[Shared default callback] --> C
  C --> E[Async execution frame]
  E --> F[Plugin operation]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2. Total +2 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 5 3 +2
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 5 3 +2

Review metrics

None.

Technical review

Best possible solution:

Keep the optimization inside the existing scope owner while preserving fresh mutable scopes and inherited callback identity.

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

Not applicable to a functional bug: source confirms repeated callback construction, while the reported allocation measurements were not independently rerun in this read-only review.

Is this the best way to solve the issue?

Yes. Sharing this stateless private callback removes repeated construction without changing public APIs, scope ownership, or lifecycle checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e27efbd2ed47.

Labels

Label changes:

  • add P3: This is a small internal allocation optimization with no intended user-visible behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer PR is exempt from the external-contributor proof gate, and this stateless callback reuse does not materially change authority. Its reported wrapped-invocation benchmark supports the narrow allocation claim, without proving whole-Gateway memory improvements.

Label justifications:

  • P3: This is a small internal allocation optimization with no intended user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer PR is exempt from the external-contributor proof gate, and this stateless callback reuse does not materially change authority. Its reported wrapped-invocation benchmark supports the narrow allocation claim, without proving whole-Gateway memory improvements.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff only replaces three always-false closures with a private shared callback. Object creation, spread precedence, registry selection, and invocation handling remain unchanged. (src/plugins/runtime/gateway-request-scope.ts:115, b4adc6c611fe)
  • Current-main necessity: Fetched main still constructs the three fallback closures at lines 249, 278, and 326; the proposed optimization remains distinct. (src/plugins/runtime/gateway-request-scope.ts:249, e27efbd2ed47)
  • Latest-release comparison: The v2026.9.4 source also allocates separate fallback callbacks. REST source inspection succeeded after local release-object inspection failed. (src/plugins/runtime/gateway-request-scope.ts:197, 3a9d69db306c)
  • Scope isolation and production entry point: PluginInstance.enter passes the selected registry and invocation into the scope owner. Existing scope tests cover inherited request facts, concurrent plugin identities, parent isolation, and module reloads; these tests were inspected, not executed. (src/plugins/runtime/gateway-request-scope.test.ts:147, b4adc6c611fe)
  • Reported allocation evidence: The supplied complete PR body reports four before/after processes exercising wrapped plugin calls, with 100,000 calls per mode, preserved output and isolation, and sampled allocation reductions of 8.17% and 10.18%. It explicitly limits these observations to a synthetic shared-host workload at an earlier base with matching owner/support bytes; 11 selected tests reportedly passed on the submitted base. (b4adc6c611fe)
  • Related merged work and routing: Main history includes shared-execution-frame work by Peter Steinberger. GitHub confirms refactor(gateway): reduce allocations during parallel sessions #146219 merged as b271d16; its scope-isolation contract is preserved here. Local parent-blob inspection was unavailable, so no exact-line introduction attribution is claimed. (src/plugins/runtime/gateway-request-scope.ts, b271d1631a96)

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.

@steipete
steipete merged commit a08cdc5 into main Sep 14, 2026
254 checks passed
@steipete
steipete deleted the codex/r21-plugin-scope-default branch September 14, 2026 09:27
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 14, 2026
* commit 'a08cdc50bc049074ed7ad2db9e18e0ed3f5415ec': (81 commits)
  perf: reuse stateless plugin scope defaults (#148080)
  fix(gateway): flush slow-consumer 1008 close frame before terminating socket (#147707)
  fix: keep model catalogs loading during other session updates (#147878)
  fix: show queued external chat messages and their source (#147848)
  refactor(chat): share math label configuration (#148073)
  perf(ui): trim eager debug overlay icon payload (#147954)
  improve(logbook): sample batch frame metadata in SQLite (#147999)
  fix(ui): dismiss suggested task cards without waiting (#148021)
  fix(maturity): cover governance, interoperability, fleet, and state (#143528)
  chore(ui): restore core lint and startup budget checks (#148010)
  fix: chat startup loads unnecessary session setup text (#147973)
  perf: speed up fresh cloud worker activation (#147945)
  fix: recover PR preparation after committed merge conflicts (#148063)
  test(plugins): isolate ClawHub Docker fixture identity (#148074)
  fix(release): acknowledge ClawHub risk on moving installs (#148041)
  fix: restore context reads for installed official Discord and Slack plugins (#143341)
  fix: identify source capsule filesystem failures (#147778)
  fix(linux): keep Quick Chat widgets bound to their Gateway (#146049)
  refactor(infra): consolidate update campaign reset ownership (#146555)
  refactor: simplify Gateway health response parsing (#147834)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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