Skip to content

fix(iroh-node): end the home relay watcher when the endpoint closes - #193995

Merged
jalehman merged 1 commit into
mainfrom
fix/iroh-relay-watcher-close
Nov 6, 2026
Merged

jalehman merged 1 commit into
mainfrom
fix/iroh-relay-watcher-close

Conversation

@jalehman

@jalehman jalehman commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: #192345

What Problem This Solves

Fixes a Node child staying alive after its iroh endpoint closes while it is watching home relay status.

User Impact

Unblocks removing process.exit from the OpenClaw ID tunnel child in #192345: pending and subsequent HomeRelayWatcher.next() calls can finish, letting the child exit naturally. This binding is not loaded by main yet. No dependency, version, lockfile, or public API shape changes.

Why This Change Was Made

The relay-status forwarding task could outlive its endpoint and retain its watch sender forever. Run it under iroh 1.4.1's documented Endpoint::closed().run_until(...) cancellation scope so closure drops the sender. Keep the existing first-status/change delivery and clarify the close promise in generated types.

Reuse the endpoint's existing cancellation owner; no new state or cancellation API. Production Rust stays the same size (three lines replaced). The 35-line regression allocation covers two lifecycle orders in real Node subprocesses, asserting null completion and successful natural exit without process.exit.

Evidence

  • Native macOS arm64 (aarch64-apple-darwin), Node 24.22.1, Rust 1.99.0.
  • Baseline source b72ee38923d26c562179b8f9db7d0fa979cc42de plus only the regression: built successfully, then both pending and post-close cases failed after 10 seconds. Each child reached endpoint closed, never reached watcher ended, and required the test runner's timeout termination (2 failures; 20.30 seconds).
  • Build command: mise exec [email protected] -- npx --yes --package=@napi-rs/[email protected] -- napi build --platform --release --strip --target aarch64-apple-darwin (same invocation as the workflow).
  • Baseline test command: node --test --test-name-pattern="home relay watcher" test/binding.test.cjs.
  • The initial npm run build attempt failed before compilation because npm could not determine the package executable; the workflow's explicit napi command above uses the same pinned CLI and build flags. That unrelated script remains unchanged.
  • Fixed candidate (same base plus this patch): passed cargo fmt --check, cargo clippy --locked --release --all-targets -- -D warnings, the release build above, and node --test test/binding.test.cjs: 10/10 passed, 0.580 seconds wall time. The new subprocess cases exited naturally in 68 ms / 39 ms. Both builds emitted only the existing macOS linker -s is obsolete warning.
  • Generated index.d.ts was retrieved from that build; index.js and Cargo.lock remained unchanged. All four platform jobs passed, including Linux wire compatibility and throughput: https://github.com/openclaw/openclaw/actions/runs/42174068153.

Reviewed and published head: 37789a6988cd4ef819ff1aec583ca76697249bd0 (identical tested Rust/test bytes).

@clawsweeper

