Skip to content

fix(update): restore managed Gateway after updater process death - #186341

Closed
steipete wants to merge 4 commits into
mainfrom
codex/issue-164800-helper
Closed

steipete wants to merge 4 commits into
mainfrom
codex/issue-164800-helper

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Refs #164800. Supersedes #186328; this draft combines the helper and repair lanes.

What Problem This Solves

Fixes a managed Gateway remaining stopped when its updater is killed before, during, or after package publication, including when the updater itself stopped the service.

User Impact

The live helper settles the interrupted update and restores a verified Gateway. If the helper also dies, openclaw update repair can recover promptly and restart the Gateway the update left stopped. Operator stops, lost ownership, named data risk, and unverifiable runtime identity still prevent automatic restart.

Why This Change Was Made

The live Linux reproduction exposed two related ownership gaps. The helper only armed restoration when it parked the service through the foreground protocol; the normal native updater stops systemd itself (update-command-service-maintenance.ts:618). Its SIGKILL therefore reached the old “no verified recovery result” branch. Standalone repair also only recognized the helper's service-stop step. Dead handoff owners could additionally retain the 45-minute recovery grace.

Both recovery paths now consume findUpdateGatewayStop in src/infra/update-run-gateway-stop.ts. It recognizes the helper's stop, or a managed handoff followed by activation with the service currently stopped. The existing completed managed-service update handoff receipt is written by both Gateway update.run (src/gateway/server-methods/update.ts:546) and automatic updates (src/infra/update-startup-auto-run.ts:379), so it remains usable after target selection changes installationMethod to npm-global. The initial update.run running snapshot is not a restart receipt. Later incoming running observations after activation persist the existing service-running receipt; those receipts, replacement boot/settled verification, completed managed restarts, and newer settled runs retire the stop. These receipts survive ledger compaction. No new stop protocol, ledger schema, or updater-side stop receipt is needed.

The helper uses its staged runtime to retain bookkeeping while the installed tree is missing. It cancels untouched publication preparation; once displacement begins it completes publication forward through the sealed publication owner, runs the installed post-core finalizer as this run's continuation, then uses gateway restart --preserve-definition --json and verifies readiness/version/build identity. Updater-stopped recovery does not require the helper-only parked systemd generation. History records rollback, success with recovery, or failure with repair/deep-status guidance.

Repair reclaims promptly only when the recorded owners are proven dead; live/unknown owners and descendant/runtime-holder fences remain. After finalization, it uses the same stop evidence to start and verify an update-stopped service while preserving later operator stops.

Rejected alternatives: treating a signal as an unrecoverable result; inferring restart permission solely from an inactive unit; requiring a new native-stop receipt from an older installed driver; importing bookkeeping from the package while it is being swapped; and adding a second helper/repair stop policy. The combined change retains one publication owner and one stop-evidence reader.

LOC against base 4daeb9252ce: production +800/−235; tests/support +764/−73; docs +76/−12; total +1640/−320 across 39 files. The required growth covers sealed crash recovery, standalone service restoration, and their boundary proof. Simplification removed the repair-only stop inference and reuses existing durable handoff evidence.

Evidence

  • Focused tests: 364 tests across 16 files passed, including all nine SIGKILL/publication cases, native-stop group-death repair, operator-stop negatives, data-risk refusals, systemd/launchd recovery, lifecycle/terminal outcomes, and ledger receipt/interruption coverage. The full run initially found seven stale termination-harness source lookups; removing the duplicate lookup and rerunning that file passed all seven. Production was unchanged for that rerun.
  • Red/green: with production temporarily reverted to pre-follow-up merge cc34e4ae6ea, five helper regressions, two repair regressions, and two compaction regressions failed. Native-stop fixtures include the real entry point's initial serviceRunning: true snapshot. The base reproduced the old no-verified-result branch and the missing installed-runtime failure during publication. Production was restored with SHA-256 verification; all corresponding tests pass on this change. A separate interim run also proved that the initial running snapshot suppressed recovery before its fix (three helper and two repair failures).
  • Build/checks: packaged runtime build passed (2m22s), including CLI bootstrap and Doctor closure checks. oxfmt --check, oxlint, line-cap ratchet, and git diff --check passed for the changed files.
  • Typecheck limitation: the requested node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo stops before source checking with Declaration input escapes checkout for tsrs in the prescribed external pnpm virtual store. The checkout containment guard was preserved; this is not a passing typecheck.
  • Autoreview: Codex local review of the complete combined diff against 4daeb9252ce finished scoped-clean (P0–P2), with no accepted/actionable findings. A fresh final pass included the termination-harness fix.
