Expand description
Data migration framework.
Migrations are versioned steps that run once, either via agentmux-srv migrate
or in-process at startup via run_pending_migrations (called unconditionally;
fast-paths to Ok(0) when already current). The in-process path runs before
any store is opened for normal operation so that id_store always binds to a
fully-backfilled shared store.
Adding a migration: implement Migration, add it to [REGISTRY], add a
file under this module. The ID must be unique and lexicographically ordered
(use the NNNN_slug convention). Retiring old migrations: remove from
[REGISTRY] once the minimum supported upgrade path passes the migration’s
origin version — the db_migrations row stays as a permanent record. That
path is the repo’s UPGRADE_FLOOR: raise it past the migration’s origin
version first, so an install older than that is told to install the floor
version before upgrading (backend::update::check::upgrade_floor).
§A Global migration is additive
Every AgentMux on the computer opens the shared stores at once, whatever its
version or channel, so a MigrationScope::Global migration may only add:
new tables, columns and rows. No drop, rename or delete until an
UPGRADE_FLOOR raise has retired the old shape (expand now, remove later;
decision D1 of REPORT_STARTUP_ARCHITECTURE_AND_MIGRATIONS_AUDIT_2026_10_20).
Start its doc comment with a //! Shared store: additive, ... line saying
what it adds. additive_guard_tests fails a Global migration with no such
line, or one that declares itself additive and writes destructive SQL. A
reviewer still has to read what a store helper does: the test cannot.
§No private marker files
db_migrations (plus a Migration::verify post-condition) is the sole
source of truth for “has this run” — SPEC_MIGRATION_SYSTEM_HARDENING_2026_08_03
Phase 2. A new migration must not introduce its own flag file, and no
migration may treat the mere existence of a marker as proof of
completion: that is the shape that left 0007’s target table empty
while its flag said “done” (§1.2, F1). The three legacy markers that
remain are evidence only — 0007’s and 0002’s helpers decide from the
data (consolidate_looks_incomplete, block_zones_look_incomplete) and
are content-idempotent, 0003’s helper ignores its marker and re-asserts
its invariant every run. The bootstrap that stamped a pre-framework
install from them, and the migrations older than the upgrade floor (0.55.0),
are retired: an install that old is told to install the floor first.
§Migrations freeze copies of live logic on purpose
Some migrations carry verbatim copies of helpers that also exist in live
code: m0020_agent_color_backfill and
m0021_backfill_agent_bundles mirror 25–30 lines each of
backend/storage/mcp_servers.rs and def_registry_mirror.rs. That is
deliberate, not accidental duplication. A migration must produce the same
rows on every machine it ever runs on, so it cannot call a live helper
whose behaviour a later release may change; the copy pins the logic as it
was at the migration’s origin version. Do not “deduplicate” a migration
against live code. When you copy logic into a new migration, say so next
to the copy — // frozen copy of <path>::<fn> as of <version> — so the
next reader can tell a freeze from a drift.
Re-exports§
pub use gate::data_needs_preparing;pub use gate::refuse_if_real_home_would_move;pub use runner::count_pending_migrations;pub use runner::doctor_report_for_instance;pub use runner::run_migrate_command;pub use runner::run_pending_migrations;pub use runner::try_count_pending_migrations;pub use runner::PendingCountError;
Modules§
- backup
- The backup taken before a batch of migrations, and its pruning. Moved out
of
runner.rsto keep it under the 1500-line limit. - carry_
forward - A new version starts with the data of the version before it
(
docs/specs/SPEC_UPGRADE_FOR_USERS_AND_AGENTS_2026_10_15.md§6). - gate
- srv’s boot gate: whether this version’s data needs
agentmux-srv migrate --preparebefore srv may open it (S1c ofdocs/specs/SPEC_FAST_STARTUP_UPGRADE_OWNS_MIGRATIONS_AND_UPDATES_2026_09_15.md§10). - m0002_
block_ zones_ v1 - m0003_
template_ sessions_ v1 - m0007_
agents_ consolidate - m0011_
shared_ store_ backfill - Shared store: additive, it inserts rows into the shared store from the channel stores.
- m0016_
seed_ starter_ mcp_ servers - Seed the global MCP Servers catalog (
db_mcp_servers, per-channel) with a curated, credential-free starter set on fresh install. - m0020_
agent_ color_ backfill - Backfill a display color (
agent_contentui:color) for every existing agent definition that doesn’t have one — the “generate a random color for all the existing agents” one-time script fromdocs/specs/SPEC_AGENT_COLOR_2026_08_08.md. - m0021_
backfill_ agent_ bundles - Bind an agent definition to the bundle another channel already recorded for it
(
docs/specs/SPEC_MEMORY_FOLLOWS_THE_AGENT_2026_09_24.md§2.1.6). - m0022_
identity_ store_ links_ backfill - Backfill
db_agent_identity_links, plus adb_accountsfallback mirror (reagentx P0 review, added after this migration’s first version — seeidentity::resolver::inject::resolve_account’s own doc comment for why the mirror is needed even thoughdb_accountsitself stays onid_storeas the authoritative store), from every reachable store into the new, permanently-global identity store — seedocs/specs/SPEC_IDENTITY_STORE_SPLIT_2026_08_17.md. - m0023_
native_ memory_ versions_ backfill - Backfill
db_agent_native_memory_versionswith onesource: "agent_inferred"version per existingdb_agent_native_memoryrow — reagent P1 (re-review of PR #2674): the spec this migration completes (docs/specs/SPEC_MEMORY_VERSION_CONTROL_AND_ARMORY_AUDIT_2026_08_19.md§9 Rollout) explicitly calls for this backfill so history views aren’t empty for pre-existing memory on upgrade. Without it, an existing user’s first post-upgrade overwrite of a memory file records only the NEW content as version 1 — the prior live content (everything that file held before this feature shipped) is permanently unrecoverable viaMemoryRevert/MemoryDiff. - m0024_
native_ memory_ backfill_ from_ fs - Finish the job
m0023was meant to do, and repair the label it left behind —SPEC_MEMORY_VERSION_CONTROL_AND_ARMORY_AUDIT_2026_08_19.md§9 (rollout backfill) and §4.5 (drift detection). - m0025_
agents_ launch_ state_ backfill - Backfill
db_agents’ latest-launch state (schema v29:session_id,status,started_at,ended_at, andlast_block_idwhere still empty) from the legacydb_agent_instancesrows. - m0026_
registry_ agent_ id_ rekey - Re-key the named-agent registry from launch ids to agent ids.
- m0027_
agents_ workspace_ backfill - Backfill
db_agents.working_directorywith the workspace each agent actually ran in, taken from its latest legacydb_agent_instanceslaunch. - m0028_
agent_ child_ tables_ repoint_ fk - Re-point six agent-child tables’
agent_idforeign key fromdb_agent_definitions(id)todb_agents(id). - m0029_
drop_ legacy_ agent_ tables - Drop
db_agent_definitionsanddb_agent_instances— the two legacy tables the agent-concept consolidation retires. - m0030_
backfill_ bundle_ component_ refs - Backfill
db_bundle_skills_reffrom the inlinedb_bundles.skillsJSON column. - m0031_
carry_ skills_ and_ mcp_ servers_ to_ identity_ store - Carry each channel’s
db_skills/db_mcp_serversrows into the permanently-global identity store, which became authoritative for them in Phase 2a (IDENTITY_STORE_SCHEMA_VERSIONv6/v7 — seeSPEC_DURABLE_BINDINGS_2026_09_10.md§7 Phase 2). - m0032_
drop_ catalog_ fk_ from_ ref_ tables - Drop the
skill_id/mcp_idforeign key from all four skill/MCP ref tables (db_agent_skills_ref,db_agent_mcp_ref,db_bundle_skills_ref,db_bundle_mcp_ref), leaving every other constraint verbatim (the agent-level pair’sagent_id → db_agentsFK, everyPRIMARY KEY, all column types). - m0033_
narrow_ skill_ global_ uniqueness_ index - Narrow the global skill uniqueness index from
(name, skill_type)tonamealone, matching the invariantskill_upsert_unique_global’s own dup-check has always enforced — with a defensive dedup pass for any existing same-name/different-type pair the OLD, wider index let through. - m0034_
identity_ history_ backfill - One-time sweep for identity conversation history stranded before
ensure_history_link(SPEC_AGENT_IDENTITY_HISTORY_PERSISTENCE_PROTOCOL_2026_08_16.md, shipped in0007c6b64051e8/ PR #2605) existed to keep it linked into the always-globalshared/identities/<id>/<provider>/<subdir>/tree. - m0035_
agent_ owns_ its_ provider - Give every agent the provider it actually runs with, before the bundle
stops deciding it (
docs/specs/SPEC_AGENT_BUNDLE_FORMAT_V0_3_2026_10_05.md§3.3). - m0036_
drop_ bundle_ mcp - Bundles stop carrying MCP servers: they belong to Connectors
(
docs/specs/SPEC_BUNDLE_CONTENTS_MEMORY_NOT_MCP_2026_10_07.md§3.1, D3). - m0037_
retire_ old_ pane_ names - Rewrites the retired pane names in stored data, once, so the frontend and srv can drop the
shims that translated them on every read. The Armory (and the Trust Center before it) was
split into Connectors and Memory, the Knowledge pane was renamed Memory, and Remotes became a
section of Connectors (
SPEC_RETIRE_ARMORY_CONNECTORS_AND_KNOWLEDGE_PANES_2026_10_05.mdPhase 3,SPEC_RENAME_KNOWLEDGE_TO_MEMORY_2026_10_06.md,SPEC_REMOTES_INTO_CONNECTORS_2026_10_08.md). - m0038_
drop_ drone_ runs_ definition_ fk - Drop
db_drone_runs.drone_id’s foreign key to this channel’s localdb_drone_definitions. - m0039_
vault_ into_ warden - The Vault became a section of Warden (operator decision 2026-10-21,
SPEC_VAULT_PANE_AGENTS_USE_SECRETS_UNSEEN_2026_10_19.md§5.6 amendment). Moves, once, for this channel: - m0040_
cron_ jobs_ to_ db_ jobs - Copy every cron job into
db_jobs(SPEC_JOBS_AND_TEMPLATES_2026_10_24.md§5.1): a job with acrontrigger in UTC and amessageaction, keeping its id, so Swarm, Schedule and the run ledger (whose rows name the job by id) carry on as before. - m0041_
retire_ untouched_ starter_ skills - Remove the six starter skills (
0015_seed_starter_skillsseeded them on a fresh install; it no longer does) from a catalog where nobody used them. - m0042_
supervisor_ modes_ reset - Set every pane the Swarm Supervisor was supervising back to Off, once.
- m0043_
rotate_ container_ agent_ keys - Replace the signing keys of every container agent, once.
- m0044_
warden_ split - Warden was split: the Vault, History and Audit are panes of their own, Host is the Swarm, and Warden keeps only its Jobs section. Moves, once, for this channel:
- m0045_
palette_ snap - Snap the colours stored before the shared palette to their nearest slot
(
docs/specs/SPEC_SHARED_PERCEPTUAL_PALETTE_16_2026_11_01.md§5.3, §7): the agents’ui:color(agent_content) and the browser profiles’ colours (browser-profiles.json). Both were picked from older lists (14 Tailwind hexes, 8 profile hexes, or an HSL pick), so they are not slot hexes yet; the frontend already draws them in their nearest slot, and this makes the stored value the slot’s own hex, which is what Kanban, the mobile app and the “least-used colour” pick for new agents read. - m0046_
remove_ empty_ agent_ bundles - Remove the empty per-agent bundles nothing points at
(
docs/reports/REPORT_AGENT_BUNDLES_REFINE_OR_DROP_2026_11_03.md). - m0047_
agents_ drop_ own_ bundle - An agent has no bundle of its own: a bundle holds only what several agents share
(
docs/reports/REPORT_AGENT_BUNDLES_REFINE_OR_DROP_2026_11_03.md). - m0048_
seed_ grok_ muse_ accounts - Give the grok and muse agents that already work an account, so none stops launching.
- m0049_
drone_ versions - The table behind graph versions
(
docs/specs/SPEC_DRONE_GENERAL_AUTOMATION_2026_11_11.md§3.3, “Graph versions”). - m0050_
drone_ checkpoints - The table behind a run’s checkpoints
(
docs/specs/SPEC_DRONE_GENERAL_AUTOMATION_2026_11_11.md§3.3). - m0051_
palette_ 12_ snap - Move the colours stored for the 16-slot palette to the 14 slots that
replace it: 12 hues, Black and White
(
docs/specs/SPEC_SHARED_PALETTE_12_HUES_BLACK_WHITE_2026_11_16.md§5). - m0052_
drone_ access - The table behind who may fire a drone
(
docs/specs/SPEC_DRONE_REAL_WORLD_JOBS_2026_11_11.md§6.5). - m0053_
history_ into_ audit - The History pane became the Audit pane’s Conversations section. Moves, once, for this channel:
- m0054_
rotate_ host_ agent_ keys - Replace the signing keys of every host agent, once.
- prepare
agentmux-srv migrate --prepare: everything a version’s data needs before srv opens it, as one step a supervisor runs while srv is stopped.- runner
- Migration runner — invoked by
agentmux-srv migrate(a CLI subcommand; the launcher runsmigrate --preparethroughsrv_spawner::run_preparewhen srv’s boot gate asks for it) and, separately, in-process at boot viarun_pending_migrations, only when no supervisor prepares data (headless srv,task dev:standalone). - schema_
probe - The one “does this table exist” probe. Every migration used to carry its own copy of the
sqlite_masterquery, with its own idea of what to do with an error.
Structs§
- Migration
Context - Context passed to every migration’s
up()call. - Migration
Error
Enums§
- Migration
Scope - Verify
Outcome - Result of an applied migration’s post-condition check
(
agentmux-srv migrate --verify, SPEC_MIGRATION_SYSTEM_HARDENING_2026_08_03 Phase 1).db_migrationsrecords only thatup()returnedOk— never that it wrote what it was meant to. A migration that can state its own effect as a cheap query implementsMigration::verify; the rest reportNotVerifiableand the doctor pass says so rather than guessing.