clawsweeper Bot commented Nov 6, 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 the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 6, 2026
jalehman added a commit that referenced this pull request Nov 6, 2026
The child now records its exit status, closes the ingress server and iroh
endpoint, and releases the IPC channel so Node exits on its own, as the
no-forced-process-exit guard requires (nodejs/node#64274). It relies on the
iroh binding ending HomeRelayWatcher.next() when the endpoint closes (#193995).
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 6, 2026
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR ends home relay status forwarding when its endpoint closes so waiting JavaScript calls finish and Node can exit naturally.

Example: A Node child consumes the initial empty relay status, starts another watcher.next(), and closes its endpoint.

  • Before: The status read remains pending and keeps the child alive.
  • After: The read and subsequent reads resolve null, allowing natural process exit.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A minimal, source-supported repair with native regression and platform CI evidence; validation remains harness-based.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored exemption applies; supporting native macOS evidence exercises the actual binding in Node subprocesses and reports null completion plus natural exit for both lifecycle orders.
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 Node process waiting for home relay status can remain alive after closing its endpoint.
Reason: The focused repair restores watcher completion and supports the maintained tunnel integration; the supplied maintainer-authored designation establishes direction.

Merge readiness

✅ Ready for maintainer review

This PR provides a minimal repair for a watcher-lifetime defect still present on main; the previous public-description finding is resolved, and no actionable defects remain.

Priority: P2
Reviewed head: 37789a6988cd4ef819ff1aec583ca76697249bd0

Before merge

None.

Findings

None.

Agent review details

How this fits together

The native binding forwards iroh relay statuses through a Tokio watch channel to JavaScript; endpoint closure now ends that forwarding task.

flowchart LR
 A[Iroh endpoint] --> B[Relay status source]
 B --> C[Forwarding task]
 C --> D[Tokio watch channel]
 D --> E[JavaScript next call]
 A --> F[Endpoint closed signal]
 F --> C
Loading

Technical review

Best possible solution:

Keep the endpoint-owned cancellation scope and both native lifecycle regressions.

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

The source and pinned dependency contract establish the failure path, and the supplied baseline run reports both lifecycle orders hanging; this review executed no target code.

Is this the best way to solve the issue?

The patch fixes the producer's lifetime through the existing endpoint cancellation owner and preserves the normal status-delivery path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Smallest complete lifecycle repair: The introduced patch wraps the existing forwarding future in endpoint.closed().run_until(), preserving status delivery without adding state, dependencies, or API shape. (crates/openclaw-iroh-node/src/endpoint.rs:154, 37789a6988cd)
  • Current main retains the defect: Main still spawns the forwarding task without endpoint cancellation, retaining its sender while the endpoint object remains alive. (crates/openclaw-iroh-node/src/endpoint.rs:154, 8d922199c076)
  • Pinned dependency confirms the lifetime contract: The binding imports iroh 1.4.1; that version explicitly documents that endpoint closure does not disconnect home_relay_status watchers and recommends combining them with closed(). Its run_until implementation drops the forwarding future when closure wins. (iroh/src/endpoint.rs:1402, d6c6963b9602)
  • Distinct native lifecycle regressions: Real Node subprocesses cover reads started before and after close, assert repeated null completion, and require natural successful exit; the body reports both failing on the baseline and passing with the patch. (crates/openclaw-iroh-node/test/binding.test.cjs:66, 37789a6988cd)
  • Exact-head platform validation: The linked binding workflow succeeded for Linux x64, Linux arm64, macOS arm64, and Windows x64 at the reviewed head; paginated check-run inspection found no pending or failing checks. (.github/workflows/iroh-node.yml:110, 37789a6988cd)
  • Prior finding resolved: The current public body retains platform and verification results while removing the private-host and agent-review details identified previously. (37789a6988cd)

PR surface

Tests +35, Other +2. Total +37 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 6 4 +2
Total 4 41 4 +37

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 status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A concrete native shutdown hang blocks the planned tunnel integration, but the binding is not loaded by current main.
  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-06T06:37:03.075Z sha 37789a6 :: needs changes before merge. :: [P3] Remove private-host and agent-review details from the PR body

Reviewed November 6, 2026, 1:44 AM ET / 06:44 UTC (Revision 2).

@jalehman

jalehman commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 6, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 6, 2026
@jalehman
jalehman merged commit e039056 into main Nov 6, 2026
116 checks passed
@jalehman
jalehman deleted the fix/iroh-relay-watcher-close branch November 6, 2026 06:49
@jalehman

jalehman commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

jalehman added a commit that referenced this pull request Nov 6, 2026
The child now records its exit status, closes the ingress server and iroh
endpoint, and releases the IPC channel so Node exits on its own, as the
no-forced-process-exit guard requires (nodejs/node#64274). It relies on the
iroh binding ending HomeRelayWatcher.next() when the endpoint closes (#193995).
jalehman added a commit that referenced this pull request Nov 6, 2026
…relayed-device Gateway auth (#192345)

* feat(openclaw-id): add the tunnel transport, OpenClaw ID sign-in and relayed-device Gateway auth

* fix(openclaw-id): an HTTP request from a removed tunnel device does nothing more

A relayed HTTP request kept the role it was admitted with, so a POST
/tools/invoke waiting in a before-tool-call hook still ran its tool after the
device was removed. Every authority check on a relayed HTTP request now asks
the membership authority whether the device is still admitted with the same
kind, account and role; a removal, a role change or OpenClaw ID turning off
fails the next check, including the last one before the tool runs.

* fix(openclaw-id): keep durable work bound to the device that authorized it

Scheduled jobs, condition scripts, script payloads, shell commands, stream
watchers and HTTP execution created over the tunnel now keep the original
device's authority (claw, root, listing seq, owner device) with the job.
Every run, restart and recovery rechecks it against the local membership
record and cancels the work when the device is removed, re-approved, its role
changes or the switch turns off. Recovery waits only for the local record.

- WebSocket and run authority follow current membership; HTTP and WebSocket
  members use the canonical OpenClaw ID profile.
- Stream watchers keep the process grant apart from the payload grant.
- Another operator's timing edits keep the original requester; they never
  promote a member's job to the editor.
- Restored Control UI continuations are owner-only only under admin scope.
- A stopped Gateway ends local authority even during a cold first load.

* test(openclaw-id): bound the ingress test WebSocket server payload

* fix(openclaw-id): keep a device's scheduled grant when another device edits its timing

* fix(openclaw-id): publish the token-binding writer before the tunnel admits devices

* fix(gateway): keep the tunnel principal on plugin HTTP route clients

* fix(gateway): never auto-approve a tunnel node by its synthetic address

* test(openclaw-id): check the tunnel child exits on its own

* fix(openclaw-id): keep the long-path ingress socket under the OpenClaw temp root

* refactor(cron): break the stream operator source import cycle

* refactor(openclaw-id): break the sign-out type cycle with the service

* refactor(gateway): give the stream job scope key its own export name

* fix(scripts): narrow operator source variants in the cron context replay

* chore(test): allocate the OpenClaw ID tunnel regression test lines

* test(gateway): give the deferred profile fixture a real auth result

* test(gateway): keep real SSH verify exports in the tunnel node mock

* fix(openclaw-id): let the tunnel child exit without forcing it

The child now records its exit status, closes the ingress server and iroh
endpoint, and releases the IPC channel so Node exits on its own, as the
no-forced-process-exit guard requires (nodejs/node#64274). It relies on the
iroh binding ending HomeRelayWatcher.next() when the endpoint closes (#193995).

* fix(openclaw-id): require the iroh relay watcher so the tunnel child can exit

A binding without HomeRelayWatcher made the child fall back to endpoint.online(),
which iroh leaves pending after the endpoint closes. That pending native call kept
a stopped child alive, so after the Gateway died it could hold its endpoint key
indefinitely. The loader now refuses such a binding as unavailable.

* fix(openclaw-id): zero the endpoint key when binding the endpoint fails

* test(openclaw-id): mock node:module without spreading its class export

* chore(test): allocate the OpenClaw ID tunnel test lines CI measures

* fix(openclaw-id): keep the inactivity window helper private to the owner lifecycle

service.ts no longer imports inactivityWindows after the owner-expiry timer moved into owner-lifecycle.ts, so the export had no consumer and failed the unused-export scan.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 7, 2026
…relayed-device Gateway auth (openclaw#192345)

* feat(openclaw-id): add the tunnel transport, OpenClaw ID sign-in and relayed-device Gateway auth

* fix(openclaw-id): an HTTP request from a removed tunnel device does nothing more

A relayed HTTP request kept the role it was admitted with, so a POST
/tools/invoke waiting in a before-tool-call hook still ran its tool after the
device was removed. Every authority check on a relayed HTTP request now asks
the membership authority whether the device is still admitted with the same
kind, account and role; a removal, a role change or OpenClaw ID turning off
fails the next check, including the last one before the tool runs.

* fix(openclaw-id): keep durable work bound to the device that authorized it

Scheduled jobs, condition scripts, script payloads, shell commands, stream
watchers and HTTP execution created over the tunnel now keep the original
device's authority (claw, root, listing seq, owner device) with the job.
Every run, restart and recovery rechecks it against the local membership
record and cancels the work when the device is removed, re-approved, its role
changes or the switch turns off. Recovery waits only for the local record.

- WebSocket and run authority follow current membership; HTTP and WebSocket
  members use the canonical OpenClaw ID profile.
- Stream watchers keep the process grant apart from the payload grant.
- Another operator's timing edits keep the original requester; they never
  promote a member's job to the editor.
- Restored Control UI continuations are owner-only only under admin scope.
- A stopped Gateway ends local authority even during a cold first load.

* test(openclaw-id): bound the ingress test WebSocket server payload

* fix(openclaw-id): keep a device's scheduled grant when another device edits its timing

* fix(openclaw-id): publish the token-binding writer before the tunnel admits devices

* fix(gateway): keep the tunnel principal on plugin HTTP route clients

* fix(gateway): never auto-approve a tunnel node by its synthetic address

* test(openclaw-id): check the tunnel child exits on its own

* fix(openclaw-id): keep the long-path ingress socket under the OpenClaw temp root

* refactor(cron): break the stream operator source import cycle

* refactor(openclaw-id): break the sign-out type cycle with the service

* refactor(gateway): give the stream job scope key its own export name

* fix(scripts): narrow operator source variants in the cron context replay

* chore(test): allocate the OpenClaw ID tunnel regression test lines

* test(gateway): give the deferred profile fixture a real auth result

* test(gateway): keep real SSH verify exports in the tunnel node mock

* fix(openclaw-id): let the tunnel child exit without forcing it

The child now records its exit status, closes the ingress server and iroh
endpoint, and releases the IPC channel so Node exits on its own, as the
no-forced-process-exit guard requires (nodejs/node#64274). It relies on the
iroh binding ending HomeRelayWatcher.next() when the endpoint closes (openclaw#193995).

* fix(openclaw-id): require the iroh relay watcher so the tunnel child can exit

A binding without HomeRelayWatcher made the child fall back to endpoint.online(),
which iroh leaves pending after the endpoint closes. That pending native call kept
a stopped child alive, so after the Gateway died it could hold its endpoint key
indefinitely. The loader now refuses such a binding as unavailable.

* fix(openclaw-id): zero the endpoint key when binding the endpoint fails

* test(openclaw-id): mock node:module without spreading its class export

* chore(test): allocate the OpenClaw ID tunnel test lines CI measures

* fix(openclaw-id): keep the inactivity window helper private to the owner lifecycle

service.ts no longer imports inactivityWindows after the owner-expiry timer moved into owner-lifecycle.ts, so the export had no consumer and failed the unused-export scan.
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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