Skip to content

fix(cli): stop pending health reads when interrupted - #196655

Merged
obviyus merged 3 commits into
openclaw:mainfrom
Alix-007:alix/fix-health-cancel-20261110
Nov 10, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
Alix-007:alix/fix-health-cancel-20261110

Conversation

@Alix-007

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: Ctrl-C during a pending openclaw health or openclaw gateway health read can leave its Gateway connection running until the launcher forcibly kills the process about two seconds later. This is reproducible when stderr is redirected, while the normal terminal interrupt is accepted.

User Impact

Interrupted read-only health commands cancel their pending connection and exit promptly with 130, without publishing a late successful result. Normal health queries still work. Shared Doctor/onboarding callers and already dispatched nonhealth mutation receipts keep their existing behavior.

Why This Change Was Made

Explicitly connect the four health CLI registrations to the existing invocation signal and read transport/readiness deadline. Carry the same signal through the optional authentication diagnostic and check it before publishing results after asynchronous presentation work. Generic Gateway actions and other RPC calls receive no new default cancellation policy.

This is one complete health-read lifetime repair across seven existing production files (+110/-26), with six existing regression suites expanded (+208/-2, net 206 LF). The dedicated 206 LF allocation covers only the actual new test lines; the global baseline is untouched. No new dependency, public option, config/default, JSON schema/protocol, permission or upgrade/migration behavior.

Evidence

Product head f5066a64003f67489e862003d647fbf7dc41bf9c; BASE baccc7e152916c7f4a48596b5cb544c12264ac54. Both clean commits use their normal cliStartup build and actual openclaw.mjs entry. The same frozen collector starts a real controlling PTY, redirects stderr to a regular file and sends real terminal Ctrl-C while the production Gateway client waits on a compatible synthetic loopback WebSocket peer:

python3 health-cancel-proof.py "$CHECKOUT" "$NEW_OUTPUT" "$NODE26" "$EXPECT"

Set EXPECT=red for baseline and EXPECT=green for the product head, using fresh isolated output directories.

  • BASE: root/gateway health, interrupted during connect or health RPC, acknowledges SIGINT but exits -9 only after the launcher kill at about 2.03s. No collector watchdog or held response release causes that result.
  • HEAD: all four interrupted scenarios exit 130 in 73.73–99.70ms; the peer records the socket closed within 12.57 ms, before harness cleanup. No late health JSON is published.
  • Controls: both uninterrupted commands exit 0 and return the expected health JSON on BASE and HEAD; all isolated input configurations remain unchanged.
  • Focused checks: 8 existing suites / 222 tests pass; after two mechanical test typing corrections, the two affected suites pass 81 tests. Final scoped types, ordinary typed lint, format and test-line ratchet in the actual CI merge context passes. The full wrapper took 244.465s (canonical worker preparation 134.155s); final two-suite replay 101.635s. One cold preparation exceeded an unchanged existing test's 120s timeout; its failure is retained, with one same-source replay passing after the generation completed. No timeout was widened.

Inspectable full BASE/HEAD terminal output, peer events, receipts, frozen collector and measured checks. Independent P0–P3 code/evidence review uses the authorized agent fallback; no official autoreview-helper result or hosted CI success is claimed.

Cleanup: owned CLI/peer processes and threads exit; isolated config hashes remain unchanged. No production Gateway/service/channel/provider or session is used. Not tested: native scenarios cover route-first JSON; full Commander text and authentication-fallback live transport are not natively replayed (focused owner tests cover those paths). Existing local presentation work without an abort seam is not newly made interruptible. Windows/macOS, real service lifecycle and upgrade completion remain untested.

@clawsweeper

clawsweeper Bot commented Nov 10, 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 commands Command implementations size: M labels Nov 10, 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. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Connect health CLI reads, readiness waits, and authentication diagnostics to the existing invocation cancellation signal.

Example: Press Ctrl-C during a pending openclaw gateway health --json request with stderr redirected.

  • Before: The connection remains open until the launcher forcibly kills the CLI.
  • After: The connection closes and the CLI exits 130 without publishing a health result.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair using existing owners, supported by exact-head shipped CLI evidence and meaningful controls; required CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): At exact head 02c4bc3, collaborator obviyus exercised built text/JSON root and Gateway health commands against isolated real Gateways in secretless Docker using real terminal Ctrl-C during pending connections; each exited 130, sockets closed, and no late health output appeared, while healthy, unreachable, and Doctor controls matched main. Contributor-linked earlier-head receipts additionally exercise held connect and health responses through the production CLI and WebSocket client.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Ctrl-C acknowledges interruption while a pending health connection continues until the launcher forcibly terminates the CLI.
Reason: Prompt cancellation restores the existing invocation contract using established owners, with collaborator-confirmed exact-head behavior and no new product surface.

Merge readiness

✅ Ready for maintainer review

This PR fixes a distinct health-command cancellation bug still present on current main; the pinned diff has no actionable findings.

Priority: P2
Reviewed head: 02c4bc37f195e3435772edff6bc2ea9d0c8a67a4

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI registrations pass invocation cancellation through health commands into the existing Gateway transport and readiness owners, which return health output or settle interrupted reads.

flowchart TD
  A[CLI invocation] --> B[Health registrations]
  B --> C[Health command]
  C --> D[Readiness deadline]
  C --> E[Gateway transport]
  C --> F[Authentication diagnostic]
  D --> G[Result or cancellation]
  E --> G
  F --> G
Loading

Technical review

Best possible solution:

Retain this focused wiring repair and merge through the normal required CI gates.

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

Current-main source omits the cancellation signal, and supplied real-process before/after evidence reproduces the resulting forced termination; this review executed no target code.

