Skip to content

fix(daemon-cli): make gateway restart health wait respond to interrupt - #187335

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/cli-restart-health-wait-ignores-interrupt
Oct 29, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/cli-restart-health-wait-ignores-interrupt

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway start/restart commands continuing health polling after accepting Ctrl-C or SIGTERM.

User Impact

Operators can interrupt the local health wait promptly and receive exit status 130 or 143, without a late success or ordinary health-wait failure. An already-admitted Gateway restart still completes; interruption does not roll it back. Genuine service failures remain visible even if an interrupt arrives at the same time.

Why This Change Was Made

Thread the existing command signal into readiness waits, polling delays and active native probes. Shared lifecycle failure handlers recognize the owned abort before emitting a failure, and lock/probe observations recheck cancellation before accepting late results. The error classifier matches the command's abort reason or direct cause rather than hiding every error after interruption.

The contributor's commits and regression cases are retained. No new signal handler, controller, timer, configuration, timeout/default, authentication/consent decision or SDK export.

Evidence

Clean-built Linux CLI before/after captures and controls, candidate 4eca98640adad29e4feb7108d12be9cd4c16f14c, main 52bc4b51ab785d1ce7c5a127410794c7336ba3bd:

  • Real externally supervised Gateway restart: unhealthy and held health responses, SIGINT/SIGTERM, each twice. Main continues probing or keeps the probe pending until SIGKILL after roughly two seconds; candidate exits naturally 130/143 in 28–71 ms, closes the probe and prints no late result.
  • Built gateway start and managed-restart lifecycle paths also pass interruption, healthy-success and actual-failure controls. These use a clearly scoped platform-adapter fixture against a real Gateway, not a claim of native systemd acceptance; real HTTP/WebSocket probes, owner checks, shared output handlers and root cleanup remain exercised.
  • Previous-owner release: candidate exits 130/143 in 32/25 ms. Resuming the real Gateway completes the admitted restart; subsequent real health commands succeed on both builds.
  • Genuine service failure coinciding with interruption remains reported, with the root preserving 130/143.
  • Clean Node 24.22.1 Linux builds and changed-owner formatting/lint checks passed. Zero test commands run and no test lines added by this repair.

Simplification retained the existing lifecycle and native transport owners. Whole-PR merge-base delta: production +82/-12 (94 gross, net +70), tests +97/-2 (contributor changes). The remaining growth wires cancellation through existing boundaries and preserves lifecycle failure ownership.

Merge danger: Two-way door: reverting restores the old waiting behavior without a migration or persistent-contract change. Blast radius is local Gateway start/restart health observation and its terminal/JSON result handling; admitted native service work and Gateway authentication/ownership rules are unchanged.

@clawsweeper

clawsweeper Bot commented Oct 29, 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 cli CLI command changes size: S labels Oct 29, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Gateway start and restart health waits honor command interruption while preserving genuine service failures.

Example: Send SIGINT while openclaw gateway restart awaits a held health response.

  • Before: The CLI acknowledges interruption but remains waiting until forced termination.
  • After: The CLI closes the probe and exits naturally with status 130 without reporting late success or failure.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with strong shipped-command evidence; committed regression execution is not documented.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The exact-head receipt exercises built CLI dispatch, real Gateway restart admission, native probes and root finalization in isolated Node 24 Linux Docker: SIGINT/SIGTERM close held probes, stop polling and exit 130/143, while healthy and genuine-failure controls retain their outcomes and admitted restarts finish. Managed-service cases explicitly use a platform-adapter fixture rather than native systemd.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gateway start and restart can acknowledge interruption while continuing health observation and delaying command exit.
Reason: Prompt cancellation restores the existing root command contract without changing restart admission, readiness requirements or operator settings.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current-main cancellation bug with no actionable findings; exact-head CI remains pending.

Priority: P2
Reviewed head: 4eca98640adad29e4feb7108d12be9cd4c16f14c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Base/head execution of the committed regression tests is not reported, although the supplied shipped-CLI before/after runs demonstrate the changed behavior.
Agent review details

How this fits together

Gateway lifecycle commands activate or restart a service, observe ownership and readiness through native probes, and return terminal or JSON outcomes through the root command cleanup owner.

flowchart TD
  A[Gateway CLI command] --> B[Lifecycle runner]
  B --> C[Service or verified Gateway owner]
  B --> D[Health observation]
  D --> E[Native HTTP and WebSocket probes]
  F[Root command cancellation] --> D
  D --> G[Lifecycle output and root cleanup]
Loading

Technical review

Best possible solution:

Use the existing command cancellation owner throughout health observation, preserving admitted restarts and genuine failure reporting.

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

The supplied built-CLI before/after receipt reproduces continued polling and held probes after SIGINT/SIGTERM; its baseline matches current main in the affected production modules.

Is this the best way to solve the issue?

The patch fixes the missing cancellation propagation at existing owners, preserves genuine errors, and adds no competing signal handler or persistent state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 50c3ff63fcd4.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Shakker: Raw commit e123606 adds src/cli/daemon-cli/lifecycle.ts:458 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e123606b46b5; files: src/cli/daemon-cli/lifecycle.ts)
  • SunnyShu: Raw commit 823fbf7 adds src/cli/daemon-cli/restart-health-probe.ts:107 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 823fbf745d4e; files: src/cli/daemon-cli/restart-health-probe.ts)

PR surface

Source +70, Tests +95. Total +165 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 82 12 +70
Tests 3 97 2 +95
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 179 14 +165

Review metrics

Metric Value Why it matters
Production versus test changes Production +82/-12; tests/support +97/-2 Growth wires cancellation through existing owners and covers distinct readiness, polling, probe and previous-owner interruption boundaries.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Interrupted Gateway lifecycle commands can remain waiting, but the demonstrated impact is limited to local CLI observation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 (2 earlier review cycles)
  • reviewed 2026-10-29T05:10:44.028Z sha 436996c44babe70d15a3070fd98881664e974fc3 :: needs real behavior proof before merge. :: [P2] Handle cancellation before lifecycle failure reporting | [P2] Carry cancellation through the active listener probe
  • reviewed 2026-10-29T06:39:01.950Z sha 76bc0b2 :: needs real behavior proof before merge. :: none

Reviewed October 29, 2026, 3:16 AM ET / 07:16 UTC (Revision 3).

…ealth

An accepted SIGINT/SIGTERM aborts the command work scope, but the daemon
lifecycle runners turned that cancellation into a user-visible failure: the
external-supervisor health wait rethrew its AbortError out of `gateway
restart`, the shared start/restart runners reported "start failed" or
"restart failed" for the cancelled wait, and the listener probe inside that
wait kept running until its own timeout.

The root signal owner already records 130/143 after cleanup, so a cancelled
wait returns instead of failing:

- `lifecycle-core` skips failure reporting when the command work scope is
  aborted, and still reports every real failure (including deadline aborts).
- `runExternalSupervisorRestart` returns without emitting a failure when its
  health wait was cancelled, replacing the previous outer `.catch`.
- `inspectGatewayPortHealth` and `confirmGatewayReachable` carry the command
  signal through the in-flight probe and re-check it after each await.

Ref: BUG-257-cli-restart-health-wait-ignores-interrupt (local finding)
@SunnyShu0925
SunnyShu0925 force-pushed the fix/cli-restart-health-wait-ignores-interrupt branch from 436996c to 76bc0b2 Compare October 29, 2026 06:26
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review.

@clawsweeper

clawsweeper Bot commented Oct 29, 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-environment Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Built Linux CLI before/after receipt

Candidate 4eca98640adad29e4feb7108d12be9cd4c16f14c, including contributor head 76bc0b2446317114a4536eb601aade512a65c7f5. Main baseline 52bc4b51ab785d1ce7c5a127410794c7336ba3bd. Sources installed and clean-built separately inside secretless Node 24.22.1 Linux/arm64 Docker. No source execution or install on the host; no live credentials, channels or model calls.

Native externally supervised restart — real CLI and real Gateway

Ran the shipped entry points with explicit isolated profiles and state/config paths:

node openclaw.mjs --profile p187335base gateway run --port <isolated-loopback-port>
node openclaw.mjs --profile p187335base gateway restart
# Same invocations with p187335cand on the candidate build.

A task-owned supervisor respawned the real Gateway after its native targeted restart request. Its real lock, owner identity and listener were verified through production code, with lsof installed in the container. A Gateway-side network fixture affected only health: either a correlated UNAVAILABLE reply or a held response, after real protocol/authentication. SIGINT/SIGTERM was sent to the CLI only after the endpoint recorded the affected request. CLI dispatch, restart admission, lock replacement, polling, native client/probe, root signal handling and finalization were not replaced.

