Skip to content

fix(state): converge legacy startup migrations - #107002

Merged
steipete merged 7 commits into
mainfrom
codex/issue-103076
Jul 14, 2026
Merged

steipete merged 7 commits into
mainfrom
codex/issue-103076

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway startup treats every doctor migration warning as blocking. Already-imported legacy state could therefore create permanent startup loops when SQLite was authoritative but an old JSON/sidecar source remained, was recreated by an older process, or collided with an existing migration archive.

Closes #103076
Fixes #97563

Why This Change Was Made

  • Carry non-blocking migration notices separately from blocking warnings through doctor and automatic startup migration paths.
  • Converge identical and safely superseded legacy sources for state-directory, update-check, plugin-install, Matrix, Memory Core, and Codex session-binding migrations.
  • Keep real conflicts and archive/retirement failures fail-closed as warnings.
  • Persist Memory Core source acknowledgements in SQLite and bootstrap older installs from every canonical .migrated archive, including numbered collisions.
  • Treat successfully archived Matrix residue as a notice across all sibling Matrix state surfaces; archive failures remain warnings.

User Impact

Upgrades no longer require repeated manual gateway starts for migration residue that was already imported or safely archived. Real divergent state still blocks startup and remains available for operator repair.

Evidence

  • Testbox tbx_01kxf5rntxq2a3a6qmdabc8weg: 204 focused migration tests passed across 5 Vitest shards.
  • Same Testbox: full pnpm build passed, including plugin SDK declaration validation and Control UI build.
  • pnpm check:changed: formatting, LOC, SDK baseline, dependency guards, and all four typecheck lanes passed. The only failure was an untouched current-main lint at src/agents/model-fallback.test.ts:3764; test: restore moving-main quality gates #106972 fixed that baseline before this branch's final rebase.
  • Source-blind doctor scenario: first doctor --fix --non-interactive --yes run archived/noticed superseded update-check residue; second run was clean.
  • Fresh structured autoreview completed with no accepted/actionable findings after the final Matrix and Memory Core convergence fixes.
  • Codex contract checked directly in sibling codex: app-server protocol thread/resume consumes persisted rollout/thread identity; foreign legacy harness sidecars are therefore informational after successful binding retirement.

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix extensions: memory-core Extension: memory-core commands Command implementations extensions: codex size: XL maintainer Maintainer-authored PR labels Jul 14, 2026

@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: e03deef113

ℹ️ 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".

warnings: [
`Left plugin install index in place because shared SQLite state has conflicting plugin install metadata for: ${merged.conflicts.join(", ")}`,
],
warnings:

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 Preserve archive failures for acknowledged install conflicts

When all plugin install conflicts are acknowledged, archiveLegacyInstalledPluginIndex can still append to the local warnings array if the legacy plugins/installs.json cannot be renamed or removed (for example because the .migrated target collides with a directory or permissions fail), but this return rebuilds warnings as [] whenever unresolved.length === 0. That reports a successful notice while leaving the legacy source in place, so startup keeps retrying without surfacing the archive failure; return the accumulated warnings in this branch.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. 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 Jul 14, 2026
@clawsweeper

clawsweeper Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 13, 2026, 10:46 PM ET / July 14, 2026, 02:46 UTC.

Summary
The branch separates non-blocking migration notices from warnings and converges legacy state residue across core state, plugin installs, update checks, Matrix, Memory Core, and Codex session bindings.

PR surface: Source +328, Tests +247. Total +575 across 17 files.

Reproducibility: yes. at source and reported-live level: the linked issue shows already-imported residue producing warnings, and startup refuses readiness whenever those warnings persist; the PR also reports a clean second run for one real doctor scenario.

Review metrics: 1 noteworthy metric.

  • Migration policy surfaces: 6 aligned. State-directory, update-check, plugin-install, Matrix, Memory Core, and Codex migrations now share readiness-sensitive convergence semantics.

Stored data model
Persistent data-model change detected: migration/backfill/repair: extensions/matrix/doctor-contract-api.test.ts, migration/backfill/repair: extensions/matrix/doctor-contract-api.ts, migration/backfill/repair: extensions/memory-core/doctor-contract-api.test.ts, migration/backfill/repair: extensions/memory-core/doctor-contract-api.ts, migration/backfill/repair: src/commands/doctor-state-migrations.test.ts, persistent cache schema: extensions/matrix/doctor-contract-api.test.ts, and 31 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #103076
Summary: This PR is the candidate fix for the canonical remaining startup-migration convergence issue and also covers a distinct plugin-install divergence subset.

Members:

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

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🌊 off-meta tidepool
Patch quality: 🦐 gold shrimp
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Preserve accumulated archive warnings in the acknowledged plugin-conflict branch and add its regression test.
  • Rebase onto current main and rerun exact-head focused migration and upgrade checks.
  • Obtain explicit likely-owner acceptance of the shared SQLite-authoritative convergence policy.

Risk before merge

  • [P2] The PR changes upgrade-time file archival, deletion, and SQLite-authority decisions across six migration families; an incorrect equivalence or authority test could suppress a real conflict or retire recoverable legacy state.
  • [P0] The warning-versus-notice policy directly controls gateway readiness, so misclassification can either recreate a startup outage or allow startup after an incomplete migration.
  • [P1] The PR head is reported behind the current main SHA and needs an exact-head review refresh after rebase; stale base drift alone is not evidence of a merge defect.

Maintainer options:

  1. Preserve archive failures before merge (recommended)
    Return accumulated archive warnings even when every plugin conflict is otherwise acknowledged, and cover the branch with a failed-archive regression test.
  2. Accept the convergence policy
    Maintainers may explicitly accept SQLite-authoritative notices and numbered archives after the defect is fixed and exact-head upgrade proof remains green.
  3. Pause the cross-surface rollout
    Pause this PR if the project is not ready to standardize legacy-state retirement and startup-blocking semantics across all affected owners.

Next step before merge

  • [P1] A likely owner should require the narrow archive-warning fix, then decide the persisted-state convergence policy and review exact-head upgrade proof; the protected maintainer label makes this unsuitable for autonomous repair routing.

Maintainer decision needed

  • Question: Should OpenClaw adopt this SQLite-authoritative convergence policy across all six migration families once archive failures are reliably preserved as blocking warnings?
  • Rationale: The branch intentionally changes persisted-state retirement and which migration outcomes can block gateway readiness, so automation cannot safely choose that upgrade and availability policy.
  • Likely owner: steipete — This person has the strongest merged history across the shared plugin doctor seam and Codex binding migration and is already carrying the cross-surface implementation.
  • Options:
    • Fix, accept, and land (recommended): Preserve archive warnings, add the focused regression, then accept the shared notice/archive policy and merge after exact-head checks.
    • Require copied-state upgrade replay: After the code fix, require a packaged first-run and second-run replay against affected legacy state before accepting the policy.
    • Pause for broader migration policy: Hold the PR if maintainers want one explicit cross-product policy before any further warning-to-notice downgrades.

Security
Cleared: No concrete security or supply-chain regression was found; the diff changes local migration logic and tests without new dependencies, workflow permissions, secret access, or downloaded code.

Review findings

  • [P2] Preserve archive failures for acknowledged plugin conflicts — src/infra/state-migrations.plugin-state.ts:235-239
Review details

Best possible solution:

Keep the unified convergence approach, preserve every archive-operation warning in the acknowledged plugin-conflict branch, add a focused failure regression, then rebase and land only after a likely owner explicitly accepts the SQLite-authoritative notice policy and exact-head upgrade checks pass.

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

Yes at source and reported-live level: the linked issue shows already-imported residue producing warnings, and startup refuses readiness whenever those warnings persist; the PR also reports a clean second run for one real doctor scenario.

Is this the best way to solve the issue?

Mostly yes: applying one convergence policy across sibling migrations is preferable to isolated exceptions, but the current plugin-install return path must preserve archive failures before this is the best safe implementation.

Full review comments:

  • [P2] Preserve archive failures for acknowledged plugin conflicts — src/infra/state-migrations.plugin-state.ts:235-239
    When every conflict has a canonical SQLite install record, this return replaces warnings accumulated by archiveLegacyInstalledPluginIndex with []. If removal or rename fails, the PR therefore emits a success notice while leaving plugins/installs.json behind and retries silently on later startups. Return the accumulated warnings in this branch and add the corresponding failed-archive test.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9b823c610816.

Label changes

