Repository navigation
fix(plugins): reduce long garbage collection pauses during streaming - #159103
Conversation
Reduce ephemeron marking during streamed replies by keeping host view, native continuation, original-value, and iterator-reader metadata on the objects themselves. Preserve foreign associations, source caches, receiver binding, lazy getters, and exact instance and consumer admission.
|
🦞👀 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 26, 2026, 8:07 PM ET / September 27, 2026, 00:07 UTC (Revision 5). ClawSweeper reviewWhat this changesThe branch moves ownership metadata for host-created plugin views and native Promise continuations onto those values, updates the PR wrapper inventory, and adds callback and reflection tests. Merge readiness✅ Ready for maintainer review Keep open: current main retains the baseline ownership implementation, while the branch has measured pause reductions and no actionable introduced defect was found. The earlier PR-wrapper provisioning failure is repaired in this head. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway runs plugin-provided functions while handling agent requests and streamed replies. Plugin instance ownership determines which callbacks and result views may execute or be read before reply chunks reach clients. flowchart LR
A[Gateway clients] --> B[Streamed request]
B --> C[Plugin runtime]
C --> D[Owned value views]
D --> E{Live instance and lease?}
E -->|Yes| F[Reply chunks]
E -->|No| G[Closed call error]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +190, Tests +79, Other +1. Total +270 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one plugin instance owner for host-created and foreign values while preserving exact-instance restoration, live stream leases, and rejection of retired calls. Do we have a high-confidence way to reproduce the issue? Yes. Two reported baseline Gateway runs with 100 protocol clients and 50 active sessions produced 1,062–1,089 ms major-GC pauses, and current main retains the measured ownership implementation. Is this the best way to solve the issue? Yes. The change targets the measured weak-registration cost within the existing plugin owner without adding a public API, setting, or stored-data format. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2871aef000cb. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Pass the exact owner type from the existing process singleton instead of importing the scope contract back into the storage implementation. Keep the private brand within the once-created store so SDK and native callers retain one ownership identity without a static import cycle.
|
CI note: |
|
Correction to the earlier unrelated-failure diagnosis: the provisioning failure is caused by this PR. Both CI attempts failed because Pushed fix Proof:
Recorded local limitation: the separate macOS six-sibling APFS clone case exceeded its unchanged 120-second budget on both main (160.245 s) and the fixed PR (122.701 s) while the host was heavily loaded. This is distinct from the Linux CI module-resolution defect. No timeout, assertion, retry policy, or baseline was changed; no passing replay is claimed to repair it. Fresh-CI follow-up: run 36269968134 on the repaired head failed in job 108482661417, Bounded comparison: |
The projection fixture launched collectors with Promise.all but assumed input order was admission order and Collector A had occupied capacity before B's creation event. Asynchronous requester lookup can reverse admission, while preparation before a full slot correctly projects as running rather than queued. Create the fixture's collectors sequentially and join dispatch with an explicit completion signal. Preserve the exact list, history, lifecycle, rename, and cancellation assertions. Extend the existing rename regression to reverse overlapping requester reads; it fails on the original fixture with the CI wrong-run-ID assertion. Controlled preparation also reproduced the original creation-event status failure. Production behavior is unchanged. Validation: all 34 tests in the file, 563 sibling session-utils/Gateway tests, changed checks with no touched-file lint/type warnings, and independent review through P2 passed. One-worker full-file wall time was 143.66s on the loaded local host. Repeated file and original CI shard verification continues before publication. Addresses unrelated CI failures observed in #159103 and #158587.
Register the intentional suppressions added by #159103 (plugin ownership garbage-collection repair): - src/plugins/plugin-instance-owned-values.ts|eslint/no-constructor-return|1 - src/plugins/plugin-instance-owned-values.ts|typescript/no-extraneous-class|1 - src/plugins/plugin-return-value.ts|typescript/unbound-method|1 The production comments explain private-field stamping and preserving the original then receiver. Update only the explicit allowlist to repair the 80-versus-77 CI mismatch. Validation: node scripts/run-vitest.mjs run test/scripts/lint-suppressions.test.ts --maxWorkers=1 (1 file, 3 tests passed).
Record the three intentional private-field stamping and Promise receiver suppressions introduced by the plugin GC fix in #159103. The exact inventory expansion is approved; runtime code and lint directives stay unchanged.
Register the intentional suppressions added by #159103 (plugin ownership garbage-collection repair): - src/plugins/plugin-instance-owned-values.ts|eslint/no-constructor-return|1 - src/plugins/plugin-instance-owned-values.ts|typescript/no-extraneous-class|1 - src/plugins/plugin-return-value.ts|typescript/unbound-method|1 The production comments explain private-field stamping and preserving the original then receiver. Update only the explicit allowlist to repair the 80-versus-77 CI mismatch. Validation: node scripts/run-vitest.mjs run test/scripts/lint-suppressions.test.ts --maxWorkers=1 (1 file, 3 tests passed).
The projection fixture launched collectors with Promise.all but assumed input order was admission order and Collector A had occupied capacity before B's creation event. Asynchronous requester lookup can reverse admission, while preparation before a full slot correctly projects as running rather than queued. Create the fixture's collectors sequentially and join dispatch with an explicit completion signal. Preserve the exact list, history, lifecycle, rename, and cancellation assertions. Extend the existing rename regression to reverse overlapping requester reads; it fails on the original fixture with the CI wrong-run-ID assertion. Controlled preparation also reproduced the original creation-event status failure. Production behavior is unchanged. Validation: all 34 tests in the file, 563 sibling session-utils/Gateway tests, changed checks with no touched-file lint/type warnings, and independent review through P2 passed. One-worker full-file wall time was 143.66s on the loaded local host. Repeated file and original CI shard verification continues before publication. Addresses unrelated CI failures observed in openclaw#159103 and openclaw#158587.
…penclaw#159103) * perf(plugins): carry host value ownership in private fields Reduce ephemeron marking during streamed replies by keeping host view, native continuation, original-value, and iterator-reader metadata on the objects themselves. Preserve foreign associations, source caches, receiver binding, lazy getters, and exact instance and consumer admission. * fix(plugins): make value ownership storage a typed leaf Pass the exact owner type from the existing process singleton instead of importing the scope contract back into the storage implementation. Keep the private brand within the once-created store so SDK and native callers retain one ownership identity without a static import cycle. * fix(tooling): include plugin ownership in PR wrapper sources
Register the intentional suppressions added by openclaw#159103 (plugin ownership garbage-collection repair): - src/plugins/plugin-instance-owned-values.ts|eslint/no-constructor-return|1 - src/plugins/plugin-instance-owned-values.ts|typescript/no-extraneous-class|1 - src/plugins/plugin-return-value.ts|typescript/unbound-method|1 The production comments explain private-field stamping and preserving the original then receiver. Update only the explicit allowlist to repair the 80-versus-77 CI mismatch. Validation: node scripts/run-vitest.mjs run test/scripts/lint-suppressions.test.ts --maxWorkers=1 (1 file, 3 tests passed).
What Problem This Solves
Streamed Gateway replies can pause for about a second during major garbage collection at 100 connected clients / 50 active sessions. Host value views, reverse lookup tables, iterator envelopes, and Promise continuations create millions of weak ownership registrations and expensive ephemeron marking.
User Impact
In two interleaved same-box pairs, maximum major-GC pauses fell from 1,062–1,089 ms to 283–338 ms. Median maximum event-loop delay fell 1,256 → 415 ms. No configuration, protocol, persisted state, or admission policy changes are required.
This is a pause reduction, not a throughput claim: median main-thread CPU per completed load-window reply was 291.13 → 294.07 ms (+1.01%). Significant shorter pauses remain.
Why This Change Was Made
Keep metadata for known host-created views and native Promise continuations in native private fields on those objects. Private-field stamping preserves prototypes and reflected keys and does not expose a symbol to foreign Proxy traps. Original restoration still checks its creating instance; reader and callback shortcuts still check their exact factory; iterator getters remain lazy and retain their live lease checks. Custom
then/species results retain the foreign ownership path.Forward/source caches deliberately remain: they preserve cached method identity, fixed shadow descriptors, constructor receivers, and active iterator state. Those caches can still contain host-created keys. Weak-value replacement can discard a containing view while a caller retains its method or fixed property, changing observable identity and ownership. This patch does not relax that contract to reach zero registrations.
Evidence
Linux, 4 vCPUs / 15.42 GiB, Node 26.9.0, pnpm 12.4.2. One replacement Blacksmith Testbox for both builds and every comparison: run 36260759907, lease
tbx_01m3fdqxts55rnyq4hdp86bhn6, now stopped. Fresh isolated Gateway state per run; 100 protocol clients / 50 active, 120 seconds, seed 1, mock provider paced at 40 word chunks/s. Identical GC/ELD preload and--trace-gc-nvp; no ownership census or CPU profiler in the clean pairs. Order: A1, B1, A2, B2.All 1,638/1,638 clean comparison turns completed: zero errors, disconnects, failed or pending turns. All isolated state was removed. Median run-level major maximum/total fell 71.16% / 73.20%; ephemeron marking/linear totals fell 77.67% / 80.49%, reported separately. Two pairs characterize this synthetic workload, not other hosts, providers, browsers, or long-running capacity.
Separate same-box registration censuses completed 426/426 and 454/454 turns. Weak-table writes fell 44.689 → 5.272 per provider chunk (-88.20%), or 11,619 → 1,371 per completed turn. Global ownership-map writes fell 1,929,411 → 132. Original-value, member-reader, and iterator-envelope maps disappear. Ten-second weak sampling estimates simultaneous extant-entry peaks of 1,015,668 → 155,472; these include uncollected garbage, have sampling uncertainty, and are not strong-retention counts. About 84% of remaining source-cache registrations were sampled as host-created; they are intentionally retained as described above.
Validation: 556 focused/isolation/authority tests across 17 files passed in 79.95 s. Final changed-file runs: callbacks 130 tests, 17.49 s wall; reflection 37 tests, 4.37 s wall. Full builds passed: baseline 10m03.51s, candidate 9m36.19s. Production and all 25 test type graphs passed; lint fixes were followed by focused type/test/lint replays and completion of the remaining selected guards. The baseline's unrelated max-lines failure was already fixed by #159039; its test-only repair was applied only for that guard run and removed before performance builds. No baseline files or lint rules were changed. Narrow inline exceptions explain the intentional private-field stamping, captured receiver binding, and custom-then fixture.
OpenAI entrypoint import screening completed on both variants (~120 MiB RSS, ~245 ms CPU). The candidate profiler marked its source identity unqualified because the comparison checkout carried a patch; separate full-file hashes match the measured commit
f7751d16b571. No qualified startup-performance improvement is claimed.Diff-scoped deslop completed. Independent Codex branch autoreview through P2: scoped-clean, no actionable findings. Production +256/-66 (net +190); tests +79/-0; total +335/-66 (net +269). No changelog changes. CI per-file timing remains pending.
The first provider job was cancelled during a build, before any clean A/B ran. Both revisions were rebuilt and all headline runs executed together on the replacement; no incomplete comparison was reused.
Architecture CI follow-up
Commit
18b9777d934a92651b1af2cb7857dc2d0cdd657dremoves the static ownership-store ↔ scope dependency. The store now receives its precise owner type at the existing singleton creation site; its private brand is created inside that once-called factory. The singleton key, shared store, private metadata layout, and per-value operations are unchanged. No type casts, copied handle interface, cycle suppression, or new singleton were added.The original Madge cycle reproduced before the repair. Both
pnpm check:import-cyclesandpnpm check:madge-import-cyclespass afterward (37.01 s combined); the latter is not covered by check-changed. The same 556 focused/isolation/authority tests pass (90.46 s runner time), along with production typecheck, lint, and a full build (9m37.35s), on Blacksmith Testboxtbx_01m3fhscb15ererb95ewedw4gd, now stopped (validation run). Deslop and independent P2 autoreview are clean. The type-erased brand implementation and ownership-operation bodies match the measured version; the swarm figures above remain measurements off7751d16b571, not a new benchmark run.Auto-merge remains armed as requested. The exact-head watcher stopped on a new failure in extensions bundle 34:
extensions/whatsapp/src/monitor-inbox.delivery-and-dedupe.test.ts:432, “delivery coordinator drains admitted same-lane turns before close completes,” expectedsecondfollowed by a newline andthird, but received onlysecond. That shard reported 145 passed / 1 failed. Fail-fast cancelled the remaining jobs, includingcheck-additional-runtime-topology-architecture; a hosted architecture pass is therefore still unconfirmed. The new failure was recorded without a retry or further source changes, at the requested stop condition. Auto-merge remains armed.