Skip to content

fix(update): update repair fails after Doctor completes on busy macOS hosts - #170779

Merged
steipete merged 2 commits into
mainfrom
steipete/process-group-exit-confirmation
Oct 13, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/process-group-exit-confirmation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw update repair (and the QA packaged bootstrap that uses it) fails with "Updated pre-plugin Doctor failed: … Command cleanup could not confirm that owned work stopped" on a busy macOS host, even though Doctor finished its work.

User Impact

User impact: updates and Doctor runs on loaded macOS hosts no longer fail just because a force-killed helper process took more than 300 ms to finish exiting, and the updater no longer risks a false "Doctor processes remain unsettled, data-at-risk" refusal for the same reason. Normal cleanup is not slower: confirmation still returns the moment the process group is gone. Tradeoff: a process group that genuinely survives SIGKILL is now reported as uncertain after up to 10 s instead of 300 ms.

Why This Change Was Made

When a command scope closes, it SIGKILLs any owned process group that is still observable and then confirms the group is gone. That confirmation reused the 300 ms TERM→KILL grace as its deadline, but post-SIGKILL teardown and zombie reaping are unrelated to the cooperative grace. On macOS, kill(-pgid, 0) reports EPERM rather than ESRCH while a group holds only unreaped zombies, which we correctly treat as alive, so under load the 300 ms window expires before the kernel finishes.

Post-kill confirmation now has one owner, waitForCommandProcessGroupExit in src/process/exec-spawn.ts, with its own 10 s budget. The scoped-command settle, the runner's forced termination, and the updater's custody settlement use it instead of three private 300 ms loops. Pre-kill identity checks, error messages, and Windows paths are unchanged. 300 ms remains the TERM→KILL grace.

