Skip to content

fix: keep native resource startup responsive on slow filesystems - #200216

Merged
steipete merged 1 commit into
mainfrom
steipete/lane2535-broker-ready
Nov 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/lane2535-broker-ready

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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.

Median Before After
Constructor return 2.712 ms 2.465 ms
Broker ready 292.052 ms 291.072 ms
Complete owner operation 366.219 ms 362.789 ms
Main-thread CPU 9.899 ms 9.778 ms
Parent-process CPU 11.289 ms 14.340 ms
Main-isolate allocation 3.176 MB 3.079 MB
Whole process-tree CPU 1.49 s 1.51 s

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.

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.
@clawsweeper

clawsweeper Bot commented Nov 16, 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 November 16, 2026 18:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T18:49:07.758225Z eb65d27 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Move 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.

  • Before: The reported maximum main-thread heartbeat gap is 2,013.902 ms.
  • After: The reported heartbeat gap is 6.571 ms while the resource operation still completes and joins cleanup.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with production-boundary fault evidence, distinct lifecycle regressions, passing exact-head aggregate CI, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records real broker startup, resource attachment, and joined retirement on Node 26.12.1/APFS, including delayed actual directory creation and verification that creation moves from parent to child. This exercises the changed internal transport boundary; bundled-runtime, Windows, and btrfs qualification are expressly unclaimed. The inspected downloaded images show unrelated UI continuation behavior and were excluded.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Starting or retiring a native resource can pause unrelated Gateway requests when synchronous directory operations wait on a slow filesystem.
Reason: The repair addresses an owned blocking path with existing process infrastructure, and its maintainer-authored direction accepts the documented costs and recoverable orphan edge.

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
Reviewed head: eb65d27c33870e6e2a331beeb320acdc3e745bb3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9c93bc3 adds src/process/spawn-broker/host.ts:148 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9c93bc347cec; files: src/process/spawn-broker/host.ts)

PR surface

Source +13, Tests +75. Total +88 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 49 36 +13
Tests 2 78 3 +75
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 127 39 +88

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Slow filesystem metadata operations can stall concurrent Gateway work, with impact limited to native resource startup and retirement.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Slow filesystem metadata operations can stall concurrent Gateway work, with impact limited to native resource startup and retirement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 2:04 PM ET / 19:04 UTC.

@steipete
steipete merged commit 775be7a into main Nov 16, 2026
222 of 223 checks passed
@steipete
steipete deleted the steipete/lane2535-broker-ready branch November 16, 2026 19:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…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.
fuller-stack-dev added a commit that referenced this pull request Nov 17, 2026
…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.
RomneyDa added a commit that referenced this pull request Nov 18, 2026
…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]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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