Skip to content

feat(spot): default spotInterruption on; wire template to UseSpot#141

Merged
lionello merged 1 commit into
masterfrom
feat/spot-interruption-default-on
Jul 22, 2026
Merged

feat(spot): default spotInterruption on; wire template to UseSpot#141
lionello merged 1 commit into
masterfrom
feat/spot-interruption-default-on

Conversation

@defangdevs

Copy link
Copy Markdown
Owner

Why

The EC2 Spot interruption handler (issue #20) shipped behind mkEnableOption, so it defaulted off. A box can therefore run on Spot with the feature present in the deployed module but no monitor unit instantiated.

That's exactly what bit a live box today: a Spot interruption stopped it on the ~2-minute notice, no agent was prompted to persist context, and an in-progress session was lost. Investigation confirmed the deployed rev contained the feature, but services.agent-box never set spotInterruption.enable, and the default was false → no agent-box-spot-monitor.service.

What

  • modules/agent-box.nixspotInterruption.enable becomes a bool mkOption defaulting to true (was mkEnableOption, forced-off). Safe as an on-by-default: the monitor reads instance-life-cycle at startup and exits immediately on a non-Spot/dev box (or when IMDS is unreachable). This is the "fix for all users" — every module consumer (hosts/vm.nix, hosts/bare-metal.nix, flake.nix, hand-written configs) now gets it by default.
  • aws/template.yaml — new installs get the flag from the CFN Spot parameter: spotInterruption.enable = ${UseSpot};. UseSpot is AllowedValues: ['true','false'], so it splices verbatim as a Nix boolean (resolves as a direct parameter Ref inside the Fn::Sub, same as the existing ${Agent}/${UserName}). On-demand boxes omit the monitor unit outright.

Impact on already-deployed boxes

Boxes whose configuration.nix doesn't set spotInterruption (i.e. those deployed before the feature existed) inherit the new default on the next agent-box-update.service run — the pin fast-forwards, the module is re-fetched, nixos-rebuild switch applies the new default, and the monitor unit gets created. No manual root edit required.

Validation

  • nix-instantiate --parse modules/agent-box.nix passes.
  • Confirmed UseSpot is not shadowed by the Fn::Sub variable map, so ${UseSpot} resolves as a template-parameter Ref.

🤖 Generated with Claude Code

@lionello
lionello marked this pull request as draft July 22, 2026 11:15
…ent config dir

The EC2 Spot interruption handler (issue #20) shipped behind an
mkEnableOption, so it defaulted off. A box could then run on Spot with
the feature present in the module but no monitor unit instantiated —
exactly what bit a live box today: an interruption stopped it on ~2 min
notice with no agent prompted to persist context, losing an in-progress
session.

- modules/agent-box.nix: make spotInterruption.enable a bool option
  defaulting to true (was mkEnableOption, forced-off). The monitor
  self-gates on instance-life-cycle and exits at once on non-Spot/dev
  boxes, so on-by-default is safe. Already-deployed boxes whose
  configuration.nix doesn't set the flag inherit the new default on the
  next agent-box-update.service run — no config edit needed.
- aws/template.yaml: set spotInterruption.enable = ${UseSpot} so new
  installs tie it to the CFN Spot parameter; on-demand boxes omit the
  monitor unit outright.
- Notify shell sessions too, instead of skipping them: a shell executes
  typed text as a command, so the notice is prefixed with '#' to land as
  a harmless comment the operator still sees in scrollback (no Escape —
  nothing to interrupt, and Escape+'#' hits readline meta bindings).
- Document the config location in the embedded AGENTS.md: name
  ~/.config/agent-box/ as the config dir and note that its `env` file
  ignores blank/`#`-comment lines, so it can be annotated. Magic
  filenames aren't discoverable; a commented, documented config is.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JkQjyhaueHL7GbnA6obZNQ
@defangdevs
defangdevs force-pushed the feat/spot-interruption-default-on branch from 8dda5fc to 9188d53 Compare July 22, 2026 11:33
@lionello
lionello marked this pull request as ready for review July 22, 2026 11:35
@lionello
lionello merged commit f1d086d into master Jul 22, 2026
2 checks passed
@lionello
lionello deleted the feat/spot-interruption-default-on branch July 22, 2026 11: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.

3 participants