Evidence

  • Root cause from preserved runs: in two failing update repair runs (one from the original report, one reproduced on this branch's parent with node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts extensions/qa-lab/src/session-host-command-state.real-gateway.e2e.test.ts), Doctor printed "Doctor complete." and wrote its clean-close receipt, then failed its final scope settlement. 70–200 ms later the parent updater's custody settlement logged "every tracked process group stopped". The groups did exit; the deadline was too short.
  • macOS behavior: a small local probe confirmed kill(-pgid, 0) returns EPERM for a zombie-only process group. Temporary instrumentation of the e2e (not committed) showed the groups being confirmed at Doctor stop time were short launchctl probes already in the zombie (Z <defunct>) state, not live work.
  • Regression tests: exec-scope-settlement.test.ts and command-process-custody.test.ts each hold a killed group in the EPERM state for 1 s before it disappears. Both fail on the previous code (scope settlement rejects with CommandProcessCleanupError; custody settlement returns settled: false) and pass now.
  • Focused tests: pnpm test src/process/exec-scope-settlement.test.ts src/process/command-process-custody.test.ts src/process/exec-termination.test.ts src/process/exec-termination.liveness.test.ts src/process/scoped-child-reaper.test.ts src/process/exec.test.ts --maxWorkers=1 → 72/72 passed, 44 s wall on a loaded host. The new regression tests run in under 10 ms each on fake timers. A broader consumer run (17 files incl. update custody, spawn broker, proxy, sessions exec) passed 196/196.
  • Static checks: pnpm tsgo:core, core test typecheck shards, oxlint, oxfmt, git diff --check clean.
  • Gap: a post-fix live e2e run on the same host could not give a verdict. The Vitest worker itself stalled in the kernel "exiting" state for ~7 minutes (host degradation unrelated to this change), so PR CI is the broad proof. The flake is intermittent; the deterministic proof is the regression tests above.
Not changed here
  • The "Shared-state WAL maintenance failed … undergoing offline maintenance" warnings seen in the same logs come from the parent update process's idle connection while the Doctor child holds offline maintenance. The refusal is correct and did not contribute to this failure; quieting it is tracked separately.
  • The 180 s test timeouts seen on some isolated reruns are a test-budget-under-load issue, not this bug.

`openclaw update repair` could fail on a loaded macOS host with
"Updated pre-plugin Doctor failed: ... Command cleanup could not confirm
that owned work stopped" even though Doctor had completed. Doctor's final
command-scope settlement SIGKILLs any owned process group that is still
observable and then waited only COMMAND_PROCESS_TREE_KILL_GRACE_MS (300 ms)
for the group to disappear. That constant is the cooperative TERM->KILL
grace; post-SIGKILL teardown and orphan reaping is unrelated and unbounded on
busy hosts. On macOS kill(-pgid, 0) reports EPERM rather than ESRCH while a
group holds only unreaped zombies, which isChildProcessTreeAlive rightly
treats as alive. In two preserved failing runs the parent's custody
settlement proved every tracked group extinct 70-200 ms after Doctor gave
up; the same 300 ms budget there could also have produced a false
"Doctor processes remain unsettled, data-at-risk" refusal.

waitForCommandProcessGroupExit in exec-spawn.ts is now the single owner of
post-kill confirmation with a dedicated 10 s budget
(COMMAND_PROCESS_GROUP_EXIT_CONFIRMATION_MS). Polling still ends as soon as
the group is gone, so normal cleanup is unchanged; only a group that truly
survives SIGKILL now reports uncertain after 10 s instead of 300 ms. The
scoped-command settle, the runner's forced termination and the custody
settlement drop their private 300 ms loops; pre-kill identity checks, error
messages and Windows paths are unchanged, and the Linux adopted-zombie
reaper registration now outlives the new confirmation window.

Regression tests hold a killed group in the macOS zombie (EPERM) state for
1 s before it disappears; both fail on the previous code (scope settlement
rejects with CommandProcessCleanupError, custody settlement returns
settled: false) and pass now.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review October 13, 2026 07:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T07:29:27.154942Z 64b0346 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Advance the Linux extension cleanup fixture by the shared post-SIGKILL confirmation budget and prune its obsolete mock-export baseline entry. CI run 38362642640 exposed both stale test artifacts. Production behavior is unchanged.
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 13, 2026
@steipete
steipete merged commit 69197e7 into main Oct 13, 2026
120 checks passed
@steipete
steipete deleted the steipete/process-group-exit-confirmation branch October 13, 2026 08:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Oct 13, 2026
* commit '7ae69497bec4d9c37f170f046a3cbbf954ff19a7': (6238 commits)
  refactor(ui): replace Systems filters with native menu (#170786)
  fix(browser): browser open honors timeoutMs for its opening navigation (#170053)
  refactor: deslop old Apple shared/macOS and Control UI code (#170823)
  perf(memory): reuse pooled origin readers (#170795)
  fix(crabbox): preserve project snapshots across runtime updates (#170780)
  fix: prevent chat image loading from shifting messages (#170819)
  refactor(ui): use native menus for Secret Store actions (#170663)
  fix(gateway): keep chat metadata available during model reloads (#170805)
  fix: preserve diagnostics for unresponsive state lease heartbeats (#170835)
  fix(test): prepare runtime config for corpus revision proof
  test: give credential fixtures database ownership
  perf(auth): unblock session writes during health preparation (#170807)
  fix(ci): use smaller runners for selected Gateway client tests (#170821)
  fix: use same-commit plugins in development macOS builds (#170776)
  perf(github): share cached reads across sessions and searches (#170825)
  fix(projects): keep listings stable during unrelated session changes (#170824)
  fix(update): update repair fails after Doctor completes on busy macOS hosts (#170779)
  fix(heartbeat): suppress truncated NO_REPLY finals such as NO_R (#170190)
  perf(sessions): reduce read transaction overhead (#170745)
  refactor: simplify older plugin and package lifecycles (#170800)
  ...
RomneyDa pushed a commit that referenced this pull request Oct 14, 2026
Backport #170779 for the post-Doctor cleanup flake in #171470.
Separate cooperative termination grace from post-SIGKILL extinction
confirmation across command scopes, runner cleanup, and recorded process
custody while preserving uncertain settlement and identity checks.

Keep the main-only extension cleanup test absent from the release branch.

(cherry picked from commit 69197e7)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
… hosts (openclaw#170779)

* fix(process): give force-killed command groups time to finish exiting

`openclaw update repair` could fail on a loaded macOS host with
"Updated pre-plugin Doctor failed: ... Command cleanup could not confirm
that owned work stopped" even though Doctor had completed. Doctor's final
command-scope settlement SIGKILLs any owned process group that is still
observable and then waited only COMMAND_PROCESS_TREE_KILL_GRACE_MS (300 ms)
for the group to disappear. That constant is the cooperative TERM->KILL
grace; post-SIGKILL teardown and orphan reaping is unrelated and unbounded on
busy hosts. On macOS kill(-pgid, 0) reports EPERM rather than ESRCH while a
group holds only unreaped zombies, which isChildProcessTreeAlive rightly
treats as alive. In two preserved failing runs the parent's custody
settlement proved every tracked group extinct 70-200 ms after Doctor gave
up; the same 300 ms budget there could also have produced a false
"Doctor processes remain unsettled, data-at-risk" refusal.

waitForCommandProcessGroupExit in exec-spawn.ts is now the single owner of
post-kill confirmation with a dedicated 10 s budget
(COMMAND_PROCESS_GROUP_EXIT_CONFIRMATION_MS). Polling still ends as soon as
the group is gone, so normal cleanup is unchanged; only a group that truly
survives SIGKILL now reports uncertain after 10 s instead of 300 ms. The
scoped-command settle, the runner's forced termination and the custody
settlement drop their private 300 ms loops; pre-kill identity checks, error
messages and Windows paths are unchanged, and the Linux adopted-zombie
reaper registration now outlives the new confirmation window.

Regression tests hold a killed group in the macOS zombie (EPERM) state for
1 s before it disappears; both fail on the previous code (scope settlement
rejects with CommandProcessCleanupError, custody settlement returns
settled: false) and pass now.

* test(process): align cleanup fixtures with exit confirmation

Advance the Linux extension cleanup fixture by the shared post-SIGKILL confirmation budget and prune its obsolete mock-export baseline entry. CI run 38362642640 exposed both stale test artifacts. Production behavior is unchanged.
RomneyDa added a commit that referenced this pull request Oct 14, 2026
Backport #170779 for the post-Doctor cleanup flake in #171470.
Separate cooperative termination grace from post-SIGKILL extinction
confirmation across command scopes, runner cleanup, and recorded process
custody while preserving uncertain settlement and identity checks.

Keep the main-only extension cleanup test absent from the release branch.

(cherry picked from commit 69197e7)

Co-authored-by: Peter Steinberger <[email protected]>
vincentkoc added a commit that referenced this pull request Oct 18, 2026
* feat(qa): report scorecard evidence gaps

Distinguish catalog coverage, recorded attempts, and qualified evidence without changing scores or release gates.

Include the canonical compatibility migration-status correction from ec1fb60.

Co-authored-by: Patrick Erichsen <[email protected]>

* chore(qa): drop compatibility backport already on main

Keep the QA evidence-gap change scoped to its 13 paths. The canonical compatibility correction ec1fb60 and later refinements are already on main; restore the six branch preimages so the merge consumes that upstream owner state.

* chore(qa): integrate canonical worker settlement fixes

* commit '7ae69497bec4d9c37f170f046a3cbbf954ff19a7': (6238 commits)
  refactor(ui): replace Systems filters with native menu (#170786)
  fix(browser): browser open honors timeoutMs for its opening navigation (#170053)
  refactor: deslop old Apple shared/macOS and Control UI code (#170823)
  perf(memory): reuse pooled origin readers (#170795)
  fix(crabbox): preserve project snapshots across runtime updates (#170780)
  fix: prevent chat image loading from shifting messages (#170819)
  refactor(ui): use native menus for Secret Store actions (#170663)
  fix(gateway): keep chat metadata available during model reloads (#170805)
  fix: preserve diagnostics for unresponsive state lease heartbeats (#170835)
  fix(test): prepare runtime config for corpus revision proof
  test: give credential fixtures database ownership
  perf(auth): unblock session writes during health preparation (#170807)
  fix(ci): use smaller runners for selected Gateway client tests (#170821)
  fix: use same-commit plugins in development macOS builds (#170776)
  perf(github): share cached reads across sessions and searches (#170825)
  fix(projects): keep listings stable during unrelated session changes (#170824)
  fix(update): update repair fails after Doctor completes on busy macOS hosts (#170779)
  fix(heartbeat): suppress truncated NO_REPLY finals such as NO_R (#170190)
  perf(sessions): reduce read transaction overhead (#170745)
  refactor: simplify older plugin and package lifecycles (#170800)
  ...

* fix(gateway): preserve safe previews and no-op bindings

Clear only the matching pending binding operation after an authoritative unchanged settlement, preserving committed and unknown invalidation fences.

Include the canonical managed-media preview correction from 47ba0ae.

Co-authored-by: Peter Steinberger <[email protected]>

* merge(main): reconcile QA reporting with frozen main

* test(gateway): verify retained route authority after binding settlement

Co-authored-by: Patrick Erichsen <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
* feat(qa): report scorecard evidence gaps

Distinguish catalog coverage, recorded attempts, and qualified evidence without changing scores or release gates.

Include the canonical compatibility migration-status correction from 3f6d26f.

Co-authored-by: Patrick Erichsen <[email protected]>

* chore(qa): drop compatibility backport already on main

Keep the QA evidence-gap change scoped to its 13 paths. The canonical compatibility correction 3f6d26f and later refinements are already on main; restore the six branch preimages so the merge consumes that upstream owner state.

* chore(qa): integrate canonical worker settlement fixes

* commit '4ae87487b6eca95ac58a2f18de0e742b240772eb': (6238 commits)
  refactor(ui): replace Systems filters with native menu (openclaw#170786)
  fix(browser): browser open honors timeoutMs for its opening navigation (openclaw#170053)
  refactor: deslop old Apple shared/macOS and Control UI code (openclaw#170823)
  perf(memory): reuse pooled origin readers (openclaw#170795)
  fix(crabbox): preserve project snapshots across runtime updates (openclaw#170780)
  fix: prevent chat image loading from shifting messages (openclaw#170819)
  refactor(ui): use native menus for Secret Store actions (openclaw#170663)
  fix(gateway): keep chat metadata available during model reloads (openclaw#170805)
  fix: preserve diagnostics for unresponsive state lease heartbeats (openclaw#170835)
  fix(test): prepare runtime config for corpus revision proof
  test: give credential fixtures database ownership
  perf(auth): unblock session writes during health preparation (openclaw#170807)
  fix(ci): use smaller runners for selected Gateway client tests (openclaw#170821)
  fix: use same-commit plugins in development macOS builds (openclaw#170776)
  perf(github): share cached reads across sessions and searches (openclaw#170825)
  fix(projects): keep listings stable during unrelated session changes (openclaw#170824)
  fix(update): update repair fails after Doctor completes on busy macOS hosts (openclaw#170779)
  fix(heartbeat): suppress truncated NO_REPLY finals such as NO_R (openclaw#170190)
  perf(sessions): reduce read transaction overhead (openclaw#170745)
  refactor: simplify older plugin and package lifecycles (openclaw#170800)
  ...

* fix(gateway): preserve safe previews and no-op bindings

Clear only the matching pending binding operation after an authoritative unchanged settlement, preserving committed and unknown invalidation fences.

Include the canonical managed-media preview correction from f3260b9.

Co-authored-by: Peter Steinberger <[email protected]>

* merge(main): reconcile QA reporting with frozen main

* test(gateway): verify retained route authority after binding settlement

Co-authored-by: Patrick Erichsen <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant