Repository navigation
fix: keep native resource startup responsive on slow filesystems - #200216
Conversation
Move private socket directory creation and cleanup to the existing broker process. Keep exclusive admission, private permissions, startup errors, and joined cleanup. The parent retains async crash cleanup only after readiness proves ownership. The real cold resource regression rejects synchronous metadata mutations and writable opens. A two-second create delay reduces the measured heartbeat gap from 2014 ms to 6.6 ms. Accept the recoverable private directory orphan if the child is killed before readiness.
|
🦞👀 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 changesMove native resource socket directory creation and cleanup off the Gateway main thread into the existing broker process. Example: A native resource operation encounters a 2,000 ms filesystem delay during directory creation.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a concrete responsiveness problem still present on main, and review found no actionable introduced defects. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe spawn broker receives private bootstrap authority from the Gateway, creates an authenticated local resource socket, attaches native resource clients, and retains cleanup until resources and transports close. flowchart LR
A[Gateway operation] --> B[Spawn broker host]
B --> C[Existing broker process]
C --> D[Private socket directory]
E[Native resource client] --> C
C --> F[Native resource owner]
F --> G[Joined resource cleanup]
G --> D
Technical reviewBest possible solution: Use the existing broker to own physical directory startup and normal cleanup, retaining asynchronous parent cleanup after established readiness. Do we have a high-confidence way to reproduce the issue? Current-main source directly exposes synchronous directory mutations on the calling thread, and the PR records discriminating delayed-create results; no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete fix using existing owners: remove main-thread filesystem waits while preserving exclusive directory creation, private permissions, startup errors, and joined cleanup. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 869734209368. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +75. Total +88 across 5 files. Added test files: 0. 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 Reviewed November 16, 2026, 2:04 PM ET / 19:04 UTC. |
|
Merged via squash.
|
…nclaw#200216) Move private socket directory creation and cleanup to the existing broker process. Keep exclusive admission, private permissions, startup errors, and joined cleanup. The parent retains async crash cleanup only after readiness proves ownership. The real cold resource regression rejects synchronous metadata mutations and writable opens. A two-second create delay reduces the measured heartbeat gap from 2014 ms to 6.6 ms. Accept the recoverable private directory orphan if the child is killed before readiness.
…the socket directory (#200453) The parent's resource authority decides whether the native resource endpoint has a private socket directory. Since #200216 the broker child re-derived that from its own platform and the endpoint's parent path. A parent that selected a directory-less endpoint while the child ran on POSIX therefore got `mkdir '.'` and EEXIST before readiness. Tests that simulate Windows in the parent hit this on macOS and Linux until #200411 pinned their fixture's authority to the host platform. Forward the authority whole in the broker bootstrap. The broker creates, permissions, and removes exactly the directory it was given, or none, and derives nothing. Attachments still carry only the endpoint and secret.
…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]>
Forward the parent-decided private directory through broker bootstrap. The broker creates and removes exactly that directory, or none, without re-deriving authority from its platform or endpoint shape. Keep attachment payloads limited to endpoint and secret. (cherry picked from commit 22d5c87) Required companion to #200216. Retain stable inline socket-path bound and the bounded filesystem observation regression. Real broker tests cover directory-less startup, existing-owner safety, and selected-path cleanup. Co-authored-by: RomneyDa <[email protected]>
…the socket directory (openclaw#200453) The parent's resource authority decides whether the native resource endpoint has a private socket directory. Since openclaw#200216 the broker child re-derived that from its own platform and the endpoint's parent path. A parent that selected a directory-less endpoint while the child ran on POSIX therefore got `mkdir '.'` and EEXIST before readiness. Tests that simulate Windows in the parent hit this on macOS and Linux until openclaw#200411 pinned their fixture's authority to the host platform. Forward the authority whole in the broker bootstrap. The broker creates, permissions, and removes exactly the directory it was given, or none, and derives nothing. Attachments still carry only the endpoint and secret.
Related: #200136, #200193
What Problem This Solves
Fixes: starting a Gateway operation that needs a native resource worker can pause other requests while its private socket directory is created synchronously.
User Impact
The Gateway stays responsive while broker directory creation or cleanup waits on the filesystem. Existing resource admission, private directory permissions, readiness errors, and joined cleanup remain enforced. Windows continues using its named pipe and avoids allocating an unused directory.
A SIGKILL between child directory creation and readiness can leave a private temporary directory: the parent has not yet observed ownership and must not remove an unrelated existing path. This recoverable edge is accepted instead of adding another handshake.
Why This Change Was Made
The Team 25c9790 incident on 2026-11-16 at 05:02 PST showed a 1.97 s main-thread btrfs transaction wait during catalog lock creation, producing a 2,002 ms event-loop stall. #200136 removed that lock. This audit found synchronous directory creation and cleanup at the existing native resource broker boundary.
The parent now allocates only the random path and secret. The existing broker process owns exclusive directory creation, chmod, socket startup, and normal cleanup. The parent retains async crash cleanup after readiness has established ownership. Existing error settlement preserves startup failures and independent cleanup failures. No new service, worker, protocol, cache, schema, or configuration.
Production grows by 13 lines across three existing modules. The growth moves physical startup and cleanup to their process owner while preserving exclusive directory ownership and error reporting.
Evidence
The original real cold create/attach/close guard fails on one mkdtempSync, chmodSync, and rmSync each. Earlier affected startup/retirement/stderr proof passes 32 cases; the final lifecycle and permission replay passes eight cases, including actual resource attachment, completed removal, private mode under an inherited umask, and refusal to delete an existing unrelated directory. The shared filesystem guard also covers direct writable opens and synchronous metadata mutation APIs after #200193.
Canonical check:changed completed: structural gates, core types, and all 29 test type graphs passed. A task-owned cleanup lint finding was repaired; final scoped lint/type/format/diff checks pass. The known dead exports reproduce on exact base 6670297 and originate in #200056 / 24385a2; no full-command success or baseline waiver is claimed. Final isolated Codex review has no actionable P0–P2 findings. The final widened cold guard passes (one selected case), and affected test types, lint, format, and fresh final-source Codex review are clean. Production is byte-identical to the measured candidate; no timing rerun was needed.
Twenty serialized fresh Node 26.12.1 processes provide five interleaved A/A controls and five A/B pairs through the real broker readiness, native resource attachment, and joined retirement flow. Exact source hashes and the creation API/PID are checked. The synthetic fixture includes a 35 GiB database, 5,000 sessions, and 62,000 workspace files; this owner does not scan that unrelated data. No Team data was used. This is source-checkout startup on APFS, not bundled-runtime or btrfs timing.
A/A owner medians were 365.614 / 366.654 ms. Parent-process CPU rose 27%, or 3.051 ms, in A/B; its A/A medians varied by 19.5%. This bounded observed cost is accepted for moving the wait off main; it is not called noise. Allocation controls varied by 34.5%, so no allocation improvement or general speedup is claimed. Owner p95 was 369.342 → 379.789 ms.
Two separate qualified fault runs delay the actual directory create by 2,000 ms. Maximum heartbeat gap falls from 2,013.902 ms to 6.571 ms, while total operation time stays about 2.39 s in both arms. Each run asserts exactly one create in the expected process: baseline main, candidate child. The first histogram detector missed the initial blocked interval; its assertion failed and that attempt is retained. Only the two fault arms were rerun with a heartbeat armed before invocation; the 20 timing samples were preserved.
No changed module is imported by the Control UI. Local Windows proof is not claimed. Exact-head CI43932457792 succeeded on
eb65d27c33870e6e2a331beeb320acdc3e745bb3. Final-head ClawSweeper review6926208501 has zero open items and no actionable findings. Native preparation is complete.