Skip to main content

Module srv_stderr

Module srv_stderr 

Source
Expand description

The stderr line protocol agentmux-srv uses to talk to whichever process supervises it — the launcher in packaged builds and task dev (crates/launcher/src/srv_spawner.rs), or the CEF host in task dev:standalone (crates/cef/src/sidecar.rs).

srv formats these lines; both supervisors parse them. Putting the vocabulary here means one definition instead of three string literals that have to stay byte-identical by convention (the “keep in sync” pattern docs/reports/REPORT_DRY_AND_MODULARITY_AUDIT_2026_09_06.md §2 counts 334 instances of).

Every line is single-line and prefix-tagged. In startup order:

  • AGENTMUXSRV-MIGRATING migrations:<n> — in-process migrations are about to run; supervisors extend their ESTART deadline. A new version’s first start prints AGENTMUXSRV-MIGRATING copying-previous-version:<v> before copying the previous version’s databases (migrations/carry_forward.rs); supervisors match the prefix only (migrating_line, is_migrating_line).
  • AGENTMUXSRV-MIGRATION-BEGIN id:<id> description:<text> / AGENTMUXSRV-MIGRATION-END id:<id> duration_ms:<n> — one pending migration is starting / has finished, inside the AGENTMUXSRV-MIGRATING window above. Before these existed, a slow migration was invisible past the initial count — the splash showed a bare, silently-running “Backend startup” clock with no indication anything unusual (a multi-minute migration) was happening inside it. See docs/reports/REPORT_SPLASH_SCREEN_ARCHITECTURE_RETHINK_2026_09_14.md §2.1. Only the launcher supervisor turns these into splash sub-rows (against the already-open backend stage — a migration is not a separate top-level stage, it happens entirely inside that one); the CEF-host sidecar has no splash to report to and simply logs them like any other stderr line, same as it already did for the unparsed line before this existed.
  • AGENTMUXSRV-STEP-BEGIN id:<id> label:<text> / AGENTMUXSRV-STEP-END id:<id> duration_ms:<n>[ status:error] — one data-preparation step besides a migration: copying the previous version’s data, a snapshot, waiting for another AgentMux’s migrations, the backup. Written by srv’s startup and by agentmux-srv migrate --prepare; the launcher shows each as a sub-row of backend, like a migration.
  • AGENTMUXSRV-NEEDS-PREPARE reason:<text> — srv was started by a supervisor that prepares data (SUPERVISOR_PREPARES_ENV) and found data that needs preparing (a previous version to copy forward, or pending migrations); it exits NEEDS_PREPARE_EXIT before writing anything, and the supervisor runs agentmux-srv migrate --prepare, then starts it again.
  • AGENTMUXSRV-MIGRATION-FAILED error:<text> — a migration failed and srv is about to exit 1 without emitting ESTART. Added by Phase 1 of docs/specs/SPEC_MIGRATION_SYSTEM_HARDENING_2026_08_03.md; before it, a failed migration was a warn! and srv booted anyway against a store in an unknown state.
  • AGENTMUXSRV-ESTART ws:<addr> web:<addr> version:<v> buildtime:<t> instance:<id> pending_migrations:<n> — ready (Estart).
  • AGENTMUXSRV-EVENT:<json> — a startup event for the launcher to log (parse_event_line).
  • AGENTMUXSRV-UPGRADE version:<v> [approved:<how>:<id>] launcher:<path> (a portable) or … installer:<path> (a setup.exe install; the digest is sha256:<hex> before it). The optional approved: token says who approved the restart; the launcher skips it. Any time after ESTART: the user chose “Upgrade & restart” and <path> is the launcher, or the installer, of a release srv downloaded and verified. The launcher checks it again, asks the user itself, and restarts into it (crates/launcher/src/upgrade_restart.rs).

Structs§

Estart
The fields of an ESTART_PREFIX line. Endpoints are host:port.
MigrationBegin
A parsed MIGRATION_BEGIN_PREFIX line.
MigrationEnd
A parsed MIGRATION_END_PREFIX line.
StepBegin
A parsed STEP_BEGIN_PREFIX line. Ids are code-chosen, without spaces.
StepEnd
A parsed STEP_END_PREFIX line.
UpgradeRequest
A parsed UPGRADE_PREFIX line: upgrade to version through target.

Enums§

Declined
Why the restart question ended without a restart: the second line of UPGRADE_DECLINED_FILE (the first is the version). srv says it in words to the user and to the agents that asked.
UpgradeTarget
What an upgrade restarts into.

Constants§

DATA_DIR_HELD_EXIT
srv’s exit code when another srv already holds this data folder’s srv.lock: one srv per set of databases (desktop app, agentmux start/run, a service). A refusal that does not clear until that server is closed, so a supervisor must not start it again by itself; the launcher shows the person a plain sentence instead of a failed start (task #49109).
ESTART_PREFIX
Prefix of the line srv writes when it is ready to serve.
EVENT_PREFIX
Prefix of a startup event line; the rest of the line is its JSON.
INSTALL_RESULT_FILE
Where the Linux launcher leaves why a .deb/.rpm upgrade didn’t happen, in updates/<version>/ of the data folder: JSON {"version": "<v>", "error": "<one line>"}. Left when the password was refused or unavailable, the file failed its checks, or the install failed (the waiter that restarts the old version writes it). srv shows it in the version panel.
MIGRATING_PREFIX
Prefix of the line srv writes before slow work that precedes ESTART (migrations, copying the previous version’s data); supervisors extend their ESTART deadline when they see it.
MIGRATION_BEGIN_PREFIX
Prefix of the line srv writes to stderr just before applying one pending migration.
MIGRATION_END_PREFIX
Prefix of the line srv writes to stderr just after one migration applies successfully. (No -END line is written on failure — up() returning Err goes straight to AGENTMUXSRV-MIGRATION-FAILED and srv exits.)
MIGRATION_FAILED_PREFIX
Prefix of the line srv writes to stderr immediately before exiting 1 because run_pending_migrations failed. Supervisors match on this to fail fast with the real reason instead of waiting out the ESTART timeout.
NEEDS_PREPARE_EXIT
srv’s exit code after an AGENTMUXSRV-NEEDS-PREPARE line.
NEEDS_PREPARE_PREFIX
Prefix of the line srv writes, under SUPERVISOR_PREPARES_ENV, before exiting because its data needs migrate --prepare.
SHARED_FOLDER_HELD_EXIT
srv’s exit code (and migrate’s) when another AgentMux of a different version holds the shared folder and this version’s data needs preparing first: a refusal that does not clear until that AgentMux is closed, so a supervisor must not start it again by itself.
SHARED_FOLDER_HELD_PREFIX
Prefix of the line srv writes just before exiting SHARED_FOLDER_HELD_EXIT.
STEP_BEGIN_PREFIX
Prefix of the line srv writes when a data-preparation step starts.
STEP_END_PREFIX
Prefix of the line srv writes when that step ends.
SUPERVISOR_PREPARES_ENV
Set to 1 by a supervisor that runs agentmux-srv migrate --prepare itself (the launcher). srv then never copies, snapshots or migrates at boot: it checks read-only and exits NEEDS_PREPARE_EXIT when the data needs it. Without it (headless srv, task dev:standalone) srv prepares in-process.
UPGRADE_DECLINED_FILE
What the launcher leaves in updates/ of the data folder when the user answered No to the restart question, or the question lapsed: the version it asked about. srv reads it to stop saying “Restarting” (the launcher has no other way to tell it), so the user can start the upgrade again at once.
UPGRADE_PREFIX
Prefix of the line srv writes when the user chose “Upgrade & restart”.

Functions§

declined_text
The contents of UPGRADE_DECLINED_FILE: the version, then why.
estart_line
is_migrating_line
migrating_line
AGENTMUXSRV-MIGRATING <what>:<detail>, e.g. migrations:3.
migration_begin_line
Migration ids (m.id(), e.g. "0020_agent_color_backfill") are a fixed, engineer-chosen identifier format with no spaces — never free text — so splitting id:<id> description:<text> on the first space is safe and exact, unlike description itself which is flattened via one_line.
migration_end_line
migration_failed_line
Format the failure line srv emits. The error text is flattened to a single line (the protocol is line-delimited; a multi-line SQLite error would otherwise split into one tagged line and several untagged ones).
needs_prepare_line
parse_declined
The version and the reason a UPGRADE_DECLINED_FILE holds. A file with only a version (an older launcher’s) has no reason.
parse_estart_line
Parse an ESTART_PREFIX line; None for any other line. A missing field reads as empty (or 0), as both supervisors always read it.
parse_event_line
The JSON of an EVENT_PREFIX line; None for any other line.
parse_migration_begin_line
Parse a MIGRATION_BEGIN_PREFIX line. None for any other line, or a begin line missing the id: field it cannot be meaningfully split without.
parse_migration_end_line
Parse a MIGRATION_END_PREFIX line. None for any other line, a malformed one, or a non-numeric/missing duration_ms: field.
parse_migration_failed_line
Parse a stderr line. Returns the error message if this is a MIGRATION_FAILED_PREFIX line, None for any other line. Tolerates a missing error: field and never returns an empty message, so callers can put the result straight into a user-facing dialog.
parse_needs_prepare_line
The reason of a NEEDS_PREPARE_PREFIX line; None for any other line.
parse_shared_folder_held_line
The owner and the reason of a SHARED_FOLDER_HELD_PREFIX line; None for any other line.
parse_step_begin_line
parse_step_end_line
parse_upgrade_line
Parse an UPGRADE_PREFIX line. None for any other line, or one missing a field (an installer needs its 64-hex-digit sha256:). A confirmed:1 token after version: sets UpgradeRequest::confirmed (any other value of it does not); an approved:<how>:<id> token is skipped.
shared_folder_held_line
AGENTMUXSRV-SHARED-FOLDER-HELD owner:<who> reason:<why the data needs preparing>.
step_begin_line
step_end_line
upgrade_line
The path goes last: it can hold spaces. confirmed adds confirmed:1 after the version: the restart is already decided, so the launcher asks nothing more (UpgradeRequest::confirmed).