Is this the best way to solve the issue?

The patch repairs the missing connection between invocation lifetime and existing read owners, preserving generic RPC behavior and callers without a signal.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0fd8c138f5bc.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1b3f38e adds src/commands/health.ts:177 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1b3f38e7e4ff; files: src/commands/health.ts)
  • Josh Avant: Raw commit f385491 adds src/commands/health.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f385491c230c; files: src/commands/health.ts)
  • Vincent Koc: Raw commit e06782d adds src/commands/health.ts:610 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e06782d5e747; files: src/commands/health.ts)

PR surface

Source +46, Tests -1. Total +45 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 72 26 +46
Tests 1 12 13 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 84 39 +45

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.

Review metrics

Metric Value Why it matters
Production versus tests Production +72/-26; tests +12/-13 Production growth connects existing cancellation boundaries; the retained regression fits the existing suite without new scaffolding or allocation.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Interrupting a pending diagnostic read leaves its connection running until forced termination, with limited impact outside the invoked CLI.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 (1 earlier review cycle)
  • reviewed 2026-11-10T12:22:35.460Z sha f5066a6 :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 8:40 AM ET / 13:40 UTC (Revision 2).

Forward the CLI cancel signal directly, treat any failure after an interrupt as silent, drop redundant pre-checks, and replace the allocation-backed tests with one regression.
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Proof for head 02c4bc3, compared with main af37a00. Both were built CLIs (pnpm build:docker) running on node 24.22.1 in a secretless Docker container. Each tree talked to its own real local Gateway, with token auth and isolated state.

Ctrl-C while a read is pending. The real Gateway was frozen with SIGSTOP. The kernel still accepts the TCP connection, so the health read hangs on its own. The CLI ran on a real pty with stderr redirected to a file. Ctrl-C (\x03 through the tty) was sent 0.5 s after the CLI's socket to the Gateway was ESTABLISHED. Each of 4 commands ran twice per tree.

command main (2 runs) this head (2 runs)
health killed by SIGKILL 3.55 / 3.56 s after Ctrl-C; socket still ESTABLISHED 300 ms after exit 130 after 0.034 / 0.032 s
health --json SIGKILL after 2.07 / 2.12 s; ESTABLISHED exit 130 after 0.030 / 0.034 s
gateway health SIGKILL after 2.14 / 2.47 s; ESTABLISHED exit 130 after 0.032 / 0.041 s
gateway health --json SIGKILL after 2.86 / 2.06 s; ESTABLISHED exit 130 after 0.037 / 0.426 s; its socket was already closing (FIN_WAIT2) 300 ms after

On both trees stderr shows only Command interrupted by SIGINT. Waiting for cleanup before exiting. Main's socket stays open until the launcher force-kills the process. This head exits within about 40 ms, which takes its socket with it. No health output was printed after Ctrl-C on either tree. On this head the only bytes written after Ctrl-C are the terminal-restore escape codes.

Controls with a fully started Gateway and no interrupt. All of these matched main once timing fields are normalized:

  • health, health --json, gateway health and gateway health --json all exit 0 with the same output.
  • The unreachable-Gateway errors are unchanged. health prints Couldn't connect to OpenClaw. and exits 1. gateway health --json prints the same gateway_transport_error / ECONNREFUSED JSON and exits 1.
  • doctor --non-interactive exits 0 with the same output, apart from random automation IDs and the Control UI asset note from the docker build.

Caller check. When it is interrupted, emitReachableGatewayAuthDiagnostic returns true, meaning "handled, nothing more to print". Its only callers are healthCommand, runGatewayHealthJsonRoute and the gateway health action. All three just return on true.

Doctor (doctor-gateway-daemon-flow), configure, onboarding (non-interactive and the wizard finalize step) and the system agent reach healthCommand or healthCommandNonExiting without a signal. Doctor's own gateway health check and channels status call waitForGatewayDiagnostic without one, and the status scan calls waitForGatewayDiagnosticReadiness without one. Every new branch depends on signal?.aborted, so none of these paths can read an interrupt as healthy.

Changes on top of the contributor's commits.

  • The signal is passed through directly.
  • After an interrupt, any failure exits quietly.
  • Redundant pre-checks and the render-time checks are dropped.
  • The test-lines allocation and the large test matrix are replaced by one regression test in health.test.ts. Two tests that duplicated existing coverage were folded in or removed.

Production is now +72/-26 against the merge base, and tests +12/-13.

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus
obviyus merged commit 401a1de into openclaw:main Nov 10, 2026
134 of 135 checks passed
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Landed in 401a1de. Thanks @Alix-007. openclaw health now stops at once on Ctrl-C.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for the real-Gateway checks and landing the Ctrl-C fix!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
fix(cli): let Ctrl-C cancel pending health reads

openclaw health and openclaw gateway health ignored Ctrl-C while the Gateway read was pending. The command kept its connection open until the launcher force-killed it about 2 s later. The health routes now pass the command's existing cancel signal to the Gateway read and exit quietly after an interrupt. Callers that pass no signal, including Doctor, configure, onboarding and status, behave as before, and no text is new.

Evidence: the built CLI on node 24.22.1 in secretless Docker against a real Gateway frozen with SIGSTOP, with Ctrl-C sent through a real terminal 0.5 s after the connection opened and stderr redirected, two runs per command. On main, health and gateway health, with and without --json, hung until force-killed 2.06 to 3.56 s after Ctrl-C with the connection still open. With this change all four exit 130 in 0.03 to 0.43 s. Answered health checks, the unreachable-Gateway errors and doctor --non-interactive give the same output on both. Details: openclaw#196655 (comment).

Thanks @Alix-007.

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 commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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