Skip to content

fix: recover gateway startup state migrations - #120687

Closed
galiniliev wants to merge 1 commit into
mainfrom
galin/DurableAgentDatabaseOwnershipRelocation
Closed

galiniliev wants to merge 1 commit into
mainfrom
galin/DurableAgentDatabaseOwnershipRelocation

Conversation

@galiniliev

@galiniliev galiniliev commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where gateway startup could repeatedly refuse readiness after bundled-plugin rebuild or persistence convergence, reporting: OpenClaw plugin migration inputs changed during startup convergence; refusing to report the gateway ready. It also recovers legacy agent database relocation without changing the durable database owner or registry intent.

Why This Change Was Made

The migration fingerprint included non-semantic, runtime-generated plugin inventory fields that can change across bundled-plugin rebuild and persistence convergence: collection and nested ordering, package-build metadata, and file timestamps. The repair fingerprints the semantic persisted inventory contract, while relocation preserves durable database ownership and registry intent.

User Impact

Operators can run openclaw doctor --fix to recover the affected legacy agent database placement, and subsequent gateway launches converge normally instead of repeatedly refusing readiness after generated plugin inventory changes.

Evidence

  • Sanitized session behavior: openclaw doctor --fix relocated the mismatch to agents/openclaw/agent/openclaw-agent.sqlite.
  • After the semantic fingerprint repair, two consecutive pnpm openclaw gateway run launches reached ready.
  • Focused migration tests and manifest registry/preflight tests passed.
  • Remote Blacksmith Testbox pnpm check:test-types passed at tbx_01kzhax5rvz5x0njrmnw3cqk0r; GitHub Actions run 31272571006.
  • Autoreview: clean.

This is local behavioral and CI proof; no live provider or channel proof is claimed.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XL maintainer Maintainer-authored PR labels Aug 8, 2026
@galiniliev
galiniliev marked this pull request as ready for review August 8, 2026 20:17
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 9, 2026, 12:47 AM ET / 04:47 UTC.

ClawSweeper review

What this changes

The PR updates Doctor’s legacy agent-database relocation and makes installed-plugin inventory fingerprints ignore non-semantic rebuild metadata so gateway startup can converge.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked by patch quality or review findings - 7 items remain

Keep this PR open: it still redirects the durable agent-database registry before the final SQLite sidecar safety check, so a late nonempty WAL/journal can leave discovery targeting a database that was never moved.

Priority: P1
Reviewed head: a7933a7262f86ecd3aec92e1cb964cc8b5a1c0a3

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The branch addresses a real startup problem and fixes the earlier diagnostic-fingerprint concern, but the remaining P1 persistent-state ordering defect makes it not ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer PR, so the external-contributor proof gate does not apply; the body’s claimed local runs are not inspectable artifacts, and the remaining source defect still blocks merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer PR, so the external-contributor proof gate does not apply; the body’s claimed local runs are not inspectable artifacts, and the remaining source defect still blocks merge.
Evidence reviewed 5 items Registry relocation precedes the final sidecar gate: The PR writes the durable registry target before rejecting a late nonempty WAL or journal; that rejection returns without moving the source database.
Discovery trusts the recorded registry path: Registered agent-database discovery returns persisted paths without verifying that the target file exists, making the premature redirect operator-visible.
Regression coverage misses the rejected late-sidecar case: The added migration test covers an empty WAL/SHM sidecar and successful relocation, not a late nonempty sidecar that must preserve both source file and source registry record.
Findings 1 actionable finding [P1] Gate sidecars before committing registry relocation
Security None None.

How this fits together

Gateway startup runs Doctor migrations before reporting ready. Doctor relocates legacy per-agent SQLite databases and persists plugin inventory facts that startup preflight compares on subsequent launches.

flowchart LR
A[Legacy agent database] --> B[Doctor migration]
B --> C[Sidecar safety check]
C --> D[Registry and file relocation]
D --> E[Gateway preflight]
F[Plugin inventory] --> G[Semantic fingerprint]
G --> E
E --> H[Gateway ready]
Loading

Before merge

  • Gate sidecars before committing registry relocation (P1) - A WAL or rollback journal can become nonempty after the initial blocker check. This redirects the registry before clearTransientAgentDatabaseSidecars rejects that sidecar, so the source file remains while discovery resolves a nonexistent target; gate first or roll back the registry update, and cover the rejected late-sidecar case.
  • Resolve merge risk (P1) - Merging can strand an existing agent database at its source path while the durable registry points to a nonexistent target, breaking agent-state discovery after Doctor reports the sidecar blocker.
  • Resolve merge risk (P1) - The PR changes persistent migration and startup-readiness behavior; its current exact-head required CI includes failures, whose logs were unavailable during this read-only review.
  • Complete next step (P2) - The repair is mechanically clear, but the protected maintainer label requires explicit maintainer handling before the branch is changed or merged.
  • Improve patch quality - Move the final sidecar gate before the registry redirect or make failure rollback atomic.
  • Improve patch quality - Add a late nonempty WAL/journal regression that asserts both registry and source database remain intact.
  • Improve patch quality - Resolve the failed exact-head CI checks before merge.

