Skip to main content

Module slug_migration

Module slug_migration 

Source
Expand description

The fork slug migration (docs/specs/SPEC_FORK_SLUG_MIGRATION_2026_10_22.md §4 Phase 2): an operation the operator starts, never a boot step, that gives each pre-fix fork the id fork_slug gives (loap-loap-2 → loap-2) and keeps the old one as a former slug, which Phase 1 already routes and reserves.

  • Plan (plan.rs, the default): candidates by §5.1, a collision check across every definition, every objects.db on disk and every live registration, and every place the old slug is stored. Changes nothing. It also reports slugs two agents hold (duplicates.rs), with a proposed id for the later one, and renames neither.
  • Holders (holders.rs): the same stores read in one pass, which a new agent’s slug is picked against too (Store::agent_def_insert).
  • Preconditions (preconditions.rs): the agents run nowhere on this host, every running AgentMux understands former slugs (stamp.rs), and the host-wide lock shared/locks/slug-migration.lock is taken.
  • Backup (backup.rs) into shared/backups/slug-migration-<ts>/.
  • Apply (run.rs, steps*.rs): S1–S8 per agent, parent first, each recorded in the write-ahead journal (journal.rs) before and after it runs; then verify (verify.rs) before the next agent.
  • Roll back: from the journal, step by step, or by restoring the backup while nothing has changed since.

It works on the disk, not on this instance’s stores, so it covers every channel and version and runs the same from the CLI (agentmux-srv migrate-fork-slugs) and from agents.migrateForkSlugs.

Re-exports§

pub use holders::HostSlugs;
pub use home::Home;

Modules§

backup
The copy a run takes before its first write (§4 Phase 2, “Back up”): every database it will touch through SQLite’s VACUUM INTO (db_copy::copy_database, never a raw copy of a file in WAL mode), and every other file it will change or delete as it is, each with its SHA-256 in the journal. Also the digests restore mode compares.
duplicates
The plan’s report of slugs more than one agent holds (two uids, one slug). New agents can’t get one any more (HostSlugs and the shared definitions are checked under the slug allocation lock), but builds before that left some: an agent made in each of two channels picked the same slug, unique in its own objects.db, and both were published. Reported, with the id a rename could give each holder after the oldest; nothing here renames anything.
holders
Who holds a slug on this host outside the shared definitions: every objects.db on disk (a row’s slug, a former slug, a former display name’s route) and every live registration. A new agent’s slug is picked against these as well as the shared definitions, under the host-wide slug allocation lock, so a row only one channel or version knows (an agent from before the shared definitions, a template launch, a copy that was never published) can’t be given to a second agent; and the definition mirror reads them before it publishes a slug. The same holders plan::holder_of checks, read in one pass.
home
Where a migration looks: the AgentMux root and every install on it, read from the disk rather than from the running instance, so every channel and version is covered, running or not (S2’s “all channels and versions”).
journal
The write-ahead journal, journal.jsonl in the run’s backup folder: one JSON record per line, appended and synced before the next write it describes. A step’s intent (with its before-image) is recorded before the step runs and its result after, so a run that stops anywhere resumes at the first step without a result, and a rollback knows what to undo.
locations
The plan’s list of every place an agent’s old slug is stored (K1–K13 of the spec’s §3), read through each step’s own before-image, so the plan shows exactly what a run would touch and nothing it wouldn’t.
plan
The plan: which agents are candidates (§5.1), what each would be renamed to, whether that id is free everywhere it could be held, and every place the old one is stored. Reads only; nothing here writes.
preconditions
What must hold before a run writes anything (§4 Phase 2, “Preconditions”): the agents run nowhere on this host, every AgentMux running here understands former slugs, and no other migration is under way.
run
A run: plan, preconditions, backup, then each agent’s steps through the journal and its verification, agent by agent (§5.2); and the two ways back, journal mode and restore mode.
running
Whether an agent runs anywhere on this host, from what every instance leaves on disk: its lease (a pane holds one for its process’s life, a turn for the turn), its registrations in the cross-channel registry, and each version’s own registrations. Read from the files, never by asking an instance, so a channel that doesn’t answer is still seen.
stamp
What a running srv can do, written beside its databases at startup (<data>/srv-features.json), so a migration can tell whether every AgentMux running on this host understands former slugs before it renames one (SPEC_FORK_SLUG_MIGRATION_2026_10_22.md §4 Phase 2, preconditions).
steps
The steps S1–S8, each as three parts: the before-image it records in the journal’s intent, the change it makes, and its undo. Every change is idempotent (it rewrites only what still holds the old value, so a second run changes nothing), and both a change and its undo work from the recorded before-image, never from a fresh look, so a step interrupted halfway is finished or reversed the same way. Database steps are in steps_db.rs, file steps in steps_files.rs.
steps_db
The database steps: S2 (every objects.db’s slug and former slugs), S3 (name-keyed signing keys), S4 (wan.db), S5 (the MuxBus credential, kept), S6 (name-only rows) and S7’s rows (persisted cmd:env). Each runs in one transaction per database, through a raw connection, so another version’s objects.db is changed only where the step says and is never upgraded.
steps_files
The file steps: S1 (the shared definition, through its record lock), the workspace .mcp.json half of S7, and S8 (the gh-<slug> folders, the bashwrap cwd file, stale registrations). Writes go through a temporary file and a rename. An undo restores the backup’s bytes when the file is still what the step left, so a reverted file is byte-identical; a file changed since is reverted field by field (S1) or left as it is, and said so.
verify
§4 Phase 2 step 5: re-read every location after an agent’s steps and say what is wrong, if anything. The new slug everywhere; the old one only as a former slug; no signing key under the old name; and both names resolve to the uid, by the same rule message delivery uses (Store::former_name_owner, which resolves former slugs and former display names alike).

Functions§

plan
The plan for home; quick finds the candidates only.
plan_choosing
The plan for home with ids the user picked for some agents (choices).
report_summary
A report as text: what changed, what is left, and the searches to run.
run
plan, apply, rollback or restore on home. stop needs the running instance and is the RPC’s.
run_choosing
[run] with ids the user picked for some agents; plan and apply take them, the other modes ignore them.
run_cli
agentmux-srv migrate-fork-slugs: print the result’s summary and its JSON; exit 0 on success, 1 on a refusal or an error.