Skip to content

fix(doctor): shut down lifecycle workers before the command exits - #164853

Merged
steipete merged 1 commit into
mainfrom
upd/upd-windows-doctor-exit-uv-handle-closing
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-windows-doctor-exit-uv-handle-closing

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: #164731

What Problem This Solves

Doctor can reach process exit with retained native workers after printing Doctor complete.. A crash at that point, such as the reported Windows assertion, makes the updater reject the candidate.

User Impact

Executable CLI commands drain shared-state databases and join their retained native-worker owner after plugin disposal. Candidate-Doctor history preserves the completion verdict even when a subsequent crash fills the output tail; nonzero and signal exits still fail the candidate.

Why This Change Was Made

Per-command cleanup closed agent resources but omitted whole-cache shared-state drainage and the default native-worker source. The missing shared-state drain is also present in v2026.9.8, whose reader pool retains idle workers after per-database cleanup. The fix calls those existing owners at the executable command boundary, after pending disposers finish. Embedded calls and Gateway work retain their caller-owned lifetimes.

Evidence

Real pnpm openclaw doctor --fix --non-interactive --no-workspace-suggestions on Linux/Node 24.19.0, with synthetic HOME, state/config/workspace, and a free Gateway port. An import hook recorded process.getActiveResourcesInfo(), native Worker events, the worker census, SQLite handles, and async-resource lifecycle at completion and exit.

Command-process exit observation Before After
Active resources API [] []
Live OpenClaw workers worker-native-lifecycle.worker.js []
Tracked native resources 1 Worker, 9 MessagePorts []
Open SQLite handles 0 0
Exit status on Linux 0 0

At Doctor complete., both builds still had the state-owner heartbeat and native supervisor; in the fixed build, both are gone by process exit. Unreferenced workers explain why the active-resources API alone missed the survivor. The Linux run proves the lifecycle gap and repair, not the reporter's exact Windows/Node 26.4.0 assertion.

  • Real-worker regression fails on the original cleanup: an open database and 2 surviving workers instead of 0. It passes after the fix, including a state read during plugin disposal and preservation of borrowed lifetimes.
  • Both changed test files passed three consecutive runs. The lifecycle test takes about 0.4s test time (13.7s file wall time, dominated by compiled-worker preparation); the existing 8-case canary suite takes about 10.6s test time / 12.2s wall time. The new assertions add no child-process fixtures.
  • Canary negative control fails on the original producer because saved crash detail omits Doctor complete.; the patched producer retains it without changing signal failure classification.
  • The 37 importer-file selection passed across 12 test projects in 223.90s; Windows-only cases remain skipped on Linux.
  • node scripts/check-changed.mjs --base bced15851945c3c460b48c03896701f9fa304536 passed: production types, all 27 core test type graphs, lint (0 warnings/errors), dead-export scans, and architecture guards (0 runtime import cycles).
  • P1 autoreview: no accepted/actionable findings.
  • The final runtime build and postbuild completed through pnpm openclaw in 39.5s before the post-fix Doctor proof.

Validation lease: tbx_01m4321tbkat178w11gt9sgwzf (Blacksmith Testbox), runner. The Linux lease has been stopped. Native Windows replay passed on this head: one executed Windows 2025 job, Node 24.19.0. The real-worker regression took 4.667s test time, 61.65s file wall time (90% transform), and 67.53s through the test wrapper. The exact Windows/Node 26.4.0 reporter environment remains unverified.

Resource-owner inventory
Resource Teardown owner and observation
Shared-state reader workers Whole-cache async database close retires the pool; per-database close only drains that database's resources.
Retained native supervisor, control and memory ports Existing native-source close joins retained domains, the supervisor, and its broker. This was the observed exit survivor.
SQLite snapshot staging workers and native-resource ports Retained staging owner settles requests and snapshots before its source joins.
Agent database execution/writer workers and lease heartbeat Existing Doctor scopes and CLI agent-database async cleanup retain their shutdown responsibility.
State-owner file-heartbeat worker and event port Visible at Doctor completion, gone by process exit in both recordings. It was introduced after the reported release.
Native SQLite handles and WAL maintenance Existing scoped cleanup plus the canonical whole-cache close; zero open handles in both command-process exit recordings.

Optional plugin native resources remain owned by plugin/harness/memory cleanup. The real Doctor fixture disabled plugins; importer tests exercised those cleanup siblings.

