Skip to content

fix: native worker supervisor crashes when a resource attachment endpoint is rejected - #180773

Merged
steipete merged 6 commits into
openclaw:mainfrom
anmol0b:fix/native-worker-attach-failure
Oct 23, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
anmol0b:fix/native-worker-attach-failure

Conversation

@anmol0b

@anmol0b anmol0b commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #180581

What Problem This Solves

Fixes the shared native worker supervisor crashing when a resource attachment endpoint is rejected synchronously, taking down unrelated workers without delivering a failure to the requester.

User Impact

The affected child reports its error and joins while the supervisor remains available for other workers. Resource cleanup uncertainty remains with its existing owner. Normal production endpoints are socket paths or named pipes; no supported configuration is known to produce the malformed endpoint used by this regression. No configuration, schema, protocol, or migration changes are required.

Why This Change Was Made

attachBrokerNativeResource() called net.connect() synchronously without containing an exception. The supervisor's close-and-rethrow catch then let the exception escape its message listener before child exit handlers were installed. The attachment client now delivers this failure through its existing failure/termination path in a microtask, after the caller installs the attachment owner and child listeners. Initial connection and startup retry use the same owner; the superseded supervisor catch is removed.

The child already exists, so create-error would incorrectly release parent custody as though construction had failed. The preserved sequence is created, error, execution-exit, then stop-error when resource cleanup cannot be confirmed. A later worker can still create, exchange a message, and stop normally.

The maintainer rewrite retains Anmol Bhardwaj's (@anmol0b) production fix and original commit. It repairs the regression's runtime-specific error-text assertion by checking RangeError and the rejected value 70000, which both supported runtimes preserve, handles supervisor errors as test failures, removes per-wait timers, and asserts the ordered join/cleanup outcome. The single regression still exercises the real supervisor over its private port, with an actual child and task port.

Production delta against merged main is +22/-18 (net +4); tests +124/-1 (net +123); docs +0/-0. The small production growth is the narrow typed catch after deleting the old rethrow wrapper; unrelated code was not removed to meet a line-count target. No additional lifecycle state, restrictions, or compatibility path was added.

Evidence

  • Source confirmation on main: src/process/spawn-broker/resource-client.ts:116 calls connect(attachment.endpoint) without a catch. The supervisor rethrows its attachment error through the private message listener. This remains present on merged main bfe2ff250e986a305004631f7654baaf7fa61ee3.
  • Regression: keeps the supervisor alive when a resource attachment endpoint is rejected synchronously sends endpoint 70000 to the real supervisor. On the unfixed base, connect() throws ERR_SOCKET_BAD_PORT, the supervisor errors/exits, and the event wait rejects before any successful sibling round trip. With the fix, the test requires child join, retained cleanup uncertainty, and subsequent sibling creation/message/stop. No per-wait timers, sleeps, or polling.
  • Prior contributor evidence: the original production-supervisor fault-injection trace on Node 24.22.1 showed the supervisor exiting with no replies before the fix, then created → error → execution-exit → stop-error and a successful sibling round trip afterward. The contributor supplied this trace; the maintainer did not rerun it locally.
  • Prior exact-head CI: run 39813158562 passed on 14ec3d9a77bfaf0ccd6cfddf7db34ed57c050a5f, including lint, types, and the Bun lifecycle suite (9 tests; regression 135 ms; file 17.34 s, including the pre-existing 15.5 s late-attachment test). This is prior-head evidence, not proof of the rewritten head.
  • Review: simplification pass retained one connection-failure owner and one regression. Initial Codex autoreview found the Node error-text mismatch; the maintainer repair addresses it. Final Codex autoreview is scoped-clean through P2 on the repaired diff. The final main merge changed only unrelated files; the reviewed patch is unchanged. Exact pushed head: 86c162214fdf0ffd76daac70c593819491f4634c; CI run 39907219078 passed all 22 selected jobs, including lint, format, production types, test types, baseline checks, and changed tests. The lifecycle suite passed 9/9 under Bun; the new regression took 33 ms, the file 16.41 s, and its shard 17.92 s.
  • Local limits: the single dependency install attempt on verified trusted main was refused: this Mac has Node 26.12.0, while main requires Node >=24.22.1 <25 or >=26.12.1. Local tests, lint, format, and typechecks were skipped per maintainer policy; PR CI owns those checks. No contributor code was executed locally, no engine check was bypassed, and no alternate runtime was downloaded. git diff --check passed.
  • Live e2e was skipped per maintainer policy. No live Gateway/channel tests or remote test leases were run. Local baseline replay and new wall-time measurements are unavailable under the same host/source-trust restrictions.

