Repository navigation
fix(doctor): migrate legacy agent databases and bound registry writes to the active state dir - #120906
Merged
Conversation
…und registry writes to the active state dir
steipete
marked this pull request as ready for review
August 9, 2026 05:12
Contributor
Author
|
Merged via squash.
|
This was referenced Aug 9, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 10, 2026
… to the active state dir (openclaw#120906) * fix(doctor): migrate legacy agent databases discovered on disk and bound registry writes to the active state dir * fix(doctor): discover configured agent databases without registry rows * fix(doctor): preserve filesystem and configured database identity * fix(doctor): prioritize configured agent database identity * fix(doctor): prefer recorded agent database ownership
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Four coupled defects around agent-database migration, all reproduced live against a copy of a real state dir:
acp_parent_stream_events(andtrajectory_runtime_events) in a pre-session_id, non-STRICT shape. The canonical schema re-landed at v12 withsession_idand no ALTER path, so thepreviousVersion < 11STRICT rebuild inensureAgentSchemafailsassertMatchingColumns("missing session_id") and the whole doctor migration rolls back — the DB is stuck at v9 forever, and the gateway refuses to start.agent_databasesregistry rows, while doctor's session steps scan the agents tree on disk. An on-disk DB with no registry row (state dir copied or restored) is never migrated — and can never self-register becauseopenOpenClawAgentDatabaseasserts the media version before registering. Doctor's later steps then crash on the unmigrated DB.OPENCLAW_STATE_DIRpointing at a copy, the copied registry rows still name the ORIGINAL~/.openclaw/agents/...paths, and the migration followed them — opening and (absent defect 1) writing schema migrations into a foreign live state dir. Verified live: a sandboxeddoctor --fixattempted exactly that against the real home state dir.runDoctorHealthContributionshad no per-step isolation, so the crash from defect 2 killed doctor entirely — with the error text "runopenclaw doctor --fix", printed by doctor --fix itself.Why This Change Was Made
ensureAgentSchemagains a structure-gated drop for the reverted-lineage runtime journals (both are derived runtime state; drop-and-recreate is the sanctioned shape, precedentdropLegacyMemoryIndexSchema).state-migrations.media-persistence-targets.ts) that unions configured session-store targets, registry rows, and disk-discovered default-layout DBs, deduplicated by filesystem identity with explicit owner authority: configuration → recorded registry fact → directory-name inference. Filesystem operations use original paths (no lexical..collapse across symlinks); realpath is used only for identity/boundary checks.session.storepaths (a documented contract) still migrate, now even without a registry row.No schema-version bump; no runtime steady-state behavior changes; runtime asserts stay.
User Impact
Users upgrading DBs that crossed the reverted May window, and anyone who copies/restores/moves a state dir (backup restore, machine migration, sandboxing), get a working
openclaw doctor --fixinstead of a permanently stuck gateway with circular advice. Doctor can no longer mutate a different installation's databases.Evidence
Live before/after on a copy of a real state dir (v9
mainagent DB with legacyacp_parent_stream_events, 21 registry rows pointing at the original~/.openclaw):doctor --fixexits 1 withOpenClawAgentDatabaseMediaMigrationRequiredError ... run openclaw doctor --fix, after attempting migration of the ORIGINAL state dir's DBs (blocked only by defect 1).mainmigrates v9 → v16 with canonicalacp_parent_stream_events(session_id, STRICT); all 21 foreign registry rows skipped + unregistered with warnings; original~/.openclawagent DB mtimes byte-identical before/after (sorted stat comparison).Tests:
node scripts/run-vitest.mjs src/infra/state-migrations(503 passed / 2 skipped incl. new coverage for legacy-journal rebuild, unregistered disk discovery, foreign-row skip with untouched bytes, configured-store discovery without registry rows, symlinked..path identity, owner-authority precedence, doctor step isolation),node scripts/run-vitest.mjs src/state/openclaw-agent-db(111 passed / 4 skipped), doctor-health suite (107 passed).