Repository navigation
fix: stop an update before installing when a running Gateway blocks its database migration - #203170
Conversation
… the state A package update that needs a shared or agent database migration hands that migration to the candidate Doctor, which needs exclusive maintenance. When the updater does not stop the Gateway that owns the state (--no-restart, a non-default OPENCLAW_HOME/OPENCLAW_STATE_DIR profile, an externally supervised Gateway), Doctor cannot enter maintenance, the final schema check fails after activation, and the update rolls the package back after minutes of work. After the updater's own service stop and before any package mutation, refuse when a live Gateway still owns the state and the activation baseline has a store the candidate must migrate. The refusal names the stores, their schema hop and the Gateway PID. Updates that need no migration keep working under a live Gateway. The pending-migration rule is now shared with the final schema check. Refs #202700
|
🦞👀 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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbed57e7fb
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await assertPendingMigrationsAdmitted({ | ||
| pendingMigrations: activationSchemas.pendingMigrations, |
There was a problem hiding this comment.
Update the native-maintenance fixture for the new admission call
On Linux/macOS, the authorized activation-helper cases in update-command-service-maintenance-native.test.ts reach this new call, but update-command-service-maintenance-native.test-support.ts mocks the entire schema module without exporting assertPendingMigrationsAdmitted. Vitest therefore throws a missing-export error after the native service stop, and the fixture's finalizer rethrows the failed update instead of satisfying await pending. Update that mock and its activation-schema result to include the new admission contract so the existing service-authority regression tests remain runnable.
AGENTS.md reference: AGENTS.md:L84-L84
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesThis PR refuses package replacement when a running Gateway prevents a required database migration. Example: Run openclaw update --no-restart with a foreground Gateway and an external agent database at schema 38 while the candidate requires 43.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-authored PR addresses a reproduced update failure, but its new admission call breaks the native-maintenance regression fixture and fails CI. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe CLI update executor validates a candidate, inventories database schemas, and stops managed services before package activation; candidate Doctor owns migration, and final verification checks its result. flowchart TD
A[Update CLI] --> B[Candidate validation]
B --> C[Database schema inventory]
C --> D[Managed service stop]
D --> E[Pending migration admission]
E --> F[Package activation]
F --> G[Doctor and final verification]
Technical reviewBest possible solution: Retain the shared migration predicate and pre-replacement check, and update the native-maintenance fixture to satisfy the new admission contract. Do we have a high-confidence way to reproduce the issue? The linked report gives an installed-package reproduction with successful offline controls, the PR reports matching live runs, and source inspection confirms the late migration failure; this review executed no target code. Is this the best way to solve the issue? The focused solution uses the existing inventory and verified Gateway identity after the updater's own stop, preserves final verification, and avoids introducing another migration or custody owner. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f4ef065b92f1. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +64, Tests +66, Docs +10. Total +140 across 6 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 21, 2026, 11:32 AM ET / 16:32 UTC. |
…vice runs An owned service is stopped by the updater, or under --no-restart its supervisor restarts the Gateway on the replaced package; keep that flow as it was. Update the native-maintenance test mock for the new schema export.
|
Merged via squash.
|
…ts database migration (openclaw#203170) * fix(update): refuse migrating updates while an unstopped Gateway owns the state A package update that needs a shared or agent database migration hands that migration to the candidate Doctor, which needs exclusive maintenance. When the updater does not stop the Gateway that owns the state (--no-restart, a non-default OPENCLAW_HOME/OPENCLAW_STATE_DIR profile, an externally supervised Gateway), Doctor cannot enter maintenance, the final schema check fails after activation, and the update rolls the package back after minutes of work. After the updater's own service stop and before any package mutation, refuse when a live Gateway still owns the state and the activation baseline has a store the candidate must migrate. The refusal names the stores, their schema hop and the Gateway PID. Updates that need no migration keep working under a live Gateway. The pending-migration rule is now shared with the final schema check. Refs openclaw#202700 * fix(update): accept an unbounded activation deadline in the migration owner check * docs(update): explain the migration refusal under an unstopped Gateway * fix(update): exclude retained agent stores from the migration owner check * refactor(update): tighten the migration owner check * fix(update): limit the migration owner check to Gateways no owned service runs An owned service is stopped by the updater, or under --no-restart its supervisor restarts the Gateway on the replaced package; keep that flow as it was. Update the native-maintenance test mock for the new schema export. * fix(update): exempt only a running owned service from the migration owner check * test(update): keep real schema exports in the native-maintenance mock Co-authored-by: Peter Steinberger <[email protected]>
…age is replaced in place (#203185) A Gateway whose package is replaced in place (for example `openclaw update --no-restart` with a running Gateway, or a manual npm install over it) lost its restart markers at the next shutdown: since #185730 (first shipped 2026.11.5) shutdown imported session-restart-resume and subagent-registry only at close, and on a release-to-release swap those chunks are gone (ERR_MODULE_NOT_FOUND). Interrupted sessions then were not resumed. The existing shutdown owner, prepareGatewayShutdownRuntime, now retains both module namespaces at startup and close calls through them, restoring the #160674 contract that shutdown never first-imports code. Docs note that running 2026.11.5/2026.11.6 Gateways keep the limitation for their next in-place replacement. Proof: kernel regression test red on base / green; Crabbox live rotate lanes (all hashed chunks removed, SIGTERM) show session-restart-resume import failures 11.6=3, base=5, fix=0. Other late loads in the same class (state worker restart-lifecycle, memory-core runtime-provider, temp-artifact-cleanup, supervisor) remain and are tracked separately. Refs #202700 Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 061fd34) Companions: #203241 is selected next in this lane for other late shutdown imports. #203170 guards database migration admission, not marker persistence. Later docs-only overlaps describe independent update UI, recovery, activation, package, advisory, service, or platform contracts; none supplies a dependency of the retained shutdown namespaces. Co-authored-by: RomneyDa <[email protected]>
…tate database (#203578) * fix(update): refuse migrating updates while a node service keeps the state open Refs #203457 * docs(update): explain the node-service migration refusal Refs #203457 * fix(update): match the node service's own state directory by filesystem identity A default node service omits the state selector and must not inherit the updater's; path aliases name one directory. Refs #203457 * fix(update): refuse every activation while a node service keeps the state open Update Doctor takes native exclusion of openclaw.sqlite on every activation, including patch updates without a schema change (#203457 reported 2026.11.5 -> 2026.11.6, both schema 36). Refuse whenever a running, kind-marked node service resolves to the same state directory, not only for pending migrations. Refs #203457 Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 19fcba1) Release adaptation: retain stable captureUpdateActivationSchemas destructuring and check node ownership only before first mutation, so Git revalidation after mutation does not report a pre-mutation refusal. Keep stable preparatory staging and check before any Gateway stop or installed activation. Release adaptation: keep only the node-service docs and regression in the conflict regions; the separate Gateway migration admission (#203170) is not a prerequisite and remains outside the lane. Companion audit: no later PR or SHA mentions through 665c286. #203497 (future package preparation) is not needed; the existing stable package/Git activation hooks already share the pre-stop boundary. #203981 is selected elsewhere and already present at lane base (f6ad5b5). Later #204275, #204253, #204224, #204127, #204094, #204095, #204151, #204054, #203994, #203990, #203917, #203959, #203926, #203925, #203915, #203914, #202934 and #203735 are not applicable as companions: independent Git, rollback, Doctor/recovery, plugin, output, docs and host changes do not supply or consume node-service admission. Validation: two same-state activation cases red on f6ad5b5 (wrongly reached mutation), three controls passed; all 73 tests in update-command-execution.test.ts passed with the fix. Co-authored-by: RomneyDa <[email protected]>
…ts database migration (#203170) * fix(update): refuse migrating updates while an unstopped Gateway owns the state A package update that needs a shared or agent database migration hands that migration to the candidate Doctor, which needs exclusive maintenance. When the updater does not stop the Gateway that owns the state (--no-restart, a non-default OPENCLAW_HOME/OPENCLAW_STATE_DIR profile, an externally supervised Gateway), Doctor cannot enter maintenance, the final schema check fails after activation, and the update rolls the package back after minutes of work. After the updater's own service stop and before any package mutation, refuse when a live Gateway still owns the state and the activation baseline has a store the candidate must migrate. The refusal names the stores, their schema hop and the Gateway PID. Updates that need no migration keep working under a live Gateway. The pending-migration rule is now shared with the final schema check. Refs #202700 * fix(update): accept an unbounded activation deadline in the migration owner check * docs(update): explain the migration refusal under an unstopped Gateway * fix(update): exclude retained agent stores from the migration owner check * refactor(update): tighten the migration owner check * fix(update): limit the migration owner check to Gateways no owned service runs An owned service is stopped by the updater, or under --no-restart its supervisor restarts the Gateway on the replaced package; keep that flow as it was. Update the native-maintenance test mock for the new schema export. * fix(update): exempt only a running owned service from the migration owner check * test(update): keep real schema exports in the native-maintenance mock Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 3f1a422) Release adaptation: Use the same migration inventory for before/after package activation, retain the stable node-service exclusion check and preserve rollback evidence if activation may have touched state. No Git release activation API. Companion audit: PR #202700 is the source. Stable node-host ownership is independent and preserved; no Git launcher cutover required. Co-authored-by: RomneyDa <[email protected]>
Related: #202700
What Problem This Solves
When
openclaw updatemust migrate a database, the new version's Doctor needs the Gateway stopped. A Gateway that the updater does not manage as a service keeps running through the update, for example a foregroundopenclaw gateway rununder a customOPENCLAW_HOME/OPENCLAW_STATE_DIRprofile, or one under an external supervisor. With such a Gateway, the update installed the new package and spent minutes on it. Doctor then could not get exclusive access, the final schema check failed, and the update put the previous version back.User Impact
User impact: an update that cannot migrate while that Gateway runs now stops before replacing anything. Its message names each database with its schema change (for example
38 -> 43) and the Gateway PID, and says to stop the Gateway and rerunopenclaw update. Updates that need no migration still run while the Gateway serves. A running service the updater owns is unaffected; the updater stops it, or under--no-restartits supervisor restarts it on the new package.Why This Change Was Made
The updater already records each store's schema before activation. It now checks, right after its own service stop and before any package mutation, whether a live Gateway still owns the state while a store needs migration. A running owned service is exempt: the state lock allows only one owner, so that owner is the service. A stopped owned service does not exempt a separate foreground Gateway. That rule ("which stores must the candidate Doctor migrate") was previously inline in the final post-activation check. It now lives in one shared helper used by both checks, so the two can't drift. Both checks apply the same agent-store discovery and the same exclusion of retained (deleted-agent) stores.
Production growth (+121/−50) is required behavior plus that single shared rule. Managed-service admission would be a smaller place for the check, but it runs before candidate validation and before the updater's own stop. There it can't know which stores need migration, or whether a managed owner is about to be released. Activation after the stop is the one point where both facts exist.
Evidence
Live on Crabbox Linux (AWS), using the reporter's setup: a custom
OPENCLAW_HOME/OPENCLAW_STATE_DIRprofile, a foregroundgateway run, and an external registered agent store restored from published 2026.11.6 at schema 38. Mainb8b06c4824fwas relabeled 2026.11.30/.31; this branch was built as 2026.11.29.--no-restartAgent database migration did not finish … expected schema 43, found 38, rolled back to the previous version--no-restartdatabase-migration-owner-live; no package replacement; installed version unchanged; Gateway still serving (/readyz200); store still at 38/readyz200, so no false refusal after the updater's own stopRegression test
admits activation only when Doctor can migrateinupdate-command-execution.test.tscovers six cases:origin/mainand green with the fix.Targeted typecheck (
tsgo:core), oxlint, and oxfmt pass. Touched and consumer update tests pass locally, except the process-lane rows that require a builtdistworker. Those rows fail identically onorigin/mainin a fresh worktree, so CI covers them.The live lanes ran on
eff70f301bd. Later commits only narrowed the exemption for running owned services. That change does not affect the custom-profile lanes, which have no owned verdict. The managed lane now skips a check that it previously passed after the service stop.Reviews: autoreview is scoped-clean (P0–P2) on
022bf8a91d4. Independent Codex read-only reviews found three problems, all addressed. Two are fixed here: retained agent stores were missing from the activation read, and a stopped owned service could exempt a separate foreground Gateway. The third is declined under the AGENTS.md compromises. It is a running managed Gateway blocked behind a foreground Gateway from another installation, which needs two Gateways on one state. That case keeps today's visible install-then-rollback, and proving which process owns the state would mean PID matching, which wrapper launchers break. CI is green on022bf8a91d4. Its last commit makes the native-maintenance test mock spread the real module, as the mock-exports ratchet requires.Separate pre-existing issue observed, not changed here: a no-migration
--no-restartupdate under a custom profile succeeds, but the foreground Gateway's self-restart then fails to load a lazily loaded chunk that the package swap removed.