The original head also has a failed openclaw/ci-gate status from Security Review run 39816532173, despite successful CI and successful dependency/security-sensitive statuses. Its publisher reported that CI had not passed; this was not a security code finding. The final rewritten head has successful CI and gate results; the earlier failed status is superseded.

The first maintainer head failed CI run 39905994821 for two PR-caused test issues: the Worker error event is typed unknown (check-test-types-core-2, job 120258867767), and Bun omits Node's socket error code (checks-node-changed-1, job 120258372430). The repair uses the existing error normalizer and checks the error name plus offending value. All lifecycle, cleanup, and sibling assertions remain. These failures are repaired here, not classified as inherited; no CI rerun was requested.

ClawSweeper's requested re-review found no actionable code findings and retained sufficient proof on 44410951a39c3972ad89cbe6ae96eda3a262e232. The two subsequent test-only corrections passed the latest Codex autoreview through P2 and the final exact-head CI above. The PR is ready for maintainer review; no merge was performed.

@clawsweeper

clawsweeper Bot commented Oct 22, 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.

@openclaw-barnacle openclaw-barnacle Bot added triage: blank-template Candidate: PR template appears mostly untouched. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: S labels Oct 22, 2026
@anmol0b anmol0b changed the title fix: native worker supervisor crashes when a resource attachment endp… fix: native worker supervisor crashes when a resource attachment endpoint is rejected Oct 22, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Oct 22, 2026
@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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR routes synchronous resource connection failures through the existing worker failure and termination path.

Example: A private worker creation request injects resource endpoint 70000.

  • Before: The connection throws synchronously and terminates the shared supervisor without delivering failure replies.
  • After: The child reports an error and exits, cleanup uncertainty is retained, and another worker successfully exchanges ping and stops.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, correct containment repair with applicable production-boundary fault evidence and successful current-head validation.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The retained contributor-reported Node 24.22.1 trace exercises the production supervisor and real connection rejection, showing ordered failure, child exit, retained cleanup uncertainty, and successful sibling operation; the production fix is unchanged and current-head CI covers the repaired regression.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A rejected resource attachment can terminate the shared supervisor and disrupt unrelated workers without delivering a failure to the requester.
Reason: The narrow repair preserves the existing lifecycle contract, adds no public controls, and has been carried forward by the feature-history owner.

Merge readiness

✅ Ready for maintainer review

This PR provides a focused containment fix for a source-confirmed supervisor crash, preserves resource custody, and has no actionable findings.

Priority: P2
Reviewed head: 86c162214fdf0ffd76daac70c593819491f4634c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The native worker supervisor receives private lifecycle requests, constructs child workers, attaches broker resources, and returns execution and cleanup receipts to the parent handle.

flowchart LR
  A[Parent worker handle] --> B[Native lifecycle supervisor]
  B --> C[Child worker]
  B --> D[Resource attachment client]
  D --> E[Spawn broker socket]
  D --> F[Existing failure and stop path]
  F --> B
  B --> A
Loading

Technical review

Best possible solution:

Land the existing attachment-owner containment fix while preserving child join and broker-owned cleanup settlement.

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

Source confirms that injected endpoint 70000 reaches an unguarded connect and escaping supervisor exception on current main; this review executed no target code.

Is this the best way to solve the issue?

The smallest complete fix belongs in the attachment client: defer synchronous rejection through its existing failure callback until the supervisor has installed ownership and child listeners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7c831b47b82d.

