Skip to main content

Module migrations

Module migrations 

Source
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.rs to 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 --prepare before srv may open it (S1c of docs/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_content ui:color) for every existing agent definition that doesn’t have one — the “generate a random color for all the existing agents” one-time script from docs/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 a db_accounts fallback mirror (reagentx P0 review, added after this migration’s first version — see identity::resolver::inject::resolve_account’s own doc comment for why the mirror is needed even though db_accounts itself stays on id_store as the authoritative store), from every reachable store into the new, permanently-global identity store — see docs/specs/SPEC_IDENTITY_STORE_SPLIT_2026_08_17.md.
m0023_native_memory_versions_backfill
Backfill db_agent_native_memory_versions with one source: "agent_inferred" version per existing db_agent_native_memory row — 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 via MemoryRevert/MemoryDiff.
m0024_native_memory_backfill_from_fs
Finish the job m0023 was 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, and last_block_id where still empty) from the legacy db_agent_instances rows.
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_directory with the workspace each agent actually ran in, taken from its latest legacy db_agent_instances launch.
m0028_agent_child_tables_repoint_fk
Re-point six agent-child tables’ agent_id foreign key from db_agent_definitions(id) to db_agents(id).
m0029_drop_legacy_agent_tables
Drop db_agent_definitions and db_agent_instances — the two legacy tables the agent-concept consolidation retires.
m0030_backfill_bundle_component_refs
Backfill db_bundle_skills_ref from the inline db_bundles.skills JSON column.
m0031_carry_skills_and_mcp_servers_to_identity_store
Carry each channel’s db_skills / db_mcp_servers rows into the permanently-global identity store, which became authoritative for them in Phase 2a (IDENTITY_STORE_SCHEMA_VERSION v6/v7 — see SPEC_DURABLE_BINDINGS_2026_09_10.md §7 Phase 2).
m0032_drop_catalog_fk_from_ref_tables
Drop the skill_id/mcp_id foreign 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’s agent_id → db_agents FK, every PRIMARY KEY, all column types).
m0033_narrow_skill_global_uniqueness_index
Narrow the global skill uniqueness index from (name, skill_type) to name alone, matching the invariant skill_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 in 0007c6b64051e8 / PR #2605) existed to keep it linked into the always-global shared/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.md Phase 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 local db_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 a cron trigger in UTC and a message action, 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_skills seeded 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 runs migrate --prepare through srv_spawner::run_prepare when srv’s boot gate asks for it) and, separately, in-process at boot via run_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_master query, with its own idea of what to do with an error.

Structs§

MigrationContext
Context passed to every migration’s up() call.
MigrationError

Enums§

MigrationScope
VerifyOutcome
Result of an applied migration’s post-condition check (agentmux-srv migrate --verify, SPEC_MIGRATION_SYSTEM_HARDENING_2026_08_03 Phase 1). db_migrations records only that up() returned Ok — never that it wrote what it was meant to. A migration that can state its own effect as a cheap query implements Migration::verify; the rest report NotVerifiable and the doctor pass says so rather than guessing.

Traits§

Migration