Skip to content

feat: spawn upgrade-spored — in-place, state-preserving spored upgrade (#234) - #240

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/234-upgrade-spored
Jun 24, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/234-upgrade-spored

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Closes #234. Builds on #232 (status shows the running spored version). Two gaps remained: you couldn't tell an upgrade was available, and the only way to get newer spored onto a box was terminate + relaunch — disruptive for long-lived/expensive GPU & Capacity-Block instances, and it loses any un-checkpointed state.

spawn upgrade-spored <instance> [--version X] [--force]

What it does

  • In place, over SSM (keyless — works on private-subnet / no-public-IP instances, matching the project's SSM-first direction). Downloads the versioned, checksum-verified spored artifact, swaps it atomically (rename over the busy binary — no ETXTBSY, mirroring pkg/launcher/bootstrap.go), restarts the daemon, and health-checks that it came back up on the target version — rolling back to the prior binary if not.
  • Default = latest release (spored is versioned in lockstep with spawn, same release tag); --version pins; a downgrade is refused without --force.
  • State preserved. The TTL deadline, accumulated compute-seconds, and the completion / pre-stop / idle / FSx config all live in EC2 tags the new spored re-reads on boot, so the death clock and compute clock continue across the swap. The TTL deadline is absolute and tag-stored, so a mid-life instance keeps its original termination time.
  • Linux only for now — Windows spored upgrade is a follow-up (spored-on-Windows is a native service, Windows spored — cross-platform lifecycle agent as a Windows Service #77).

Also in this PR

  • spawn status flags "spored upgrade available: vX → vY — run 'spawn upgrade-spored …'", best-effort and offline-tolerant (no network → just shows the running version).
  • spored writes its version to the spawn:spored-version tag on boot, so status / upgrade read it without execing in, and an upgrade can confirm the new binary took effect (spawn status should show the spored version running on the instance #232/Upgrade spored on a live instance in place (show latest available + spawn upgrade-spored), preserving state #234).
  • Fix: a graceful spored shutdown now flushes compute-seconds before exiting. The tag was only written on a 1–5 min throttle, so stopping the daemon (including an upgrade) could discard up to ~5 min of compute time; agent.Cleanup now persists the current total so the next start resumes the compute clock without losing the tail.
  • release.yaml uploads the .sha256 to the versioned spored S3 path (spawn/versions/<v>/…) so a pinned --version download can be checksum-verified (only the floating "latest" path had one before).

Tests

buildSporedUpgradeScript (versioned path, regional+fallback, atomic mv, stop/start, health-check+rollback, checksum, fail-fast), compareVersions (incl. downgrade/pre-release/short-version), parseSporedVersion, and the compute-seconds base carry-over invariant. Tier 0 coverage gate updated to classify upgrade-spored. make check green.

Refs

#232 (running version), #76 (authenticity key — a future gate on the upgrade), #77 (Windows upgrade follow-up), lifecycle invariant (an upgrade must not extend or reset the TTL).

#234)

Replace spored on a running instance without terminate/relaunch and without
losing its lifecycle state.

  spawn upgrade-spored <instance> [--version X] [--force]

- Over SSM (keyless — works on private-subnet / no-public-IP GPU & Capacity-Block
  hosts). Downloads the VERSIONED, checksum-verified spored artifact, swaps it
  atomically (rename over the busy binary, no ETXTBSY), restarts the daemon, and
  health-checks that it came back up on the target version — rolling back to the
  prior binary if not.
- Default target is the latest release (spored is versioned in lockstep with
  spawn); --version pins; a downgrade is refused without --force.
- State preservation: the TTL deadline, compute-seconds, and completion/pre-stop/
  idle/FSx config live in EC2 tags the new spored re-reads on boot, so the death
  clock and compute clock continue across the swap (TTL deadline is absolute &
  tag-stored — mid-life instances keep their original termination time).
- Linux only for now (Windows is a follow-up).

Also:
- spawn status flags when a newer spored is available (offline-tolerant).
- spored writes its version to the spawn:spored-version tag on boot, so status /
  upgrade can read it without an exec (#232/#234).
- FIX: a graceful spored shutdown now flushes compute-seconds before exiting.
  The tag was only written every 1–5 min, so stopping the daemon (incl. an
  upgrade) could discard up to ~5 min of compute time; agent.Cleanup now persists
  the current total so the next start resumes the compute clock.
- release.yaml uploads the .sha256 to the versioned spored S3 path so a pinned
  --version download can be checksum-verified.

Tests: script generation, semver compare/downgrade refusal, status version
parse, compute-seconds base carry-over. Tier 0 coverage gate updated.

Closes #234.
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.72727% with 104 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/upgrade_spored.go 62.80% 60 Missing and 1 partial ⚠️
pkg/agent/agent.go 18.51% 21 Missing and 1 partial ⚠️
cmd/status.go 30.76% 17 Missing and 1 partial ⚠️
cmd/spored/main.go 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit fcc8055 into main Jun 24, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/234-upgrade-spored branch June 24, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade spored on a live instance in place (show latest available + spawn upgrade-spored), preserving state

1 participant