Repository navigation
Description
Repo: spore-host/spawn
Labels (suggested): enhancement, agent, spot
Relates to: the // Future enhancement: Support webhooks, email, SNS… note at pkg/agent/agent.go:1066 (spot-interruption handler)
Summary
Add an optional, launch-configured webhook that spored fires once,
best-effort, from the existing checkSpotInterruption handler when an AWS spot
interruption notice arrives — so an external consumer can learn about the
reclamation inside the ~2-minute warning window, which the current
tag-and-poll surface structurally cannot deliver.
This is deliberately scoped to not change spawn's grain. spawn stays
fire-and-forget: the node still owns its own death, opens no connection it waits
on, and the webhook is a courtesy emit (a write to one more sink, next to the tag
and the local file) — not an outbound relationship spawn maintains.
Motivation
Today the spot-interruption fact is caught on-node within the window
(monitorSpotInterruptions, 5s IMDS poll) and surfaced as: a Slack/notifier ping,
the local file /tmp/spawn-spot-interruption.json (agent.go:1053, not visible
off-node), and — eventually — an EC2 State transition + tag change.
A programmatic, off-node consumer (e.g. a cohort-style reconciler driving
ephemeral jobs) therefore learns about a reclamation only after the instance is
gone, via polling ListInstances. By then the warning window is closed, so the
consumer cannot use it to do the things the window exists for:
- checkpoint partial work before the node dies,
- re-place the job on a fallback/patient rung (
lagotto) proactively, - settle the spent budget as a fault with a reason, rather than inferring a
bareterminatedafter the fact with the reason already lost on-node.
The information already exists, on-node, in time. The only gap is that it isn't
emitted anywhere a machine can consume it within the window. The note at
agent.go:1066 already anticipates exactly this.
Why this belongs in spored (not an external watcher)
The cheapest, most truthful place to surface this fact is where it's already
known — on the node, inside the window. An external watcher (e.g. subscribing to
AWS EventBridge's interruption notice) would rediscover a fact spored already
holds, seconds later, off-node, having lost nothing the node didn't already
have — and it adds a whole new relationship-maintaining component to a system
whose primitives (spawn, lagotto) are uniformly fire-and-forget. A fire-once
webhook from spored is the least-invasive option on every axis: no new
component, no new relationship-shape, and it's the only path that preserves the
window.
The grain is preserved because the boundary that matters is "spawn must never
await", not "spawn must never emit." A best-effort POST that is allowed to
fail and be dropped — exactly as the node itself is allowed to vanish — does not
await. It's another expression of fire-and-forget, identical in spirit to writing
a tag.
Proposed shape
Three new optional LaunchConfig fields (alongside TTL/IdleTimeout/
CostLimit/OnComplete/PreStop/ClientToken):
| Field | Type | Meaning |
|---|---|---|
SpotInterruptionWebhookURL |
string (optional) |
If set, spored POSTs here once on interruption. Empty = disabled (today's behavior). |
WebhookCorrelation |
string (optional, opaque) |
Caller-supplied blob. spored echoes it verbatim in the payload and never parses it. This is how a consumer correlates the event back to its own entity/grant/record without spawn knowing anything about the consumer. |
WebhookTimeout |
duration (optional, small default e.g. 2s) |
Hard cap on the POST so it can never eat the reclamation window. |
Payload: a fixed, stable on-node fact-struct + the opaque echo. spored emits
what it already holds; the caller takes the fields it cares about and ignores the
rest. Proposed body:
{
"event": "spot_interruption",
"instance_id": "i-0abc…",
"region": "us-east-1",
"az": "us-east-1a",
"reason": "spot-interruption",
"interruption_deadline": "2026-06-21T18:42:00Z", // AWS-provided ~2-min window end
"name_tag": "<spawn:name>",
"client_token": "<LaunchConfig.ClientToken>", // load-bearing for cohort/Telos correlation
"compute_seconds": 1234, // already tracked (spawn:compute-seconds, agent.go:580)
"lifecycle_phase": "running",
"last_activity_time": "2026-06-21T18:39:50Z",
"correlation": "<WebhookCorrelation, echoed verbatim>",
"emitted_at": "2026-06-21T18:40:03Z"
}Hard requirements (these are what keep it in-grain)
- Fire-once, best-effort, no retry, no await. A single POST with
WebhookTimeoutcap. Failure (timeout, non-2xx, DNS) is silently dropped —
logged at most. A node mid-reclamation must not block on a POST any more than it
blocks on a tag write. No delivery guarantee is offered or implied; the consumer
must still have a poll-and-infer fallback (the EC2 state + tags remain the
durable source of truth). - Off the critical path. Fire from the existing spot handler, but it must not
gateCleanup/runPreStop/the 2-minute survival work (same discipline as CRITICAL: spored monitor loop never runs after startup — TTL/idle/on-complete/pre-stop all silently dead #65,
which deliberately decoupled the spot monitor so a blocking IMDS call can't
disable TTL enforcement). The webhook is the last thing, time-boxed. - Payload is a projection of on-node knowledge only.
sporedincludes only
fields it already holds. A request for anything off-node is impossible by
construction (there are no caller-supplied "please include X" fields except the
opaque echo). This honors the "assuming spored has it" constraint — the contract
cannot promise a field the node can't produce mid-reclamation. sporednever parsesWebhookCorrelation. Pure passthrough, like a user
tag orClientToken. spawn stays entirely consumer-agnostic.- Opt-in. Empty URL = exactly today's behavior. No new always-on outbound
traffic, no new IAM/SNS dependency, no change for existing users.
Explicitly out of scope (to protect the grain)
- No SNS/EventBridge emission from spawn. That would make spawn maintain a
managed-service relationship; the webhook is a dumb fire-once POST. (A consumer
who wants SNS can point the webhook at their own endpoint that republishes —
their concern, not spawn's.) - No delivery guarantees, no queue, no retry/backoff. Durability lives in the
poll-and-infer fallback, not here. - No general lifecycle webhook (yet). This issue is scoped to spot
interruption specifically, because that's the only lifecycle event where the
window matters — idle-stop and TTL-terminate are benign, non-time-critical, and
perfectly served by tag-and-poll. (If a generalLifecycleWebhookURLis wanted
later, it's a separate discussion; keeping this narrow keeps it in-grain.)
Open question for the maintainer
Fixed payload struct vs. selectable field list? This proposal assumes a
fixed on-node fact-struct (above) plus the opaque echo — simplest, most
in-grain, and a typical consumer wants essentially all of it anyway. A selectable
field list adds a validation surface for marginal benefit. Recommend fixed; flag
if you'd prefer selectable.
Consumer note (non-binding, for context)
The motivating consumer is a cohort-style reconciler (the same shape as
pkg/mpicohort): on receiving the POST it correlates by client_token →
its entity → its budget record, settles the spent compute (compute_seconds) as a
fault (not a completion) with reason, and re-places the job on a patient rung
(lagotto) within the window. The poll-and-infer path (EC2 state + spawn:* tags)
remains the always-correct baseline; this webhook is the in-window upgrade over
it. No change to spawn's responsibilities is implied beyond the fire-once emit.
Activity
scttfrdmn commentedon Jun 21, 2026
Read through this and grounded it against the code — the proposal is sound, in-grain, and the gap is real. One correctness bug in the payload to fix before implementing, plus a couple of small notes.
Confirmed against the code
agent.go:1066is exactly the// Future enhancement: Support webhooks, email, SNS, etc.line, insidesendSpotInterruptionNotification, called fromcheckSpotInterruption(:1039)./tmpfile, and (eventually) an EC2 state/tag change. No machine-consumable, in-window, off-node emit exists.notifier.goalready does a best-effort outboundPOSTwith a 5s timeout (:147/:153). This webhook is the same shape pointed at a caller-supplied URL with a machine payload — so it's not redundant with the existing notifier.interruption_deadline←InterruptionInfo.Time(provider.go:103),compute_seconds←spawn:compute-seconds(written by spored),instance_id/region/az/name_tag/lifecycle_phase/last_activity_timefrom identity + config + agent state.The one real problem:
client_tokenis not on-nodeThe payload lists
client_tokenas "load-bearing for cohort/Telos correlation" — but spored can't see it.provider.Configis populated entirely from EC2 tags (+ IMDS) at startup and periodic refresh.ClientTokenis theRunInstancesidempotency parameter (aws/client.go:124); it is never written as a tag and not exposed via IMDS. So the single field the issue calls load-bearing is the one field the node can't produce — which violates the issue's own hard-requirement #3 ("the contract cannot promise a field the node can't produce mid-reclamation").Recommended fix — cleaner and more in-grain: drop
client_tokenfrom the fixed payload and letWebhookCorrelation(the opaque echo) carry correlation. It's launch-configured, reaches spored through the exact same tag mechanism every other config field uses, is never parsed, and is purpose-built for this. The consumer puts its own client-token / entity / grant ID into the blob.The alternative — start tagging
ClientTokenat launch so spored picks it up — adds an always-written, mildly-sensitive tag for somethingWebhookCorrelationalready covers. Not worth it. Flag if you'd rather go that way, but my recommendation is to removeclient_tokenand rely on the echo.Smaller notes
SpotInterruptionWebhookURL,WebhookCorrelation,WebhookTimeout) should flow asspawn:*tags →provider.Config, consistent with every other field. The opt-in / passthrough requirements fit that mechanism exactly.reason: the proposal hardcodes"spot-interruption", butInterruptionInfo.Actionis"terminate"or"stop"(provider.go:102). Worth echoingactioninto the payload too, so the consumer knows whether it's a terminate or a stop.checkSpotInterruption, after the existing file notification,WebhookTimeout-boxed, never gatingCleanup/runPreStop(the CRITICAL: spored monitor loop never runs after startup — TTL/idle/on-complete/pre-stop all silently dead #65 discipline). The existing SlackNotifyalready runs post-Cleanup, so there's a clean precedent slot.Open question (fixed vs selectable payload)
Agree with your own lean — fixed struct + opaque echo. The echo handles the "I need my own field" case; a selectable list is validation surface for no real gain.
So: net +1 to implement, with one change to the spec — remove
client_token; correlation rides onWebhookCorrelation. Confirm that (and theactionecho) and I'll pick it up.scttfrdmn commentedon Jun 21, 2026
Confirming the review independently against the source (cloned HEAD) — both findings hold, and I agree with the spec change.
client_tokenis genuinely not on-node — confirmedClientTokenis consumed only at theRunInstancescall:pkg/aws/client.go:360-361setsinput.ClientToken = aws.String(launchConfig.ClientToken). That's its only use.spawn:*tag (grep for a client-token tag returns nothing), andprovider.Configis populated "from EC2 tags at startup" + IMDS (pkg/provider/provider.go:63,111,114;ec2.goIMDS path). Neither carries the token.client_tokenin the payload — it would violate the issue's own hard-requirement Raise test coverage on low-coverage packages (aggregate 24.7%) #3. Agreed: dropclient_token; correlation rides onWebhookCorrelation. That field reaches spored through the same tag→provider.Configmechanism as everything else, is never parsed, and is exactly the right home. Not worth taggingClientTokenjust to recover it.reason→ echoaction— confirmedThe IMDS
spot/instance-actiondocument carriesAction∈ {terminate,stop} (pkg/provider/ec2.go:291path,:314struct,:328Action: action.Action). The hardcoded"spot-interruption"loses that. Agreed: echo the AWSactionverbatim (and the consumer can treat the event type asspot_interruptionwhile readingactionfor terminate-vs-stop — they're different axes).One consumer-side consequence worth recording
For the motivating cohort/Telos consumer, correlation-via-
WebhookCorrelation(notclient_token) means the consumer must put its own key into the blob at launch — which is fine, because the consumer is the one that minted the cohortEntityIntent.IdempotencyTokenin the first place (cohortports.go: the token is deterministic in cluster/entity/generation, supplied BY the consumer). So the consumer already holds the value to echo; it just passes it asWebhookCorrelationinstead of relying on spawn to reflectClientTokenback. Net: the correlation story is actually cleaner this way — spawn stays fully consumer-agnostic, and the consumer owns its own correlation key end to end. No spawn-side change needed beyond the two edits above.Net
+1 to the revised spec: fixed payload struct minus
client_token, plusaction, correlation via the opaqueWebhookCorrelationecho. Everything else in the proposal (fire-once/best-effort/no-await,WebhookTimeout-boxed, fired last after the existing file/Slack notify per the #65 discipline, opt-in) is confirmed in-grain against the code. Good to implement as revised.feat: optional fire-and-forget spot-interruption webhook (#228) (#229)
feat(agent): completion webhook + always-on heartbeat tag (#497) (#498)