LOC: production +27/-4; tests +69/-0; docs +5/-0.

Drain shared-state databases and join the retained native worker source after
executable CLI plugin disposal. Preserve embedded and Gateway-owned lifetimes.
Keep Doctor's completion verdict in candidate diagnostics while preserving
failure classification for subsequent crashes.

Refs #164731.
@clawsweeper

clawsweeper Bot commented Oct 4, 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 docs Improvements or additions to documentation cli CLI command changes size: S labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 4, 2026, 5:56 AM ET / 09:56 UTC (Revision 2).

ClawSweeper review

What this changes

The PR drains shared database workers and joins retained native workers before executable CLI commands exit, and preserves Doctor completion diagnostics when a later crash fails an update.

Merge readiness

⛔ Needs changes before merge - 1 item remains

The repair remains useful: current main still omits this terminal cleanup, and no introduced correctness defect was found. The new Windows evidence addresses native cleanup coverage; the previously requested published-updater compatibility check remains outstanding.

Priority: P1
Reviewed head: f802f09091605675b25f154a7c466ac9b457e8df

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with strong real shutdown evidence and meaningful negative controls.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured Linux run exercises the real Doctor entrypoint and shows the native supervisor and ports absent after executable cleanup; the pinned Windows replay supplements native boundary coverage. Published-updater validation remains a separate repository gate. No stored-data format or migration contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Linux run exercises the real Doctor entrypoint and shows the native supervisor and ports absent after executable cleanup; the pinned Windows replay supplements native boundary coverage. Published-updater validation remains a separate repository gate. No stored-data format or migration contract changes.
Evidence reviewed 10 items Verified introduced patch: The pinned merge-base-to-head diff introduces only command cleanup, native-source cleanup exposure, completion diagnostics, associated regressions, and Doctor documentation. The verified test-merge comparison contains those same six paths, without the unrelated endpoint drift.
Existing ownership and cleanup order: The executable-only guard excludes embedded calls and Gateway boot. runCli releases plugin resources before returning through the new finally block, which waits for pending disposers, drains the canonical database cache, and closes the existing default native source without creating another owner.
Current-main necessity: Fetched main still returns directly from the command scope without whole-cache drainage or default-native-source closure. Its existing teardown helpers therefore do not already implement the requested executable-boundary repair.
Findings None None.
Security None None.

How this fits together

Executable CLI commands own resources acquired during command execution and plugin disposal. During updates, the updater runs the candidate’s Doctor and records its output and exit status before accepting the candidate.

flowchart TD
  A[Executable CLI command] --> B[Run command and Doctor checks]
  B --> C[Finish plugin disposal]
  C --> D[Drain shared database workers]
  D --> E[Join retained native workers]
  E --> F[Process exit]
  F --> G[Updater records diagnostics and exit status]
Loading

Before merge

  • Complete next step (P2) - Record the required published-updater × candidate compatibility result using existing operator state before merge.
Agent review details

Security

None.

PR surface

Source +23, Tests +69, Docs +5. Total +97 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 27 4 +23
Tests 2 69 0 +69
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 101 4 +97

Review metrics

None.

Technical review

Best possible solution:

Keep terminal shutdown in the executable CLI owner and confirm that a shipped updater accepts the repaired candidate using existing operator state.

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

Yes for the retained-worker lifecycle gap: current-main cleanup omits the terminal owners, and the captured real Doctor comparison demonstrates the survivor. The exact reported Windows assertion was not reproduced in this review.

Is this the best way to solve the issue?

Yes: invoking existing teardown owners after plugin disposal is a narrow repair that preserves borrowed lifetimes and crash failure classification; upgrade-boundary validation remains required.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A Doctor shutdown crash can reject an otherwise completed candidate and interrupt Windows updates.
  • 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. Sufficient (live_output): The captured Linux run exercises the real Doctor entrypoint and shows the native supervisor and ports absent after executable cleanup; the pinned Windows replay supplements native boundary coverage. Published-updater validation remains a separate repository gate. No stored-data format or migration contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Linux run exercises the real Doctor entrypoint and shows the native supervisor and ports absent after executable cleanup; the pinned Windows replay supplements native boundary coverage. Published-updater validation remains a separate repository gate. No stored-data format or migration contract changes.

Evidence

What I checked:

  • Verified introduced patch: The pinned merge-base-to-head diff introduces only command cleanup, native-source cleanup exposure, completion diagnostics, associated regressions, and Doctor documentation. The verified test-merge comparison contains those same six paths, without the unrelated endpoint drift. (src/cli/runtime-cleanup-scope.ts:77, f802f0909160)
  • Existing ownership and cleanup order: The executable-only guard excludes embedded calls and Gateway boot. runCli releases plugin resources before returning through the new finally block, which waits for pending disposers, drains the canonical database cache, and closes the existing default native source without creating another owner. (src/cli/runtime-cleanup-scope.ts:82, f802f0909160)
  • Current-main necessity: Fetched main still returns directly from the command scope without whole-cache drainage or default-native-source closure. Its existing teardown helpers therefore do not already implement the requested executable-boundary repair. (src/cli/runtime-cleanup-scope.ts:77, a0a1f184a386)
  • Released behavior: The latest supplied release, v2026.9.8, likewise lacks the added cleanup at this command boundary. Its Doctor environment builder already sets update markers; the patch adds no new updater handshake, configuration option, or stored-data contract. (src/cli/runtime-cleanup-scope.ts:77, fc23bc864e45)
  • Real Doctor shutdown evidence: The captured PR body reports before/after execution of the real Doctor command on Linux with Node 24.19.0 and synthetic state. The retained native supervisor, one Worker, and nine MessagePorts survive before the fix and are absent at fixed-process exit; SQLite handles are zero in both runs. This proves the lifecycle repair, rather than the exact Windows/Node 26.4.0 assertion. No local execution was performed during this review. (src/cli/runtime-cleanup-scope.ts:86, f802f0909160)
  • Native Windows replay: https://github.com/openclaw/openclaw/actions/runs/37193125930 completed successfully at the exact reviewed head. The jobs API confirms one executed Windows probe and successful exact-replay steps; the captured body identifies the real-worker cleanup regression on Windows 2025/Node 24.19.0. This is native cleanup-boundary coverage, not a demonstrated published-updater flow. Detailed log retrieval was blocked by the review environment’s storage-host allowlist. (src/cli/runtime-cleanup-scope.workers.test.ts:21, f802f0909160)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record a published-updater × candidate run against existing operator state, including the candidate Doctor exit and updater acceptance outcome.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-04T09:48:07.774Z sha f802f09 :: needs changes before merge. :: none

@steipete
steipete marked this pull request as ready for review October 4, 2026 09:51
@steipete
steipete merged commit 685fdc1 into main Oct 4, 2026
214 of 215 checks passed
@steipete
steipete deleted the upd/upd-windows-doctor-exit-uv-handle-closing branch October 4, 2026 10:10
steipete added a commit that referenced this pull request Oct 4, 2026
…164915)

Track deferred shared-state cleanup behind overdue plugin disposal and late writes without blocking the command. Reuse the existing five-second cleanup budget once ordered database and native-worker teardown can start. Verify actual worker joins instead of process-wide count equality.

Refs #164853 and hourly run 37200643847.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…164853)

Drain shared-state databases and join the retained native worker source after
executable CLI plugin disposal. Preserve embedded and Gateway-owned lifetimes.
Keep Doctor's completion verdict in candidate diagnostics while preserving
failure classification for subsequent crashes.

Refs openclaw#164731.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…penclaw#164915)

Track deferred shared-state cleanup behind overdue plugin disposal and late writes without blocking the command. Reuse the existing five-second cleanup budget once ordered database and native-worker teardown can start. Verify actual worker joins instead of process-wide count equality.

Refs openclaw#164853 and hourly run 37200643847.
RomneyDa pushed a commit that referenced this pull request Oct 5, 2026
Drain shared-state databases and join the retained native worker source after
executable CLI plugin disposal. Preserve embedded and Gateway-owned lifetimes.
Keep Doctor's completion verdict in candidate diagnostics while preserving
failure classification for subsequent crashes.

Refs #164731.

(cherry picked from commit 685fdc1)
RomneyDa pushed a commit that referenced this pull request Oct 5, 2026
…164915)

Track deferred shared-state cleanup behind overdue plugin disposal and late writes without blocking the command. Reuse the existing five-second cleanup budget once ordered database and native-worker teardown can start. Verify actual worker joins instead of process-wide count equality.

Refs #164853 and hourly run 37200643847.

(cherry picked from commit 138b606)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. 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.

1 participant