Skip to content

fix: stop an update before installing when a running Gateway blocks its database migration - #203170

Merged
steipete merged 8 commits into
mainfrom
codex/issue-202700
Nov 21, 2026
Merged

steipete merged 8 commits into
mainfrom
codex/issue-202700

Conversation

@steipete

@steipete steipete commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Related: #202700

What Problem This Solves

When openclaw update must 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 foreground openclaw gateway run under a custom OPENCLAW_HOME/OPENCLAW_STATE_DIR profile, 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 rerun openclaw 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-restart its 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_DIR profile, a foreground gateway run, and an external registered agent store restored from published 2026.11.6 at schema 38. Main b8b06c4824f was relabeled 2026.11.30/.31; this branch was built as 2026.11.29.

Lane Result
main → main, --no-restart Reporter's failure reproduced: exit 1 after 163 s, Agent database migration did not finish … expected schema 43, found 38, rolled back to the previous version
fix → main, --no-restart Refused in 138 s with database-migration-owner-live; no package replacement; installed version unchanged; Gateway still serving (/readyz 200); store still at 38
same profile, Gateway stopped, rerun Exit 0; new version active; store migrated to 43
fix → main, default profile with a systemd user service (updater stops it) Exit 0 in 228 s; store migrated to 43; /readyz 200, so no false refusal after the updater's own stop

Regression test admits activation only when Doctor can migrate in update-command-execution.test.ts covers six cases:

  • A live owner plus a pending migration is refused before mutation. This case is red on origin/main and green with the fix.
  • With no owner, the update proceeds.
  • With no migration needed, the update proceeds under a live owner.
  • A retained agent store is excluded.
  • A running owned service is exempt.
  • A stopped owned service is not exempt.

Targeted typecheck (tsgo:core), oxlint, and oxfmt pass. Touched and consumer update tests pass locally, except the process-lane rows that require a built dist worker. Those rows fail identically on origin/main in 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 on 022bf8a91d4. 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-restart update 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.

… 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
@clawsweeper

clawsweeper Bot commented Nov 21, 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.

@steipete
steipete marked this pull request as ready for review November 21, 2026 16:16
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: M labels Nov 21, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T17:20:28.186497Z 4f39488 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +495 to +496
await assertPendingMigrationsAdmitted({
pendingMigrations: activationSchemas.pendingMigrations,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This 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.

  • Before: The package is replaced, Doctor cannot acquire maintenance access, and the update rolls back.
  • After: The updater identifies the database and Gateway PID before package replacement and instructs the operator to stop the Gateway and retry.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production repair is focused and has relevant live verification, but a confirmed fixture regression leaves exact-head CI failing.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR supplies concrete Linux installed-CLI results for a custom profile and published-release schema-38 agent store: early refusal preserves the package and serving Gateway, stopped-owner retry reaches schema 43, and managed-service activation succeeds.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update discovers that a running Gateway prevents migration only after replacing the package, forcing an avoidable rollback.
Reason: The maintainer-authored direction addresses a controlled report, preserves working no-migration and managed-service paths, and gives actionable recovery before package replacement.

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
Reviewed head: cbed57e7fbf6b4b755aa37d64c769c5d2502b1af

Before merge

  • Update the native-maintenance fixture for the new admission call (P2) - The authorized activation-helper cases reach this new call, but update-command-service-maintenance-native.test-support.ts fully mocks the schema module without exporting assertPendingMigrationsAdmitted and returns no pendingMigrations from captureUpdateActivationSchemas. Those cases now throw after the native service stop instead of completing successfully. Exact-head CI confirms three matching missing-export failures. Update the fixture's mock and activation-schema result, then rerun the native-maintenance suite; this also confirms the existing finding at fix: stop an update before installing when a running Gateway blocks its database migration #203170 (comment).

Findings

  • [P2] Update the native-maintenance fixture for the new admission call — src/cli/update-cli/update-command-execution.ts:495-496
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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:

  • [P2] Update the native-maintenance fixture for the new admission call — src/cli/update-cli/update-command-execution.ts:495-496
    The authorized activation-helper cases reach this new call, but update-command-service-maintenance-native.test-support.ts fully mocks the schema module without exporting assertPendingMigrationsAdmitted and returns no pendingMigrations from captureUpdateActivationSchemas. Those cases now throw after the native service stop instead of completing successfully. Exact-head CI confirms three matching missing-export failures. Update the fixture's mock and activation-schema result, then rerun the native-maintenance suite; this also confirms the existing finding at fix: stop an update before installing when a running Gateway blocks its database migration #203170 (comment).
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Agent migration classification keeps the original intent (76752e0: Use inventory ownership and registrations so retained plugin stores are not mistaken for agent databases.)
  • Retained deleted-agent exclusion keeps the original intent (a72e9a3: Accept stores Doctor intentionally holds without migrating them while continuing to verify active agent stores.)
  • Activation schema baseline keeps the original intent (da0e0ba: Capture SQLite baseline schemas even without candidate canary output so failed activation can be rolled back safely.)
  • Validation and service-stop ordering keeps the original intent (9b3f350: Keep the serving Gateway available during validation and close it before activation through the existing CLI update owner.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/cli/update-cli/update-command-service-maintenance-native.test.ts --maxWorkers=1
  • pnpm test src/cli/update-cli/update-command-execution.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit da0e0ba adds src/cli/update-cli/update-command-schema.ts:537 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: da0e0ba8cae1; files: src/cli/update-cli/update-command-schema.ts)

PR surface

Source +64, Tests +66, Docs +10. Total +140 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 114 50 +64
Tests 1 66 0 +66
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 190 50 +140

Preflight source

Source 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

Metric Value Why it matters
Production versus test growth Production +114/-50; tests +66/-0 The production growth adds the early admission check while consolidating the existing migration rule; the four test rows protect distinct admission outcomes.

Root-cause cluster

Relationship: same_root_cause
Canonical: #202700
Summary: This PR implements the early refusal requested by the linked report's live-owner migration reproduction.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: This improves a bounded advanced CLI update workflow with a documented stop-and-retry recovery path.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This improves a bounded advanced CLI update workflow with a documented stop-and-retry recovery path.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

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.
@steipete
steipete merged commit 3f1a422 into main Nov 21, 2026
134 checks passed
@steipete
steipete deleted the codex/issue-202700 branch November 21, 2026 18:54
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…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]>
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant