Skip to content

fix: resource broker startup fails when parent and child disagree on the socket directory - #200453

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/spawn-broker-endpoint-directory
Nov 17, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/spawn-broker-endpoint-directory

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Related: #200216, #200411

What Problem This Solves

The native resource broker can fail to start with Spawn broker failed before readiness: EEXIST: file already exists, mkdir '.'. It happens when the parent process selects an endpoint with no private socket directory while the broker child runs on POSIX. Developers met it as 17 of 27 failures in src/cli/update-cli.windows-lifecycle.test.ts on macOS and Linux, each stopping before the test reached its subject.

The file passed 27 of 27 at the commit before #200216, which moved creation of the broker's private socket directory out of the parent and into the broker child.

While this PR was in progress, #200411 merged and turned those tests green by having the update lifecycle fixture create its authority under the host platform. The broker itself still fails the same way for any other caller that selects a directory-less endpoint; the new tests here reproduce that on current main.

User Impact

No user-visible change. Shipped installs are not affected: the parent starts the broker with its own runtime binary, so both processes see the same platform and already agree. The failure needs a parent and child that disagree, which today only happens in tests that simulate Windows in the parent while the real child runs on POSIX.

No data was at risk. I traced every path to a directory removal on main: each one runs only after the same broker's exclusive mkdir of that path succeeded, and mkdir('.') cannot succeed, so nothing reaches a removal of . or of any path the broker did not create itself.

Why This Change Was Made

Two processes each decided whether the endpoint has a private directory. The parent's resource authority decides from its platform: a named pipe and no directory on Windows, otherwise <private dir>/resource.sock. After #200216 the broker child decided again from its own platform and the endpoint's parent path. When they disagreed, the child took the parent path of a pipe name, got ., and tried to create it.

The authority owns that decision, so the fix forwards it. The parent sends the authority whole in the broker's bootstrap message, and the broker creates, permissions, and removes exactly the directory it was given, or none. It no longer reads its platform or the endpoint's shape. Resource attachments handed to workers still carry only the endpoint and secret.

What #200216 set out to do is kept: the parent does no synchronous filesystem work for this directory, creation is exclusive, the mode is 0700, and cleanup is joined on close and on startup failure.

The wire change is one field on the internal parent-to-broker bootstrap message, which both ends read from the same build. There is no schema, config, public protocol, or dependency change.

#200411's fixture line is left in place. It keeps the update lifecycle tests on a private socket directory; without it, and with this fix, a POSIX child would listen on a socket file named like the pipe in the working directory, as it did before #200216.

Evidence

Local runs are on macOS arm64. The local Vitest wrapper defaults to the Bun runtime; OPENCLAW_VITEST_RUNTIME=node selects Node. Head is 38d4f9f on origin/main b9a72b5. main moved several times during the work; none of the movement touched src/process/spawn-broker/.

The reported failure, same command throughout

node scripts/run-vitest.mjs src/cli/update-cli.windows-lifecycle.test.ts

Tree Result
7cb238a, the parent of #200216 27 passed
origin/main bbf7f75, before #200411 17 failed, 10 passed, all 17 with EEXIST ... mkdir '.'
this change on cc6c3a7, before #200411 27 passed on Bun, 27 passed on Node
this change on 81d8cee, which includes #200411 27 passed on Bun

Only the third row separates this change from #200411: it is this change alone turning the file green.

Root cause, and the alternative ruled out

  • With the parent's platform reported as win32, the real authority returns no directory and the endpoint \\.\pipe\oc-br-<secret>. POSIX dirname of that string is ..
  • A stale directory or the working directory's contents do not explain it. createBrokerNativeResourceServer from main, run in a new empty working directory, fails with the same mkdir '.' for the pipe endpoint and starts normally for a POSIX endpoint in that same directory. The first case in the test file also failed, with no earlier case to leave state behind.

Regression and guard tests through the real host and a real broker child (src/process/spawn-broker/resource-transport.test.ts)

Test main source This head
serves an endpoint the authority gave no directory without creating or removing one fails: EEXIST on mkdir of the endpoint's parent passes
removes only the authority's directory when its endpoint cannot listen fails: the child creates a different directory than the authority named passes
refuses an existing resource directory without removing its contents passes passes
creates and retires a cold native resource without main-thread synchronous metadata passes passes

Running the head's tests against main's five source files gives 3 failed, 7 passed of 10 across resource-transport.test.ts and resource-server.test.ts, on both runtimes. The third failure is the in-process server test, which shows the reported mkdir '.' directly. On this head both files pass 10 of 10 on both runtimes.