Label changes:

  • add P0: The linked bug can leave the gateway permanently unable to report ready after an upgrade, with manual state-file intervention as the current recovery.
  • add merge-risk: 🚨 compatibility: The PR changes how shipped legacy files are classified, archived, removed, and superseded by SQLite during upgrades.
  • add merge-risk: 🚨 session-state: Memory Core and Codex migration branches acknowledge or retire persisted legacy state whose incorrect classification could stale or mis-associate session data.
  • add merge-risk: 🚨 availability: The warning-versus-notice result directly determines whether gateway startup fails closed.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The maintainer-labeled PR is exempt from the external-contributor proof gate; its Testbox runs and source-blind two-run doctor scenario remain useful supplemental upgrade evidence.

Label justifications:

  • P0: The linked bug can leave the gateway permanently unable to report ready after an upgrade, with manual state-file intervention as the current recovery.
  • merge-risk: 🚨 compatibility: The PR changes how shipped legacy files are classified, archived, removed, and superseded by SQLite during upgrades.
  • merge-risk: 🚨 session-state: Memory Core and Codex migration branches acknowledge or retire persisted legacy state whose incorrect classification could stale or mis-associate session data.
  • merge-risk: 🚨 availability: The warning-versus-notice result directly determines whether gateway startup fails closed.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The maintainer-labeled PR is exempt from the external-contributor proof gate; its Testbox runs and source-blind two-run doctor scenario remain useful supplemental upgrade evidence.
Evidence reviewed

PR surface:

Source +328, Tests +247. Total +575 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 11 625 297 +328
Tests 6 257 10 +247
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 882 307 +575

What I checked:

Likely related people:

  • steipete: Prior merged work consolidated plugin doctor migration seams and moved Codex app-server bindings into SQLite state, directly overlapping this PR's core and Codex migration boundaries. (role: feature-history owner and likely policy decision owner; confidence: high; commits: eafe2a8d0bb6, 0d981095d430, f91de52f0d23; files: src/plugin-sdk/runtime-doctor.ts, src/plugins/doctor-state-migration-fs.ts, extensions/codex/src/migration/session-binding-sidecars.ts)
  • vincentkoc: Recent merged work touched the same archive, SQLite sidecar, and plugin install-index migration behavior, and the canonical linked issue is assigned to this person. (role: recent state-migration contributor; confidence: high; commits: 5cebe9666790, 6326395c0ae4, 7485dd649262; files: src/infra/state-migrations.doctor.ts, src/infra/state-migrations.debug-proxy.ts, src/commands/doctor-state-migrations.test.ts)
  • obviyus: Authored and merged the predecessor convergence change that introduced the shared notices and numbered-archive policy this PR extends. (role: adjacent convergence-policy contributor; confidence: high; commits: 0d41316bcc34, 709855d623b2, a00d175b0d32; files: src/infra/state-migrations.doctor.ts, src/commands/doctor-state-migrations.test.ts, src/plugins/doctor-state-migration-fs.ts)
  • sallyom: Recent history introduced the gateway readiness path that treats remaining migration warnings as startup blockers. (role: startup readiness contributor; confidence: medium; commits: b81666ca6af2; files: src/commands/doctor-config-preflight.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete
steipete force-pushed the codex/issue-103076 branch from ec85ad4 to 81a79fd Compare July 14, 2026 02:50
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jul 14, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at 2763aadf732f4a6e11f624b3515382455ba4bac0.

  • Testbox tbx_01kxf5rntxq2a3a6qmdabc8weg: 204 focused migration tests across 5 shards; full build passed.
  • Source-blind doctor proof: first run archived acknowledged update-check residue and emitted a notice; second run was clean.
  • check:changed: formatting, LOC, SDK surface, dependency guards, and four typecheck lanes passed.
  • Structured autoreview reran after each accepted finding; final review has zero findings.
  • Exact-head hosted CI run 29302150479: all 54 jobs passed.
  • Repo-native prepare gate passed. Known proof gaps: none.

@steipete
steipete merged commit 4da0eb1 into main Jul 14, 2026
107 of 109 checks passed
@steipete
steipete deleted the codex/issue-103076 branch July 14, 2026 03:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 14, 2026
* fix(state): converge legacy startup migrations

Co-authored-by: Eva <[email protected]>

* refactor(state): split legacy migration helpers

* fix(memory): persist legacy source acknowledgements

* fix(state): remove stale migration imports

* fix(memory): recognize numbered migration archives

* fix(matrix): downgrade archived migration residue

* fix(memory): satisfy migration lint

---------

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

Labels

channel: matrix Channel integration: matrix commands Command implementations extensions: codex extensions: memory-core Extension: memory-core 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. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

1 participant