Repository navigation
fix(doctor): shut down lifecycle workers before the command exits - #164853
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. Reviewed October 4, 2026, 5:56 AM ET / 09:56 UTC (Revision 2). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherExecutable 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +23, Tests +69, Docs +5. Total +97 across 6 files. View PR surface stats
Review metricsNone. Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…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.
…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.
…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.
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)
…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)
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-suggestionson Linux/Node 24.19.0, with synthetic HOME, state/config/workspace, and a free Gateway port. An import hook recordedprocess.getActiveResourcesInfo(), native Worker events, the worker census, SQLite handles, and async-resource lifecycle at completion and exit.[][]worker-native-lifecycle.worker.js[][]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.Doctor complete.; the patched producer retains it without changing signal failure classification.node scripts/check-changed.mjs --base bced15851945c3c460b48c03896701f9fa304536passed: production types, all 27 core test type graphs, lint (0 warnings/errors), dead-export scans, and architecture guards (0 runtime import cycles).pnpm openclawin 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
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.