What each test proves:

  • No directory given. The first test pre-creates a directory with another owner's file in it and mode 0755, tells the host the endpoint has no directory, and attaches a real resource. While the broker is live the directory holds only that file and the socket. After close it holds only the file, with unchanged content and mode.
  • Startup failure, and nothing else removed. The second test names a directory and points the endpoint at that same path, so listening can only fail because the broker created it. Afterward the parent directory holds only the other owner's file. Two temporary mutations confirm the test bites: skipping the startup-failure removal leaves the directory behind and fails it, and not forwarding the directory lets startup succeed and fails it.
  • Exclusive creation. The third test is the existing one, now asserting EEXIST and the full directory listing.
  • Mode 0700 and removal on close. The fourth test is the existing one, unchanged: it checks the mode under a hostile umask and that the directory is gone after the host closes.

Suites and checks

Commands, counts, and two unrelated intermittent failures seen locally

Runs marked "same tree" used commit 04c6c8e49ca on origin/main 81d8cee. Its seven changed files are byte-identical to this head; the later base movement touched none of them.

Check Result
node scripts/run-vitest.mjs 'src/process/spawn-broker/', Bun (same tree) 116 passed, 94 skipped of 210; 22 files passed, 12 skipped
the same, Node (same tree) 187 passed, 23 skipped of 210; 33 files passed, 1 skipped
resource-transport.test.ts and resource-server.test.ts, this head 10 of 10 on Bun, 10 of 10 on Node
src/cli/update-cli.windows-lifecycle.test.ts, Bun (same tree) 27 passed
pnpm tsgo:all, this head exit 0
oxfmt --check and node scripts/run-oxlint.mjs on the seven changed files (same tree) clean
OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs (same tree) exit 0
check-test-lines-ratchet.mts --base origin/main --no-merge-base, this head OK, +74 of 400
check-session-identity-ratchet.mts --base origin/main --no-merge-base, this head OK
test/scripts/eager-import-closure.test.ts -t "PR wrapper inventory" (same tree) 1 passed, 22 filtered out

The skips are existing skipIf conditions in files this PR does not touch; the command-transport tests skip under Bun. The dead-export scan was skipped and not run.

Two timing-sensitive tests in that directory failed intermittently on this machine while other jobs loaded it. Neither uses native resources, and both fail the same way with main's five source files swapped in:

  • context.test.ts, "keeps Gateway child spawning in-process after timeout admission": the 30-second spawnSync budget expires because the child's fs.watch never reports the marker its broker child wrote. With main's source it failed 2 of 4 isolated runs.
  • proxy-retention.test.ts, "releases completed command proxies after the host closes": retained: 1 instead of 0 after forced collection. With main's source it failed 4 of 6 runs, and 5 of 6 on this change.

Both passed in the two full-directory runs in the table.

The broker test directory passes on both runtimes. Typecheck, format, lint, the changed-file gate, and both ratchets are clean. The dead-export scan was not run. Two timing-sensitive broker tests that do not use native resources failed intermittently on a loaded machine, as often with main's source as with this change; details are in the block above.

CI on 38d4f9f finished with 62 checks passed, 57 skipped, and none failed. checks-node-changed-8 ran resource-transport.test.ts (9 of 9) and resource-server.test.ts (1 of 1) on Linux under Bun. CI did not select update-cli.windows-lifecycle.test.ts for this diff, so that file's results above are local only.

Test files audited in full

  • resource-transport.test.ts: added the two tests above and one shared fixture for a pre-existing owner directory. The existing "refuses an existing resource directory" case moved onto that fixture and gained the EEXIST and full-listing assertions; nothing it checked was dropped. In "keeps owner cleanup replies usable" an expect inside a socket callback moved after close, so a wrong value fails the test instead of stalling the callback.
  • resource-server.test.ts: removed the temp-directory fixture and its two imports, restoring the synthetic endpoint the test had before fix: keep native resource startup responsive on slow filesystems #200216. That fixture existed only so the server's derived mkdir had somewhere to succeed; the test mocks node:net and asserts nothing about directories, so no coverage is lost. The process.connected override is now restored through onTestFinished, so a rejected startup cannot leak it.
  • All cases in resource-transport.test.ts keep their existing skipIf(win32); I did not change that.

Review

One independent read-only review by a fresh agent given the diff and the contract, with no access to my reasoning. It found no blocking issue and raised test and typing points.

  • Applied: the startup-failure test could not tell "created then removed" from "never created", so it was reshaped as above. The directory is now an explicit string | undefined from one named authority type. The fixture and callback fixes are the ones listed under the audit.
  • Not taken: listing the bootstrap fields one by one in host.ts. The bootstrap type is now defined as the authority plus a generation, so the spread sends exactly that type.
  • Partly taken: the named authority type is used by the protocol and the tests, while the host.ts field keeps the equivalent ReturnType<...> to stay clear of that file's 700-line cap.

The repository's autoreview helper does not work on this machine, so it was not run.

Not proven

  • Real Windows, where parent and child are both win32. By reading, the authority is unchanged there and the broker receives no directory, as before. No Windows run.
  • The /tmp fallback for long temp roots has no dedicated test. The broker now receives that directory from the authority instead of deriving the same value.
  • The parent's own removal after readiness when the broker died without cleaning up is not separately tested. The cold-resource test cannot tell the broker's removal from the parent's.
  • Linux was not run locally; CI covered the two touched test files there, under Bun only.

…the socket directory

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

clawsweeper Bot commented Nov 17, 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.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR forwards the parent’s socket-directory choice to the resource broker instead of having the child derive it again.

Example: A POSIX broker receives endpoint /tmp/oc-example/resource.sock with directory undefined and an existing parent directory.

  • Before: The child tries to create /tmp/oc-example and fails with EEXIST before readiness.
  • After: The child listens on the supplied endpoint and leaves the existing directory and its contents intact after shutdown.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and correct by source inspection, supported by detailed reported integration results rather than independently inspected execution artifacts.
Proof confidence 🦐 gold shrimp (3/6) This internal contract repair changes no supported shipped user flow; reported macOS Node and Bun integration runs exercise the changed host-to-real-child path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Developers using simulated platforms can encounter broker startup failures before their intended test behavior runs.
Reason: The maintainer-authored direction consolidates an existing decision without adding options, public contracts, or another lifecycle owner.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit 9c93bc347cec by Peter Steinberger; no PR verified.

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it removes a concrete duplicate startup decision while preserving directory ownership and cleanup guarantees; no actionable code defects were found.

Priority: P3
Reviewed head: 38d4f9f76fc19c09035ffbdc132be7c7ad19e503

Before merge

None.

Findings

None.

Agent review details

How this fits together

The spawn-broker host allocates native-resource connection details and bootstraps a separate process, which serves resource attachments and joins native cleanup.

flowchart TD
  A[Resource authority] --> B[Broker host]
  B --> C[Private bootstrap IPC]
  C --> D[Broker child]
  D --> E[Resource socket server]
  F[Resource worker] --> E
  E --> G[Native resource lifecycle]
Loading

Technical review

Best possible solution:

Keep directory selection in the existing resource authority and let the broker consume that decision for creation and cleanup.

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

Source establishes the directory-less endpoint failure, and the body reports base-failing, head-passing real-child regressions; independent execution was outside this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete ownership repair: forward the existing directory decision through bootstrap, remove its duplicate derivation, and retain distinct success and failure cleanup coverage.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Child-owned socket-directory creation and cleanup keeps the original intent (775be7a: Move slow filesystem operations off the parent while preserving exclusive ownership, permissions, and joined cleanup.)
  • Native-resource authority and private bootstrap keeps the original intent (9c93bc3: Retain native resource custody independently of disposable workers and preserve cleanup ownership.)
  • Server test directory fixture changes intended behavior with a stated reason (775be7a: Provide a creatable directory after startup began deriving one from the endpoint; explicit directory-less startup now removes that fixture requirement without removing lifecycle assertions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 775be7a adds src/process/spawn-broker/resource-authority.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 775be7a709fa; files: src/process/spawn-broker/resource-authority.ts)
  • Vincent Koc: Raw commit c97faa7 adds src/process/spawn-broker/resource-server.ts:438 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c97faa7ae259; files: src/process/spawn-broker/resource-server.ts)

PR surface

Source +15, Tests +74. Total +89 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 28 13 +15
Tests 2 97 23 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 125 36 +89

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:

No label changes.

Label justifications:

  • P3: This repairs an internal startup contract exposed by simulated platforms; shipped parent and child processes already use the same runtime and platform.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 17, 2026, 1:40 AM ET / 06:40 UTC.

@fuller-stack-dev
fuller-stack-dev merged commit 22d5c87 into openclaw:main Nov 17, 2026
138 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/spawn-broker-endpoint-directory branch November 17, 2026 06:53
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

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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