Skip to main content

Module runner

Module runner 

Source
Expand description

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).

--prepare and the in-process path report per-migration progress as agentmux_common::srv_stderr’s AGENTMUXSRV-MIGRATION-BEGIN/-END lines on stderr (STDERR_PROGRESS), which the launcher’s splash shows as sub-rows. Plain migrate (no flags) prints newline-delimited JSON on stdout instead, for scripts and operators running it by hand. Failures are written to <home>/logs/migration-error.log; the process exits non-zero so the launcher can surface the error rather than booting with a half-migrated data dir.

Structs§

AppliedIds
Which migration ids each tracking store records as applied, read through a FALLIBLE path. Err means the store exists but its tracking state could not be read (not a database, malformed table, locked): every migration of that scope then reports VerifyOutcome::Error instead of being silently skipped as “unapplied” and letting the pass exit 0 — codex P1 on #3058, which Store::migration_is_applied’s unwrap_or(false) would have caused. A store file that does not exist, or one predating the db_migrations table, has nothing recorded and is Ok(empty).
DoctorReport
The complete migration doctor report for one data dir.
DoctorRow
One registry migration, in registry order.
DoctorSummary
VerifyRecord
One line of the verify report.

Enums§

PendingCountError
Why a pending count could not be determined. Distinguished from “zero pending” on purpose: a caller deciding whether the schema is current must be able to tell “nothing to do” from “I could not tell”, because the safe reaction to each is opposite.

Constants§

VERIFY_FAILED_EXIT_CODE
Exit code of migrate --verify when at least one applied migration’s post-condition is a mismatch or its check errored. Distinct from 1 (a migration RUN failed) so a caller can tell “your data is inconsistent” from “the migrate command itself broke”, and from 2, which clap uses for a CLI usage error (a typoed flag must not read as a data finding — reagent P2 on #3058). See docs/exe-return-codes.md.

Functions§

count_pending_migrations
Return the number of REGISTRY migrations that have not yet been applied, reporting 0 on any error so startup is never blocked.
doctor_report
The doctor report for data_dir, against an explicit registry (tests pass fakes; production passes REGISTRY). Read-only.
doctor_report_for_instance
doctor_report for the running instance’s own registry and resolved shared store / home — what GET /api/v1/muxspect/migrations serves. Err when the shared root can’t be resolved at all (no AGENTMUX_SHARED_DIR, CI), the same condition under which run_migrate_command treats migrations as a no-op.
run_migrate_command
Called from main.rs when the migrate subcommand is active. Returns the exit code (0 = success, 1 = failure, 3 = --verify found a mismatch — see VERIFY_FAILED_EXIT_CODE).
run_pending_migrations
Apply all pending migrations in-process before srv opens its stores.
try_count_pending_migrations
Number of REGISTRY migrations not yet applied, or why that could not be determined.
verify_applied
Run verify() for every migration in regs whose tracking store records it as applied. Generic over the registry slice so the harness can be tested with fakes; production passes REGISTRY.
verify_exit_code
Exit code for a verify report: 0 unless any record is a mismatch or an error. NotVerifiable is not a failure — it is the honest default.