Expand description
Self-update, via kaishin.
A magi run takes minutes of agent latency, so a background release check costs nothing measurable: it is spawned on the same tokio runtime as the command, overlaps it, and is drained with a bounded wait at shutdown. It never delays the graph.
Structs§
- Beat
- What the watchdog wants said this tick.
- Checker
- Throttled release checker.
- Handover
Lease - Proof that
hand_overis running: written when it is entered, beaten while it waits on the loop, removed when it leaves. - Lease
Guard - Held by
hand_overfor as long as it runs; removes the lease on drop. - Progress
- One upgrade’s progress, persisted at
progress_path. - Stall
- A non-terminal stage that has outlived what it should take.
- Watchdog
- Decides when the watchdog speaks. Pure: the caller supplies
now.
Enums§
- Pending
- A background update check, resolved at shutdown.
- Stage
- How far a self-upgrade this deck set in motion has gotten.
- Stall
Kind - How a non-terminal stage came to be called stuck.
Constants§
- HEARTBEAT_
SECS - How often the watchdog repeats itself for one stage.
- LEASE_
TTL_ SECS - A handover lease with no beat for this long is not alive. Same idiom as
ask::LEASE_TTL; no pid is consulted. - LOG_
MAX_ BYTES - The log is rotated to
upgrade.log.1(one generation) past this size. - NO_
AUTOUPDATE_ ENV - Env kill-switch. Any non-empty value other than
0/falsedisables the background check, and it is read before the config so a brokenmagi.tomlcannot force a network call. - STALL_
AFTER_ SECS - A non-terminal
replaced/restartingstage older than this is stuck. - WATCHDOG_
POLL - How often the watchdog thread looks at
upgrade.json.
Functions§
- append_
bounded - Append
linetopath, rotating to<path>.1first when the file has reachedmaxbytes. Open-append-close every time, so a rename or a deleted file never leaves a stale handle. - default_
interval - Default interval between checks.
- disabled_
by_ env - Is the background check switched off by the environment?
- effective_
interval - The interval
cfgconfigures, floored at [MIN_INTERVAL], ordefault_intervalwhen unset or unparsable. - fail_
progress - Record
detailas the failure of the upgrade request that is asking, unless a handover is already in flight (parking/restarting): that handover is not this request’s to fail. The check and the write happen under the same lock aswrite_progress, so a handover that recordsparkingin between cannot be overwritten. Returns whether it was written. - finalize
- Drain a pending check and print at most one line.
- lease_
path - Where the
HandoverLeaselives, besideupgrade.json. - live_
lease - The lease, when it proves
hand_overof this upgrade is alive atnow. - log_
path - Where every handover step is appended, beside
upgrade.json. Written by this module directly, so no supervisor redirection of stderr can orphan it. - log_
step - One handover step: to
tracingat INFO and to<home>/upgrade.log, with a UTC timestamp and this process’s pid. Best-effort - a failed write is a warning, never a failed upgrade. - log_
warn - Like
log_step, at WARN. - monotonic
- What to persist when
candidateis written overcurrent. - progress_
path - Where
Progressis recorded: besidedaemon.json, not under the cache dir - seeProgress’s own doc for why the two are not the same place. - read_
lease - The lease on disk, if there is one.
- read_
note - The watchdog’s message for exactly this stage of this upgrade, if any; a note from another stage or another upgrade is ignored.
- read_
progress - The last upgrade this deck recorded, if it has ever started one.
- reconcile_
after_ restart - Reconcile a leftover progress record on startup, before the server starts answering requests.
- repo_
name - This binary’s own repository name, for
--repo .auto-discovery (web::serve,main::resolve_repo) to match a checkout against without a second, driftable copy of [REPO] anywhere else. - run_
self_ update magi self-update.- set_
parked_ talks - Record which chat turns the parked handover is still waiting on. Written
only while the stage is
Stage::Parking, under the same lock aswrite_progress, so a stage that moved on is never touched. - spawn
- Spawn the background check for
cfg, unless it is switched off. - spawn_
watchdog - Run the watchdog on a thread of its own, so a blocked runtime, or a process half-way through dropping one, still speaks. It never ends; it is a daemon thread and dies with the process.
- stage_
age_ secs - Seconds
progresshas been in its stage atnow. A clock that went backwards counts as zero, never as a negative age. - stall
- Pure: whether
progressis stuck atnow. - talks_
phrase - The phrase naming the chat turns a park waits on, empty for none.
- waited_
secs - Seconds
hand_overhas been alive and waiting, whenleaseproves it. - write_
progress - Persist
progress, atomically, never moving an upgrade in progress back to an earlier stage - seemonotonic. - write_
progress_ logged write_progressthat says so when it fails, instead of dropping the error: a progress file that silently stops moving is the symptom this module exists to explain.