Provenance checked

  • Supervisor attachment and task-port custody keeps the original intent (215d60d: Direct task transport reduced message hops while retaining supervisor ownership of startup, native exit, and resource settlement.)
  • Shared failure callback keeps the original intent (d264306: The refactor consolidated equivalent error delivery and termination without changing lifecycle ownership.)
  • Resource connection and cleanup ownership keeps the original intent (9c93bc3: Retained resource transport preserves cleanup custody through worker failure; the patch extends its existing failure path to synchronous connection rejection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduction and smallest complete fix: The introduced production changes catch connection construction failure in the attachment owner and remove the supervisor's redundant close-and-rethrow wrapper; no new lifecycle state or competing owner is introduced. (src/process/spawn-broker/resource-client.ts:118, 86c162214fdf)
  • Current main retains the defect: Current main still calls connect synchronously without containment and rethrows attachment failure before installing child event handlers; the affected files match the pinned introduction base. (src/process/spawn-broker/resource-client.ts:116, 7c831b47b82d)
  • Custody contract: The parent treats create-error as constructor refusal and abandons unattached custody, so an already-constructed child's attachment failure must retain ordinary error, execution-exit, and cleanup settlement. (src/infra/worker-native-handle.ts:501, 86c162214fdf)
  • Bounded production exposure: The authority producer creates a socket pathname or Windows named pipe, and captureNativeResource overlays that authority onto the attachment; no supported producer of numeric endpoint 70000 is established. (src/process/spawn-broker/resource-authority.ts:28, 86c162214fdf)
  • Retained behavioral proof and regression: The full PR body retains the contributor's Node 24.22.1 production-supervisor fault trace showing failure replies, child exit, and a successful sibling round trip. The regression asserts ordered created, error, execution-exit, and stop-error replies using real workers and ports. (src/infra/worker-native-lifecycle.test.ts:173, 86c162214fdf)
  • Re-review scope: Compared with the previous reviewed head, production behavior is unchanged; the test now normalizes unknown Worker errors and checks RangeError plus 70000 across Node and Bun. (src/infra/worker-native-lifecycle.test.ts:128, 86c162214fdf)

Likely related people:

  • Peter Steinberger: Raw commit d264306 adds src/infra/worker-native-lifecycle.worker.ts:179 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d2643069b48d; files: src/infra/worker-native-lifecycle.worker.ts)

PR surface

Source +4, Tests +123. Total +127 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 22 18 +4
Tests 1 124 1 +123
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 146 19 +127

Review metrics

Metric Value Why it matters
Production versus regression code Production +22/-18; tests +124/-1 The small production increase contains the exception within the existing owner; one regression verifies failure ordering, child exit, retained cleanup uncertainty, and subsequent worker operation.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The patch contains a shared-supervisor crash, but the demonstrated malformed private input has no established supported production producer.
  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-22T16:39:55.573Z sha 14ec3d9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-22T19:07:13.455Z sha 14ec3d9 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-23T05:34:48.917Z sha 4441095 :: needs maintainer review before merge. :: none

Reviewed October 23, 2026, 2:24 AM ET / 06:24 UTC (Revision 4).

@anmol0b

anmol0b commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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 rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 23, 2026
Merge current main while preserving the contributor's attachment-client fix.
Assert the stable socket error code instead of Bun-specific wording, observe
supervisor failures without unhandled errors, and use event-driven waits.
Require child join and retained cleanup uncertainty before checking that a
subsequent worker can still create, exchange a message, and stop.

Fixes openclaw#180581
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete merged commit a06d324 into openclaw:main Oct 23, 2026
122 of 124 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@anmol0b
anmol0b deleted the fix/native-worker-attach-failure branch October 23, 2026 10:32
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…oint is rejected (openclaw#180773)

* fix: native worker supervisor crashes when a resource attachment endpoint is rejected

* test: normalize native supervisor error events

* test: assert attachment failure across Node and Bun

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawtributors PR from a clawtributor 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. triage: blank-template Candidate: PR template appears mostly untouched.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Native worker attachment failure crashes the lifecycle supervisor without returning a create-error

3 participants