Skip to content

fix(test): capture child diagnostics before CLI deadlock cleanup - #150288

Merged
steipete merged 1 commit into
mainfrom
upd/flake-cli-exit-device-credentials
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/flake-cli-exit-device-credentials

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #150244

What Problem This Solves

CLI process tests can hit their deadlock guard after printing guidance, leaving no child-resource evidence to explain the stall. This is the maintainer-directed diagnostic follow-up to the hosted failure.

User Impact

There is no production behavior change. Maintainers get the child’s active resource/handle types, active request types, and bounded pending-promise counts in the next timeout failure. The underlying intermittent hang remains unexplained.

Why This Change Was Made

The shared test harness preloads a Node-only diagnostic signal handler and waits for its readiness acknowledgement before signaling it. A timeout remains a failure at the original deadline; a separate 200 ms diagnostic window precedes SIGKILL and pipe cleanup. An unresponsive child still receives bounded cleanup, and cleanup errors cannot replace the first failure. The diagnostic dump is retained separately from the stderr tail so later noisy output cannot hide it. Windows and Bun keep the existing termination path without this POSIX Node preload.

The production owner check found no metadata await blocking this error exit. logger-file-transport.ts:74,229 awaits stat only in the background flush; one-shot-output.ts:8,16 independently schedules exit with a bounded stream drain. The synchronous buffered-log rescue at logger-file-transport.ts:332,404 remains unchanged.

Evidence

  • The new held-handle regression failed against the original harness because the error lacked "Timeout":1. It passes with the diagnostic preload, including when later stderr exceeds the output-tail limit.
  • Tests cover an unresponsive child, exit during diagnostic grace remaining a failure, ordinary output staying unchanged, and an input failure surviving a secondary kill error.
  • Prior investigation: 30/30 focused Linux / Node 24.19.0 attempts passed, including 20 under CPU load. All children called process.exit 3–14 ms after guidance, with JavaScript exit handlers returning within 4–15 ms. The original hosted log has no guidance timestamp or handle dump.
  • Local Node 24.21.0 proof: the final 12-case harness suite passed 20/20 repetitions (240 cases). The real missing-credentials CLI case also passed 20/20 repetitions, and passed again after the final type-aware error-normalization adjustment.
  • node scripts/check-changed.mjs: passed, including core test typechecking, all selected guards, and type-aware lint. Fresh pre-commit Codex autoreview: scoped-clean at P1. The requested --mode branch --base origin/main --max-priority P1 review is also scoped-clean, with no findings.
  • Broader local proof: 48 passed, 5 failed, 1 skipped. The same five non-loopback Gateway cases fail with the original harness: the fixture selects an unreachable link-local IPv4 address on this Mac. The original harness reports Gateway transport timeouts. These failures are independent of this change; no assertions, baselines, retries, or command budgets were weakened.

Production LOC delta: 0. Tests and test support: +244 / -61 (net +183), across three files.

Representative new guard failure excerpt:

CLI process did not exit before the 500ms deadlock guard (exitCode=null signalCode=null)
Child diagnostics: SIGUSR2 requested; grace=200ms; received. SIGKILL cleanup attempted.
--- child diagnostics ---
{"pid":55608,"elapsedMs":464,"activeResources":{"PipeWrap":2,"Timeout":1},"activeHandles":{"Socket":2},"activeRequests":{},"pendingPromises":{"tracked":1,"truncated":false,"hint":"Unresolved promises alone do not keep the event loop alive."}}
--- child stdout (tail) ---
partial
Original-stall candidates and owner evidence

References below describe the investigated source at 387da5edaa9d6c6cfcfc15e167fe2e46d8647d86. These test, command, and exit owners match the failing PR head; the wider source trees differ.