Endpoint Signal Main: repetitions 1, 2 Candidate: repetitions 1, 2
unhealthy SIGINT 2026 ms / SIGKILL, 2112 ms / SIGKILL 71 ms / 130, 32 ms / 130
unhealthy SIGTERM 2014 ms / SIGKILL, 2147 ms / SIGKILL 28 ms / 143, 31 ms / 143
hold SIGINT 2162 ms / SIGKILL, 2076 ms / SIGKILL 34 ms / 130, 30 ms / 130
hold SIGTERM 2100 ms / SIGKILL, 2025 ms / SIGKILL 28 ms / 143, 38 ms / 143

Main acknowledged interruption but continued polling: four recorded health requests per unhealthy case, versus one on the candidate. Held main probes remained pending until process death. All main interrupted processes subsequently exited by SIGKILL after about two seconds; the collector did not send SIGKILL, and these are not natural cancellation exits. Candidate exited naturally 130/143 in 28–71 ms, closed the active peer, made no later probe, and emitted only the existing interruption/cleanup notice—no late lifecycle failure or success.

Controls on both builds: unmodified healthy endpoint completed the real targeted restart and returned 0; a separate state root with no active owner retained the actual restart refusal and 1.

Shared start and managed-restart output owners

Also ran the actual built gateway start and gateway restart --preserve-definition commands against a real running Gateway. For these paths only, a narrowly scoped loader fixture supplied the platform service adapter (loaded/running identity and completed activation); this is not evidence of real systemd service acceptance. All lifecycle runners, restart-intent preparation, real owner/lock checks, native HTTP/WebSocket probes and root exit handling remained production code. The real Gateway advertised the same supervised service identity as the adapter, rather than bypassing owner admission.

  • Both commands, held and unhealthy health observations, SIGINT and SIGTERM: main remained waiting then exited SIGKILL in 2018–2219 ms; candidate exited naturally 130/143 in 30–34 ms, without late success/failure output.
  • gateway start additionally held real /healthz and /readyz requests; candidate closed both HTTP requests and the WebSocket probe on cancellation.
  • Healthy controls returned 0 on both builds. A genuine adapter restart exception retained the ordinary failure diagnostic and 1 on both.
  • A separate genuine-failure race dispatched that adapter error, then accepted SIGINT/SIGTERM before the error arrived: candidate preserved the actual service-failure diagnostic, while root retained 130/143. This confirms that coincident interruption does not silently swallow service errors; only the owned abort reason (or its direct cause) settles silently.

Previous owner release and admitted restart completion

Paused the task-owned real Gateway after its native restart RPC connection closed, before it could release its old owner. Interrupting the waiting CLI produced main SIGKILL after 2207/2184 ms, versus candidate 130 in 32 ms / 143 in 25 ms. Resumed the Gateway after each CLI exit; its already-admitted restart finished, and a fresh real gateway health --json returned 0 in every case. No clock change or simulated process time.

Checks and scope

Clean Linux builds passed. Oxfmt check and Oxlint passed on the four changed production modules (zero lint warnings/errors). Zero test commands run; zero test lines added by this repair. Existing contributor regressions retained.

Simplification retained existing root cancellation, shared failure reporting and native probe owners; no new handler/controller/timer, timeout/default change, auth/consent change or SDK export. The final patch also rechecks cancellation after probe setup and previous-owner reads. Whole PR merge-base delta: production +82/-12 (net +70; 94 gross); tests +97/-2 (net +95, contributor changes). Under the 300-gross-production scope limit.

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 29, 2026
@clawsweeper clawsweeper Bot added 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 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@obviyus
obviyus merged commit 745279f into openclaw:main Oct 29, 2026
142 checks passed
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in 745279f. Thanks @SunnyShu0925. The daemon health wait now stops on Ctrl-C or a service stop.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
openclaw#187335)

fix(cli): stop the daemon health wait on Ctrl-C and SIGTERM

After a daemon start or restart, the CLI waited for the Gateway to become healthy but ignored SIGINT and SIGTERM, so it kept probing until it was killed. The wait now aborts its active probe on the first signal and exits with 130 or 143 with no late result. A genuine service failure that coincides with the interrupt is still reported, and a restart that was already admitted still completes.

Update behavior: this only cancels the CLI's own wait when that process receives an interrupt. Start, restart and update runs that aren't interrupted wait and report exactly as before, and the service itself is not changed.

Evidence: clean-built Linux CLI with a real Gateway. With an unhealthy or held probe, main kept probing until killed at about 2 s (twice per signal); with this change it exited 130 or 143 in 28 to 71 ms, closed its probes and printed nothing late (twice per signal). Healthy and real-failure controls behave correctly, and admitted restarts resumed and later health commands succeeded. Details: openclaw#187335 (comment).

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes 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.

2 participants