Focused test command
node scripts/run-vitest.mjs \
  src/infra/update-managed-service-handoff-interrupted.test.ts \
  src/cli/update-cli/update-repair-service.test.ts \
  src/infra/update-run-ledger.compaction.test.ts \
  src/cli/update-cli/update-repair-command.test.ts \
  src/cli/update-cli/update-command-finalize-refusal.test.ts \
  src/infra/update-managed-service-handoff-recovery.test.ts \
  src/infra/update-managed-service-handoff-lifecycle.test.ts \
  src/infra/update-managed-service-handoff-recovery-systemd.test.ts \
  src/infra/update-managed-service-handoff-recovery-launchd.test.ts \
  src/infra/update-managed-service-handoff-triage.test.ts \
  src/infra/update-managed-service-handoff-terminal-result.test.ts \
  src/infra/update-managed-service-handoff-termination.test.ts \
  src/infra/update-managed-service-handoff-command.test.ts \
  src/infra/update-run-ledger.test.ts \
  src/infra/update-run-capture-receipts.test.ts \
  src/infra/update-run-interruption.worker.test.ts \
  --maxWorkers=1

The termination file was rerun with the same runner after fixing its stale lookup. The existing manager/lifecycle suites exercise process startup, publication, cancellation, and lease custody and take longer than unit-only tests.

The helper boundary uses real SIGKILL children, package publication journals, ledger writes, and native lease custody, with synthetic native-manager/readiness/finalizer I/O. The repair boundary runs the registered CLI with real ledger and dead-handoff reclamation. This is not a fresh live Linux/systemd upgrade result; the AWS reproduction still needs to be rerun against this head.

Let repair bypass custody grace for positively dead owners while preserving descendant checks. Restore gateways stopped by interrupted managed updates, retain startup evidence across readiness failures, and preserve later operator stops.

Refs #164800.
Keep handoff bookkeeping in the staged runtime and recover from recorded publication and generation state after an updater signal or missing result. Finalize verified candidates under the same run, restart through the guarded helper path, and retain actionable terminal refusals for unsafe recovery.

Refs #164800.
@clawsweeper

clawsweeper Bot commented Oct 27, 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 size: L labels Oct 27, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 1366b0a3996df8740be653cfc6ffe1035dc63eea, but the PR head is now 85bffe07970e5843de6e76ce8268b839f2c25343. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (1 earlier review cycle)
  • reviewed 2026-10-27T21:58:43.237Z sha 1366b0a :: needs real behavior proof before merge. :: [P1] Preserve the foreground ownership validator during the ledger cutover

@steipete steipete changed the title fix: restore managed Gateway after an interrupted updater fix(update): restore managed Gateway after updater process death Oct 27, 2026
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XL and removed size: L labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: applying reviewed decision.

I am applying the reviewed decision for this pull request: fix(update): restore managed Gateway after updater process death This is item 1/1 in the current shard. Shard 1/1.

This transient lease prevents a newer review from overlapping label, comment, or close mutations.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 29, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Superseded by #188497, which consolidates this draft and its sibling onto current main and adds the live Crabbox proof.

@steipete steipete closed this Oct 30, 2026
@steipete
steipete deleted the codex/issue-164800-helper branch November 2, 2026 06:30
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. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant