Repository navigation
fix: resource broker startup fails when parent and child disagree on the socket directory - #200453
Conversation
…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.
|
🦞👀 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. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — suspected predecessor, not a causality claim: source commit 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +15, Tests +74. Total +89 across 7 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: No label 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 17, 2026, 1:40 AM ET / 06:40 UTC. |
|
Merged via squash.
|
…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: #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 insrc/cli/update-cli.windows-lifecycle.test.tson 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 exclusivemkdirof that path succeeded, andmkdir('.')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=nodeselects Node. Head is 38d4f9f onorigin/mainb9a72b5.mainmoved several times during the work; none of the movement touchedsrc/process/spawn-broker/.The reported failure, same command throughout
node scripts/run-vitest.mjs src/cli/update-cli.windows-lifecycle.test.tsorigin/mainbbf7f75, before #200411EEXIST ... mkdir '.'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
win32, the real authority returns no directory and the endpoint\\.\pipe\oc-br-<secret>. POSIXdirnameof that string is..createBrokerNativeResourceServerfrommain, run in a new empty working directory, fails with the samemkdir '.'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)mainsourceEEXISTonmkdirof the endpoint's parentRunning the head's tests against
main's five source files gives 3 failed, 7 passed of 10 acrossresource-transport.test.tsandresource-server.test.ts, on both runtimes. The third failure is the in-process server test, which shows the reportedmkdir '.'directly. On this head both files pass 10 of 10 on both runtimes.What each test proves:
EEXISTand the full directory listing.Suites and checks
Commands, counts, and two unrelated intermittent failures seen locally
Runs marked "same tree" used commit 04c6c8e49ca on
origin/main81d8cee. Its seven changed files are byte-identical to this head; the later base movement touched none of them.node scripts/run-vitest.mjs 'src/process/spawn-broker/', Bun (same tree)resource-transport.test.tsandresource-server.test.ts, this headsrc/cli/update-cli.windows-lifecycle.test.ts, Bun (same tree)pnpm tsgo:all, this headoxfmt --checkandnode scripts/run-oxlint.mjson the seven changed files (same tree)OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 node scripts/check-changed.mjs(same tree)check-test-lines-ratchet.mts --base origin/main --no-merge-base, this headcheck-session-identity-ratchet.mts --base origin/main --no-merge-base, this headtest/scripts/eager-import-closure.test.ts -t "PR wrapper inventory"(same tree)The skips are existing
skipIfconditions 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-secondspawnSyncbudget expires because the child'sfs.watchnever reports the marker its broker child wrote. Withmain's source it failed 2 of 4 isolated runs.proxy-retention.test.ts, "releases completed command proxies after the host closes":retained: 1instead of 0 after forced collection. Withmain'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-8ranresource-transport.test.ts(9 of 9) andresource-server.test.ts(1 of 1) on Linux under Bun. CI did not selectupdate-cli.windows-lifecycle.test.tsfor 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 theEEXISTand full-listing assertions; nothing it checked was dropped. In "keeps owner cleanup replies usable" anexpectinside 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 derivedmkdirhad somewhere to succeed; the test mocksnode:netand asserts nothing about directories, so no coverage is lost. Theprocess.connectedoverride is now restored throughonTestFinished, so a rejected startup cannot leak it.resource-transport.test.tskeep their existingskipIf(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.
string | undefinedfrom one named authority type. The fixture and callback fixes are the ones listed under the audit.host.ts. The bootstrap type is now defined as the authority plus a generation, so the spread sends exactly that type.host.tsfield keeps the equivalentReturnType<...>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
win32. By reading, the authority is unchanged there and the broker receives no directory, as before. No Windows run./tmpfallback for long temp roots has no dedicated test. The broker now receives that directory from the authority instead of deriving the same value.