Candidate Owner and observation
stdout/stderr write, drain Immediate src/cli/one-shot-output.ts:8,12,16; reachable, with a five-second unreferenced fallback.
Logger Immediate, metadata request, synchronous exit rescue src/logging/logger-file-transport.ts:74,322,332,404; reachable. Successful-run traces identify the pending request as logger fs.promises.stat; it did not prevent exit.
Gateway WebSocket/request timers src/gateway/call.ts:1238 rejects missing credentials before client creation at :954; normal settlement clears the timer and stops the client at :897,922.
SecretRef exec child src/gateway/credentials-secret-inputs.ts:139 requires a configured SecretRef; this fixture has none. Exec ownership is src/secrets/resolve.ts:495.
Writable state/coordinator src/cli/devices-cli.runtime.ts:97 selects read-only; src/state/openclaw-state-db-readonly.ts:369 returns for the absent database. Coordinator retention at src/infra/sqlite-coordinator.ts:222,239 is unreferenced.
Progress timer src/cli/progress.ts:130 takes the no-op path for piped stderr.
Respawn child/inherited pipes src/cli/gateway-backed-exit.process.test-support.ts:124,134 disables both respawn paths for this fixture.
Pending cleanup disposer src/cli/runtime-cleanup.ts:34,43; cleanup unwinds before src/entry.ts:336 prints guidance.
Scratch SQLite Worker node-sqlite.mjs:75,103,123; startup awaits the worker’s exit before admitting the CLI.

No production cleanup divergence was found. The prior experiment selected the one failing test rather than replaying all 42 in original order, and instrumentation can affect scheduling.

Collect bounded child resource diagnostics before deadlock cleanup while
preserving the original timeout and interaction failures. Keep production
logging and output-drain behavior unchanged.

Related: #150244
@clawsweeper

clawsweeper Bot commented Sep 16, 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: M maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 20:32
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 4:40 PM ET / 20:40 UTC.

ClawSweeper review

What this changes

The CLI test harness captures child resource diagnostics before terminating stalled processes and preserves the original failure when cleanup also fails.

Merge readiness

✅ Ready for maintainer review

Useful diagnostic work remains absent from current main. The bounded capture and cleanup changes have no identified blocking defect, and the linked Windows cleanup PR addresses a separate path.

Priority: P3
Reviewed head: 86dbdd8e2381aee79d7e8a5667031613fa51655b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused diagnostic improvement with relevant process evidence and no identified blocking correctness or security issue.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed owner is the CLI test harness itself: the supplied Node 24.21.0 child-process trace shows resource capture before bounded cleanup, with repeated process tests covering timeout and ordinary CLI behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed owner is the CLI test harness itself: the supplied Node 24.21.0 child-process trace shows resource capture before bounded cleanup, with repeated process tests covering timeout and ordinary CLI behavior.
Evidence reviewed 8 items Pinned change ownership: The host-verified merge-base-to-head patch contains only the CLI harness, its regression tests, and the diagnostic preload. The verified test merge against its recorded main parent preserves that same scope.
Deadline and cleanup invariants: The complete harness retains exit-plus-stream-EOF completion, makes the timeout final before requesting diagnostics, limits diagnostic grace to 200 ms, and attempts each pipe cleanup independently. Readiness is removed from returned stderr.
Meaningful process-boundary coverage: The complete tests exercise held timers and promises, noisy stderr, exit during diagnostic grace, an unresponsive event loop, interaction failures with throwing cleanup, ordinary output, and detached descendant pipes.
Findings None None.
Security None None.

How this fits together

CLI process tests launch isolated Node processes and collect their exit status and output. This harness controls their deadlock deadline and supplies failure details to the test runner.

flowchart TD
  A[CLI process test] --> B[Child process with diagnostic preload]
  B --> C{Finished before deadline?}
  C -->|Yes| D[Return exit status and output]
  C -->|No| E[Request resource diagnostics]
  E --> F[Bounded grace and process cleanup]
  F --> G[Report timeout with diagnostics and output]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +183. Total +183 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 244 61 +183
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 244 61 +183

Review metrics

Metric Value Why it matters
Production versus test growth Production 0; tests and test support net +183 lines Growth is confined to diagnostic instrumentation and process-boundary regressions, with no application runtime expansion.
Diagnostic grace 200 ms after the existing deadline Capture time is bounded and cannot turn a timed-out child into a successful test.