Findings

  • [P1] Gate sidecars before committing registry relocation — src/infra/state-migrations.doctor.ts:1131-1147
Agent review details

Security

None.

PR surface

Source +533, Tests +747. Total +1280 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 605 72 +533
Tests 3 747 0 +747
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 1352 72 +1280

Review metrics

Metric Value Why it matters
Production versus test LOC production +605/-72; tests +747/-0 The substantial production growth is justified by new migration ownership and fingerprint-contract handling, but it makes the remaining persistent-state ordering defect especially important to resolve.

Stored data model

Persistent data-model change detected: database schema: src/commands/doctor-state-migrations.test.ts, migration/backfill/repair: src/commands/doctor-state-migrations.test.ts, serialized state: src/infra/state-migrations.doctor.ts, serialized state: src/infra/state-migrations.legacy-sessions.ts, serialized state: src/infra/state-migrations.types.ts, serialized state: src/state/openclaw-agent-db-registry.ts, and 9 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair relocation ordering before merge (recommended)
    Run the final sidecar gate before changing the registry, or atomically roll the registry update back whenever the file move is rejected.
  2. Pause the branch
    Do not merge the migration changes if the relocation invariant cannot be made atomic and regression-proven on the current head.

Technical review

Best possible solution:

Move the final sidecar rejection/cleanup ahead of the registry redirect, then add a regression that proves a blocked late-sidecar move preserves both filesystem and registry ownership.

Do we have a high-confidence way to reproduce the issue?

Yes—source establishes a current-head path: a nonempty WAL/journal appearing after initial planning causes the later sidecar gate to reject relocation after the registry has already moved. This was not executed because the review is read-only.

Is this the best way to solve the issue?

No—the semantic fingerprint portion is well-scoped, but the relocation sequence must gate sidecars before committing the durable registry change or restore that record on failure.

Full review comments:

  • [P1] Gate sidecars before committing registry relocation — src/infra/state-migrations.doctor.ts:1131-1147
    A WAL or rollback journal can become nonempty after the initial blocker check. This redirects the registry before clearTransientAgentDatabaseSidecars rejects that sidecar, so the source file remains while discovery resolves a nonexistent target; gate first or roll back the registry update, and cover the rejected late-sidecar case.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7f3cc6995bc6.

Labels

Label justifications:

  • P1: A blocked migration can make gateway startup unable to find an existing agent database.
  • merge-risk: 🚨 compatibility: The change alters upgrade-time relocation of existing on-disk agent databases.
  • merge-risk: 🚨 session-state: A premature registry redirect can detach persisted agent state from its discoverable database path.
  • merge-risk: 🚨 availability: The affected path runs before gateway readiness and can prevent normal startup recovery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer PR, so the external-contributor proof gate does not apply; the body’s claimed local runs are not inspectable artifacts, and the remaining source defect still blocks merge.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the original stable plugin-index fingerprint and has recent history around the surrounding migration flow. (role: original fingerprint-cache author and recent migration contributor; confidence: high; commits: 2babe03bf521, 75dbe52e; files: src/plugins/manifest-registry-installed.ts, src/infra/state-migrations.doctor.ts)
  • Ryan Gu: Authored recent gateway-wedge migration repair work in the same Doctor/state-migration area. (role: recent gateway-migration contributor; confidence: medium; commits: 63c94952b3e4; files: src/infra/state-migrations.doctor.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-08T20:45:00.080Z sha 627134e :: found issues before merge. :: [P1] Delay registry relocation until the sidecar gate passes
  • reviewed 2026-08-08T22:38:44.294Z sha 8d9172c :: found issues before merge. :: [P1] Gate sidecars before committing registry relocation | [P1] Preserve diagnostic codes across the persisted index

@galiniliev galiniliev self-assigned this Aug 8, 2026
@galiniliev
galiniliev force-pushed the galin/DurableAgentDatabaseOwnershipRelocation branch from 627134e to 8d9172c Compare August 8, 2026 21:11
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 8, 2026
Co-authored-by: Copilot <[email protected]>
Copilot-Session: e61bf540-058b-4337-ae97-98fb7c39ef02
@galiniliev
galiniliev force-pushed the galin/DurableAgentDatabaseOwnershipRelocation branch from 8d9172c to a7933a7 Compare August 9, 2026 04:15
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 9, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Closed after the viable replacement landed:

The source branch had maintainer edits disabled, was conflicting/dirty, and still contained an unresolved persistent-state relocation ordering defect. The landed replacement therefore uses a materially different, current-main owner-boundary repair for the remaining plugin install-record work; the separate agent-database slice had already landed through #120906.

Galin Iliev's investigation and historical intent are credited in #121045, and every semantic replacement commit preserved Galin's Co-authored-by trailer.

@RomneyDa
RomneyDa deleted the galin/DurableAgentDatabaseOwnershipRelocation branch October 22, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL 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.

2 participants