Skip to content

feat: optional fire-and-forget spot-interruption webhook (#228) - #229

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/spot-interruption-webhook
Jun 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/spot-interruption-webhook

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #228.

What

Adds spawn launch --spot-webhook-url <url> (+ --webhook-correlation,
--webhook-timeout). On an AWS spot interruption notice, spored fires a
single, best-effort POST so an off-node consumer (e.g. a cohort-style
reconciler) learns about the reclamation inside the ~2-minute window — the
one thing the tag-and-poll surface structurally can't deliver.

This implements the agent.go:1066 // Future enhancement: Support webhooks…
note the issue cites, exactly as scoped in the issue + the maintainer/filer
review thread.

Payload (fixed struct + opaque echo)

{
  "event": "spot_interruption",
  "instance_id": "i-0abc…", "region": "us-east-1", "az": "us-east-1a",
  "action": "terminate",                         // AWS verbatim: terminate|stop
  "interruption_deadline": "2026-06-21T18:42:00Z",
  "name_tag": "mpi-node-0",
  "compute_seconds": 1234,
  "last_activity_time": "2026-06-21T18:39:50Z",
  "correlation": "<echoed verbatim>",
  "emitted_at": "2026-06-21T18:40:03Z"
}

Per the review thread — no client_token. It is not on-node: spored's
config comes from spawn:* tags + IMDS, and the RunInstances ClientToken is
neither tagged nor in IMDS. Correlation rides on the opaque --webhook-correlation
blob instead (the consumer already mints its own key), so spawn stays fully
consumer-agnostic. The payload also echoes the AWS action (terminate vs stop),
which the issue's hardcoded "spot-interruption" reason would have lost.

In-grain guarantees (spawn never awaits)

  • Fire-once — the spot monitor re-enters checkSpotInterruption every 5s; a
    guard ensures exactly one POST.
  • Time-boxed — --webhook-timeout (default 2s) hard-caps it so it can't eat
    the reclamation window.
  • Fired last — after the existing file notification, so a slow/dead endpoint
    can't delay Cleanup/runPreStop/the survival work (the CRITICAL: spored monitor loop never runs after startup — TTL/idle/on-complete/pre-stop all silently dead #65 discipline).
  • Best-effort — disabled / timeout / DNS / non-2xx is logged at most and
    dropped. EC2 state + spawn:* tags remain the durable source of truth.
  • Opt-in — empty URL = today's behavior exactly.

Plumbing

Follows the existing pre-stop / on-complete path verbatim: three LaunchConfig
fields → spawn:spot-webhook-url / spawn:webhook-correlation /
spawn:webhook-timeout tags (written only when a URL is set) → provider.Config
on-node. Also surfaces the instance AZ on-node from the IMDS identity document
(idDoc.AvailabilityZone) for the payload.

Tests

  • pkg/agent: emit payload + correlation echo + asserts no client_token;
    opt-in disabled (no URL → no POST); best-effort drop on 5xx; fire-once.
  • pkg/aws: buildTags writes the three tags only when a URL is set.
  • test/e2e: TestTier0_Launch_SpotWebhookTags — flag→tag round-trip against Substrate.

make check green; full Tier-0 e2e suite green.

Adds `spawn launch --spot-webhook-url <url>`: on an AWS spot interruption
notice, spored fires a single best-effort POST so an off-node consumer learns
about the reclamation inside the ~2-minute window — which the tag-and-poll
surface structurally cannot deliver.

The payload is a fixed projection of on-node facts (instance/region/az, the AWS
`action`, the interruption deadline, accumulated compute-seconds, last-activity)
plus an opaque `--webhook-correlation` blob echoed back verbatim for the consumer
to correlate against its own record. Per the issue review, the payload does NOT
carry the RunInstances ClientToken: it isn't on-node (spored's config comes from
spawn:* tags + IMDS), so correlation rides on the opaque echo instead — keeping
spawn fully consumer-agnostic.

Stays in-grain (fire-and-forget, never awaits):
  - fire-once (the spot monitor re-enters every 5s), no retry
  - `--webhook-timeout` (default 2s) hard-caps the POST
  - fired LAST in checkSpotInterruption, after the file notification, so a slow
    or dead endpoint can't delay Cleanup/pre-stop/the survival work (#65 discipline)
  - failure (disabled, timeout, DNS, non-2xx) is logged at most and dropped; the
    EC2 state + spawn:* tags remain the durable source of truth
  - opt-in: empty URL = today's behavior exactly

Plumbing follows the existing pre-stop/on-complete path: three LaunchConfig
fields → spawn:spot-webhook-url / spawn:webhook-correlation / spawn:webhook-timeout
tags → provider.Config on-node. Also surfaces the instance AZ on-node from the
IMDS identity document (idDoc.AvailabilityZone) for the payload.

Tests: emit payload/echo + no-client_token, opt-in disabled, best-effort drop,
fire-once (pkg/agent); buildTags opt-in tagging (pkg/aws); flag→tag round-trip
e2e (TestTier0_Launch_SpotWebhookTags).
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.11111% with 44 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 60.34% 19 Missing and 4 partials ⚠️
pkg/provider/ec2.go 0.00% 16 Missing ⚠️
cmd/launch.go 37.50% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e1aa9e2 into main Jun 21, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/spot-interruption-webhook branch June 21, 2026 22:24
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.

Optional fire-and-forget spot-interruption webhook (the named agent.go:1066 enhancement)

1 participant