Technical review

Best possible solution:

Keep diagnostic collection in the shared test harness while preserving the deadline, bounded cleanup, and production CLI exit behavior.

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

Not applicable to this diagnostic-only improvement. The held-child timeout is demonstrated in the supplied trace; the original intermittent CLI stall remains unreproduced.

Is this the best way to solve the issue?

Yes. Extending the existing child harness supplies missing evidence without speculatively changing production cleanup or weakening timeout assertions.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This improves developer failure diagnostics without changing production behavior or fixing the underlying intermittent stall.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed owner is the CLI test harness itself: the supplied Node 24.21.0 child-process trace shows resource capture before bounded cleanup, with repeated process tests covering timeout and ordinary CLI behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed owner is the CLI test harness itself: the supplied Node 24.21.0 child-process trace shows resource capture before bounded cleanup, with repeated process tests covering timeout and ordinary CLI behavior.

Label justifications:

  • P3: This improves developer failure diagnostics without changing production behavior or fixing the underlying intermittent stall.
  • 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. Sufficient (terminal): The changed owner is the CLI test harness itself: the supplied Node 24.21.0 child-process trace shows resource capture before bounded cleanup, with repeated process tests covering timeout and ordinary CLI behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed owner is the CLI test harness itself: the supplied Node 24.21.0 child-process trace shows resource capture before bounded cleanup, with repeated process tests covering timeout and ordinary CLI behavior.

Evidence

What I checked:

  • Pinned change ownership: The host-verified merge-base-to-head patch contains only the CLI harness, its regression tests, and the diagnostic preload. The verified test merge against its recorded main parent preserves that same scope. (86dbdd8e2381)
  • Deadline and cleanup invariants: The complete harness retains exit-plus-stream-EOF completion, makes the timeout final before requesting diagnostics, limits diagnostic grace to 200 ms, and attempts each pipe cleanup independently. Readiness is removed from returned stderr. (src/cli/cli-process-child.test-helpers.ts:179, 86dbdd8e2381)
  • Meaningful process-boundary coverage: The complete tests exercise held timers and promises, noisy stderr, exit during diagnostic grace, an unresponsive event loop, interaction failures with throwing cleanup, ordinary output, and detached descendant pipes. (src/cli/cli-process-child.test-helpers.test.ts:80, 86dbdd8e2381)
  • Captured behavioral evidence: The supplied PR body includes a real child timeout transcript showing SIGUSR2 capture, an active Timeout, one pending promise, retained partial output, and cleanup. It reports 240 successful focused cases and 20 successful missing-credentials CLI repetitions on Node 24.21.0, while explicitly separating five baseline network-fixture failures. These are contributor-reported observations, not executions performed during this review. (86dbdd8e2381)
  • Current-main necessity: Current main still kills the child immediately at the guard deadline without requesting resource diagnostics; its harness matches the PR's merge-base version. The diagnostic preload is also absent from the inspected latest-release tree, so no shipped implementation of this patch was established. (src/cli/cli-process-child.test-helpers.ts:150, e1658b84e202)
  • Merged area history: Current-main history includes earlier harness and runtime-policy work by Peter Steinberger. GitHub verifies fix(ci): preserve test runtime flags in CLI children #148038 as merged at this commit and identifies steipete as its author. Its patch adds the runtime-policy comment retained at review line 137. Some local historical blobs were unavailable; the read-only GitHub commit response supplied the relevant patch. (src/cli/cli-process-child.test-helpers.ts:137, 7c665e63e221)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit c2c0700 into main Sep 16, 2026
243 checks passed
@steipete
steipete deleted the upd/flake-cli-exit-device-credentials branch September 16, 2026 20:59
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
)

Collect bounded child resource diagnostics before deadlock cleanup while
preserving the original timeout and interaction failures. Keep production
logging and output-drain behavior unchanged.

Related: openclaw#150244
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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