Repository navigation
fix(plugins): avoid Gateway stalls during source preparation - #200320
Conversation
Move source/native capture root and staging-token custody into the existing broker resource owner. Preserve cache/recovery retention and loaded-addon custody across execution shutdown, ordinary Gateway restarts, and broker loss. The actual root boundary now performs zero main-thread metadata calls instead of 28; two-second create faults leave the Gateway event loop responsive. Cold/warm preparation and whole-process CPU costs are measured and disclosed in the PR. No schema, config, cache, or public protocol changes.
|
🦞👀 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 Summary: ✅ CompletedThis 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR moves plugin source and native capture-root creation and physical custody into the existing resource broker. Example: Plugin preparation encounters a two-second source-directory creation delay.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a concrete Gateway responsiveness problem, and the earlier findings remain resolved; no actionable defect was found in the final type-only repair, while exact-head CI is still pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherPlugin and catalog preparation turn installed source into captured artifacts; the broker now owns physical roots and staging tokens while existing host leases retain cache, recovery, and loaded-native custody. flowchart LR
A[Gateway preparation] --> B[Existing resource broker]
B --> C[Capture roots and tokens]
C --> D[Preparation workers]
D --> E[Host artifacts]
E --> F[Cache and recovery leases]
F --> B
Technical reviewBest possible solution: Complete the broker custody cutover while preserving existing admission, independent leases, restart behavior, and joined cleanup. Do we have a high-confidence way to reproduce the issue? Current-main source reaches synchronous capture-root allocation, and the supplied built-runtime fault results isolate the resulting event-loop stall; this read-only review executed no target code. Is this the best way to solve the issue? The existing broker is the appropriate physical owner because moving directory creation alone would leave staging-token operations and custody on main. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against af9d6236b33f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +685, Tests +400, Docs +14, Other +401. Total +1500 across 40 files. Added test files: 3. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)
Reviewed November 16, 2026, 9:00 PM ET / November 17, 2026, 02:00 UTC (Revision 3). |
Complete capture-root consumer migration, restore low-space setup containment through the existing source-acquisition classification, and keep physical commit typing distinct from asynchronous leases. Preserve actual cleanup and yielding proof, update wrapper and fixed factory inventories, and remove the redundant broker-port suppression.
|
Addressed all six items from review 6934080805 in head d82c6f1:
Production and affected test types, scoped lint/format, the 400-line test budget and independent Codex review pass. The PR body retains the unexplained extra Darwin-only provisioning timeout and identifies all performance numbers as prior-03b measurements. Exact-head CI is still required; no inherited-CI exception is claimed. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Head 274e2ab fixes the one remaining CI failure from run43995776480: the new shared type created a static import back-edge between admission state and the lease module. The unchanged contract now lives in an import-free type leaf, with direct type-only imports from all four consumers. No executable statement, physical operation, error policy, or guard allowance changed. The exact failed Madge guard reports zero cycles; core types, scoped type-aware lint, formatting and independent Codex review pass. All six findings addressed in the numbered response remain resolved. Your completed d82 review had zero open items; please check this final type-only delta. The body retains prior-revision measurement labels, adverse costs and the unexplained local Darwin timeout. New exact-head CI remains required, with no inherited-red exception. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…200374) * fix(plugins): keep reload recovery metadata off the Gateway thread Move the complete asynchronous recovery copy into the existing capture broker, including root creation, copy filtering, native link validation, and cleanup. Reuse one physical copy algorithm for the retained sync fork. Follow up on #198262 and Wes (@akmad)'s original #181491 recovery work. Preserve the independent native leases established by #200320. A synthetic two-second create delay reduces the median MAIN heartbeat gap from 2010 to 10 ms. Cold owner time rises 94.750 to 124.388 ms; that cost and the remaining synchronous fork/import contracts are recorded in the PR evidence. No configuration or schema changes. * fix(tooling): include recovery imports in the PR wrapper * test: prepare runtime build graph workers before test launch A cold full Vitest worker compilation took 76 seconds inside the first 60-second heartbeat build-graph test. Enroll this selection in the existing runner preparation owner; preserve graph selection, test limits and assertions. Direct and projects runner regressions fail before the correction and all 55 runner cases pass afterward. Changed checks retain only the previously attributed Slack/UI dead exports. * test: provide compiler artifacts for eager tooling admission Use the existing controlled compiler for the unrestricted tooling selection. The eight-case admission table reproduces the missing manifest before this fixture migration and passes after it; retain the compiler count, receipt and selection assertions. No production behavior or timeout changes.
…w#200320) * fix(plugins): avoid Gateway stalls during source preparation Move source/native capture root and staging-token custody into the existing broker resource owner. Preserve cache/recovery retention and loaded-addon custody across execution shutdown, ordinary Gateway restarts, and broker loss. The actual root boundary now performs zero main-thread metadata calls instead of 28; two-second create faults leave the Gateway event loop responsive. Cold/warm preparation and whole-process CPU costs are measured and disclosed in the PR. No schema, config, cache, or public protocol changes. * fix(plugins): preserve capture failure contracts across broker custody Complete capture-root consumer migration, restore low-space setup containment through the existing source-acquisition classification, and keep physical commit typing distinct from asynchronous leases. Preserve actual cleanup and yielding proof, update wrapper and fixed factory inventories, and remove the redundant broker-port suppression. * refactor(plugins): keep native capture contract in a type leaf
…penclaw#200374) * fix(plugins): keep reload recovery metadata off the Gateway thread Move the complete asynchronous recovery copy into the existing capture broker, including root creation, copy filtering, native link validation, and cleanup. Reuse one physical copy algorithm for the retained sync fork. Follow up on openclaw#198262 and Wes (@akmad)'s original openclaw#181491 recovery work. Preserve the independent native leases established by openclaw#200320. A synthetic two-second create delay reduces the median MAIN heartbeat gap from 2010 to 10 ms. Cold owner time rises 94.750 to 124.388 ms; that cost and the remaining synchronous fork/import contracts are recorded in the PR evidence. No configuration or schema changes. * fix(tooling): include recovery imports in the PR wrapper * test: prepare runtime build graph workers before test launch A cold full Vitest worker compilation took 76 seconds inside the first 60-second heartbeat build-graph test. Enroll this selection in the existing runner preparation owner; preserve graph selection, test limits and assertions. Direct and projects runner regressions fail before the correction and all 55 runner cases pass afterward. Changed checks retain only the previously attributed Slack/UI dead exports. * test: provide compiler artifacts for eager tooling admission Use the existing controlled compiler for the unrestricted tooling selection. The eight-case admission table reproduces the missing manifest before this fixture migration and passes after it; retain the compiler count, receipt and selection assertions. No production behavior or timeout changes.
…0216) Move private socket directory creation and cleanup to the existing broker process. Keep exclusive admission, private permissions, startup errors, and joined cleanup. Parent crash cleanup follows successful readiness. Accept the recoverable private directory orphan before readiness. (cherry picked from commit 775be7a) Release adaptation: retain the stable inline 103-byte socket path bound instead of importing the newer socket-directory helper. Reuse the saved real cold-resource regression with direct filesystem spies instead of introducing the later all-filesystem observation helper. Required companion: #200453 (22d5c87) will follow to preserve the parent-decided directory in broker bootstrap. #200320 source capture, #200370 host/readiness interface, #200567 retired request cleanup, and 4a9273a export correction are separate owners, not prerequisites for this stable private-directory lifetime. Co-authored-by: RomneyDa <[email protected]>
Backport #200320 to the stable preparation owner. Physical roots and tokens stay independent of execution-worker lifetimes; native commit joins publication settlement. Preserve source filters, native authority, and failure custody. (cherry picked from commit 907e17b) Co-authored-by: RomneyDa <[email protected]>
* fix(plugins): avoid Gateway stalls during source preparation Move source/native capture root and staging-token custody into the existing broker resource owner. Preserve cache/recovery retention and loaded-addon custody across execution shutdown, ordinary Gateway restarts, and broker loss. The actual root boundary now performs zero main-thread metadata calls instead of 28; two-second create faults leave the Gateway event loop responsive. Cold/warm preparation and whole-process CPU costs are measured and disclosed in the PR. No schema, config, cache, or public protocol changes. * fix(plugins): preserve capture failure contracts across broker custody Complete capture-root consumer migration, restore low-space setup containment through the existing source-acquisition classification, and keep physical commit typing distinct from asynchronous leases. Preserve actual cleanup and yielding proof, update wrapper and fixed factory inventories, and remove the redundant broker-port suppression. * refactor(plugins): keep native capture contract in a type leaf (cherry picked from commit 907e17b) Co-authored-by: RomneyDa <[email protected]> Release adaptation: #200320 is required by #200374 because the baseline async recovery path still performs root creation, filtering and link metadata synchronously on the Gateway. Retain the coherent existing broker-resource migration rather than invent a second worker owner.: (cherry picked from commit a7feea3b844d37918527cca29e9f9812b61b156a)
…200374) * fix(plugins): keep reload recovery metadata off the Gateway thread Move the complete asynchronous recovery copy into the existing capture broker, including root creation, copy filtering, native link validation, and cleanup. Reuse one physical copy algorithm for the retained sync fork. Follow up on #198262 and Wes (@akmad)'s original #181491 recovery work. Preserve the independent native leases established by #200320. A synthetic two-second create delay reduces the median MAIN heartbeat gap from 2010 to 10 ms. Cold owner time rises 94.750 to 124.388 ms; that cost and the remaining synchronous fork/import contracts are recorded in the PR evidence. No configuration or schema changes. * fix(tooling): include recovery imports in the PR wrapper * test: prepare runtime build graph workers before test launch A cold full Vitest worker compilation took 76 seconds inside the first 60-second heartbeat build-graph test. Enroll this selection in the existing runner preparation owner; preserve graph selection, test limits and assertions. Direct and projects runner regressions fail before the correction and all 55 runner cases pass afterward. Changed checks retain only the previously attributed Slack/UI dead exports. * test: provide compiler artifacts for eager tooling admission Use the existing controlled compiler for the unrestricted tooling selection. The eight-case admission table reproduces the missing manifest before this fixture migration and passes after it; retain the compiler count, receipt and selection assertions. No production behavior or timeout changes. (cherry picked from commit 5275f43) Co-authored-by: RomneyDa <[email protected]> Release adaptation: apply after #200320 native capture owner prerequisite; retain source recovery copy and regression contracts unchanged. Follow-up #200571 detaches the independent owner from retired caller context.: (cherry picked from commit b1d97f0a472874e12bbfb3a0e429f97f509d3710)
…#200983) (cherry picked from commit 929f2e7) Co-authored-by: RomneyDa <[email protected]> Release adaptation: required #200320 companion; safely abandon native factories that never dispatched and retain cleanup obligations after broker startup failure.: (cherry picked from commit f2af7017a4995544bfcdca0001076661681fa6c3)
* fix(workers): preserve missing-module startup errors Render non-Error diagnostic causes before forwarding native worker failures so loader host objects cannot replace the original error with DataCloneError. Keep primitive causes and structured Error metadata, and verify the real supervisor error and join path on stock Bun, the pinned fork, and Node. Removes the native error-forwarding dependency on oven-sh/bun#46711. * fix(workers): narrow serialized diagnostic scalars explicitly * test(workers): consolidate native failure regressions Reuse one shared and cyclic error graph, extend the downlevel value table, and cover missing worker entries inside the existing supervisor recovery flow before its healthy sibling control. Preserve the original cases while reducing test lines by two against the PR base; remove the now-unneeded allocation. (cherry picked from commit 058133d) Release adaptation: Only cloneable diagnostic normalization and encoder/lifecycle regressions. Later inherited-code fix 416b357 is independent, not prerequisite; supervisor timing and plugin startup rewrites excluded. Follow-up dispositions: d82e097 test(process): wait for broker failure before retained replacement (openclaw#202539); 416b357 fix: preserve the real reason a worker failed; 907e17b fix(plugins): avoid Gateway stalls during source preparation (openclaw#200320); adb660f fix: allow retrying refused native worker cleanup (openclaw#198240) Validation: Direct exported encoder/decoder: baseline fails 3 non-Error diagnostic cases; fixed passes 3; primitive and Error graph regression retained. Normal wrapper lifecycle proof pending compiled-worker setup. diff --check passes. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit cb68af332a1182ed21b39c10b53b1f6e3036461c) (cherry picked from commit 7a4af04d616ab677c58fa1f369b947bef45c382a)
What Problem This Solves
Fixes Gateway event-loop stalls when plugin preparation creates source/native capture directories and their physical staging tokens on a filesystem waiting for a transaction commit.
Related: #200136, #200193, #200216. The motivating Team incident (25c9790, 2026-11-16 05:02 PST) blocked the Gateway MAIN thread for 1.97 seconds in
openat2(O_CREAT)underscheduler:update.remote-model-catalog; the kernel waited inbtrfs_create → start_transaction → wait_current_trans. The catalog's redundant lock was removed separately. This change handles the remaining physical capture-root owner.User Impact
Plugin preparation can wait on filesystem creation while the Gateway event loop remains responsive. There is no configuration or schema change and no operator action required.
The tradeoff is explicit: measured cold owner time increases from 183.267 to 453.257 ms, warm owner time from 141.459 to 182.479 ms, and whole process-tree CPU from 1,050 to 1,310 ms. A separate loaded-addon profile on the preceding revision observed 127.828 MiB RSS in the retained broker (summed process RSS increased 120.922 MiB; shared pages and profiling overhead included). The final revision proves ordinary same-process restarts reuse that broker; it does not remeasure that RSS observation. These costs are accepted for removing filesystem-transaction stalls from the Gateway thread, not described as an overall speedup.
Why This Change Was Made
The existing broker resource owner now creates and retains the physical source/native roots and staging tokens. Preparation workers borrow paths; host cache and recovery leases retain the physical custody after execution ends. Loaded native code keeps its token until host exit. Ordinary Gateway restarts reuse the existing broker, and a fresh source replaces permanently failed or sealed authority without reopening old claims or inventing cleanup receipts.
This is the smallest complete root-custody cutover: moving only mkdir would leave token creation and lifetime operations on MAIN. Production grows by 685 lines across 21 production modules plus a net-zero build import adjustment. Twenty of those lines complete the shared lease type and preserve source-acquisition error classification across the new broker boundary. The growth is the private resource adapter and lifetime handoff; the old parent allocation callback and duplicate independent-resource count are removed. Existing pool/dependency declarations are moved intact to keep their owning modules within the repository's limits. No new manager, cache, database table or public protocol is introduced.
This does not claim all Gateway filesystem work is asynchronous. Recovery-copy/binding, runtime-selected synchronous JS/CJS/native imports, and the existing native-load realpath observation remain separate work.
Evidence
The real preparation boundary records 28 synchronous root operations on the exact parent, including seven mutations, and zero on the candidate. Actual two-second source/native
mkdtempSyncfaults move from the Gateway process into the broker: fault-interval heartbeat gaps are 2,029/2,010 ms before and 7/7 ms after; whole-operation candidate maxima are 14/12 ms. Existing physical custody and cleanup assertions remain active.The timing and injected-delay results below were measured on runtime source corresponding to
03b70d95e1d71ab021158898cbcc06eaea7568a1. Subsequent CI repairs preserve the create algorithm while correcting error projection, the shared lease type, and a broker sender binding, and removing an unnecessary await of a synchronous commit. These are prior-revision performance measurements, supported by focused regression proof of the changed paths, rather than a claim that final-head bytes were remeasured.Canonical built Node 26.12.1/APFS proof used a synthetic surrounding 35 GiB agent database, 5,000 sessions and 62,000 workspace files; this owner does not scan those unrelated files. No Team data was copied. Five A1/A2 controls and five A/B pairs each include cold and warm phases (20 processes); four additional processes exercise the actual source/native faults. All 24 processes, observed brokers and source/artifact verification joined successfully. No samples were discarded. Host one-minute load was 9.376–11.450; tails are retained rather than attributed to noise.
Main allocation excludes the broker, so it is not a global memory-saving claim. A/A cold owner medians were 186.086/184.935 ms, warm 147.092/145.145 ms, and tree CPU 1,060/1,050 ms.
Rerunnable workload: build each pinned checkout with
pnpm build sourcePerformance, then runnode --expose-gc scripts/perf/plugin-capture-custody-measure.mjs --repo <built-checkout> --fixture <synthetic-fixture> --label <arm>. Use--fault sourceor--fault nativewith--delay-ms 2000and candidate--expect-off-mainfor the injected faults. The driver and preload are included in this PR.Synthetic fixture setup and repeatable workload
Create the surrounding fixture once with the existing generator, outside the measured window:
Build baseline and candidate separately. Invoke the candidate's committed driver against each built
--repo, with unique labels and the same--fixture /absolute/new-fixture/physical. Run A1/A2/A/B five times serially, then A/B for each source/native fault. Wrap each process in/usr/bin/time -lfor the whole-tree CPU column. Preserve source/build hashes and every JSON row. The synthetic payload is 2 MiB; real addon loading and post-exit reclaim are separately proven by the focused lifecycle test.Focused proof covers the original main-thread guard, preparation cancellation/deadline/settlement, physical cache retention, real addon loading and reclaim exclusion, old-lease/successor overlap, ordinary same-process restart reuse, and actual broker-loss recovery. The sealed-only intermediate candidate failed the real process-loss regression; the final owner predicate passes all 17 lifecycle and 18 transport-retirement cases. A test-only watcher barrier timed out during validation; it now uses a bounded async sentinel wait under the unchanged deadline, and all four affected/cascading cases passed. Final affected types, lint, formatting and independent Codex reviews pass.
Before the CI-repair commit, full
pnpm check:changed --staged --base 2435c1faa791de766688ba27ca7a14a92e30b7e4passed every gate except dead exports: 113 identities match the exact parent, plus one task-owned benchmark export. The benchmark now uses an explicit shared installer; its targeted script-export scan, lint/format and all four baseline/candidate source/native fault qualifications pass. The 113 parent findings remain a failed local gate, not a green result or an automatic CI waiver. Exact-head CI and final-head zero-open ClawSweeper review are required before landing.The first exact-head CI run, 43987530227, found incomplete consumer migrations: a missing wrapper inventory entry, stale capture-root observations and low-space injection, an overbroad physical commit return type, an unregistered fixed protocol export, a new lint suppression, and test-line growth. The repair restores the existing contracts. The real broker low-space test also exposed lost source-acquisition classification before session creation; forwarding that existing fact restores startup containment while leaving transport and cleanup failures fatal. No failures from that CI run are claimed inherited. Repair head
d82c6f178d6b4cb1c09de4974664cd5140fb3f88passes focused regressions, production types and all affected test type graphs, type-aware lint, formatting, the export-owner guard, the 400-line test budget without allowance, and independent Codex review. Its CI run completed with only the static type-cycle failure described below; ClawSweeper cleared all six items on that head.Local provisioning covers 16 of the 17 Linux CI failures; the remaining filesystem case is platform-specific and remains CI proof. The selector also included a Darwin-only full cold/warm sibling case already known to have an unexplained timeout: it exceeded its 120-second deadline, reporting 202.398 seconds while synchronous subprocess work finished. That local failure is retained and is not classified inherited; its passing sibling cases are not a claimed fix. No full provisioning replay or blind CI rerun was performed.
CI run 43995776480 on
d82c6f1passed the previously failing checks but exposed one static type dependency cycle between admission state and the lease module. Head274e2ab300d4866700dec1891bf67dbe2e60568fmoves the unchanged contract into an import-free type leaf and updates all four consumers. The exact Madge guard now reports zero cycles; core types, type-aware lint, format and independent Codex review pass. This five-file change contains no executable behavior change and does not require remeasuring the prior performance results. Final-head CI and ClawSweeper re-review remain required; no inherited-failure exception is claimed.