Repository navigation
Description
Summary
A --pre-stop hook did not run (or did not complete effectively) when an instance was
terminated by TTL expiry, causing total loss of the job's output. --pre-stop exists
precisely to flush results before a lifecycle-triggered stop/terminate — but on the TTL path
it didn't save the data, which is the exact scenario it's meant to protect.
What happened
spawn launch ... --ttl 48h --pre-stop 'aws s3 sync ~/output s3://bucket/...'- Long-running GPU job (SAM inference) was still in progress at 48h.
- At exactly T+48h, spawn terminated the instance ("User initiated" per StateTransitionReason).
- The pre-stop sync did not land any files in S3 — output was lost.
- Output lived on the instance-store NVMe (ephemeral, wiped on terminate), so there was no
second chance to recover.
Why this is a data-loss bug, not just user error
The whole point of --pre-stop is "run this before any lifecycle-triggered stop/terminate so
results are flushed." A TTL expiry IS a lifecycle-triggered terminate. If pre-stop doesn't
reliably run-to-completion on the TTL path, the hook gives a false sense of safety.
Questions for maintainers:
- Does the TTL reaper invoke
--pre-stopat all, and does it WAIT for it to complete before
issuing the terminate? (The spawn#70/Idle-stopped instances have no daemon → TTL can never fire locally; they bill EBS indefinitely #71 out-of-band reaper may terminate without going
through spored's pre-stop path.) - If pre-stop ran, did it race the instance-store teardown / lose network before finishing a
multi-GB sync? --pre-stop-timeoutdefault is 5m — a large sync can exceed that. Is the timeout enforced
as "kill the sync and terminate anyway"? If so, partial/zero sync on big outputs is expected
and should be documented loudly.
Suggested
- Guarantee
--pre-stopruns to completion (up to--pre-stop-timeout) on the TTL-terminate
path, same as on idle/completion paths. - If pre-stop can't be guaranteed on TTL-terminate (e.g. the out-of-band reaper bypasses spored),
document that explicitly — pre-stop is then NOT a safety net for TTL, only for idle/on-complete,
and users must not rely on it for TTL. - Consider a T-minus warning event (like the idle/ttl warnings spored already emits) that gives
pre-stop a head start before the hard terminate deadline.
Impact
Lost 48h of g5.12xlarge compute ($270) and ~110k detections on a science workload, because
the data was on ephemeral storage and pre-stop didn't flush it before TTL terminate. Mitigations
on our side (persistent EBS, periodic incremental S3 upload, longer TTL) are real and we'll apply
them — but pre-stop silently not protecting the TTL case is the spawn-side gap.
Version
spawn v0.45.1
Activity
scttfrdmn commentedon Jun 16, 2026
Correction — this is a dup of #63 (pre-stop runs as root), not a 'pre-stop didn't run on TTL' bug
Dug further. The pre-stop hook did run on the TTL-terminate path — my original framing was wrong. The actual failure is #63: pre-stop runs as root, so
~resolved to/root, and our hookaws s3 sync ~/output s3://...synced the empty/root/outputinstead of the real output at/home/ec2-user/output(symlinked to the instance-store/scratch/output). It 'succeeded' syncing nothing.So:
~/$HOME is root's, not the workload user's, so any hook referencing~,$HOME, or a relative path silently targets the wrong location.This is exactly the least-surprise failure #63 predicts ('Wrong $HOME / environment vs. how the workload ran'). Closing this as a duplicate of #63 — but flagging that #63 is higher-severity than 'consistency/ownership': it causes silent data loss for the canonical pre-stop use case (
aws s3 sync ~/results ...), which is the flag's own documented example. Recommend bumping #63's priority accordingly.Workaround until #63 lands: use absolute paths in --pre-stop (
aws s3 sync /home/ec2-user/output ...), never~or relative paths.scttfrdmn commentedon Jun 16, 2026
Duplicate of #63 (pre-stop runs as root). See analysis above.
scttfrdmn commentedon Jun 16, 2026
Dug into the code. There are two TTL-terminate paths with different pre-stop guarantees, and your three questions land exactly on the seam:
Path 1 — spored (in-instance): pre-stop does run to completion
TTL expiry in the monitor loop calls
a.terminate(ctx, "TTL expired")(pkg/agent/agent.go:337), andterminate()runsrunPreStop()synchronously beforeprovider.Terminate()(agent.go:1224-1243).runPreStopblocks oncmd.Run()up to the timeout, then proceeds. So when spored is healthy, pre-stop is honored on the TTL path — same as idle/on-complete.Path 2 — ttl-reaper (out-of-band Lambda): pre-stop is bypassed entirely
The #70/#71/#72 backstop reaper calls
TerminateInstancesdirectly (lambda/ttl-reaper/main.goterminate()) — no pre-stop, no SSM RunCommand, no grace (git log -S SendCommand/PreStopon that dir is empty — it never did). By design it's a dumb "kill it no matter what" backstop for when spored is dead. So your Q1 is the real gap: if the reaper does the terminating, pre-stop never runs. Confirmed.Which path hit you — and why I suspect it's actually the timeout, not the reaper
Two things point away from the reaper for your specific run on v0.45.1:
terminate()→ which does run pre-stop. Which makes Q3 the likely culprit:--pre-stop-timeoutdefaults to 5 minutes, andrunPreStopenforces it as "kill the sync and terminate anyway" (agent.go:1212-1219: onDeadlineExceededit logs "timed out — proceeding with shutdown" and returns). A multi-GBaws s3 syncof a 48h SAM run almost certainly blew past 5 min → spored killed the sync mid-flight and terminated → partial/zero objects in S3, and the NVMe was wiped. That matches "pre-stop did not land any files" far better than a silent bypass would.StateTransitionReason: "User initiated"is consistent with either an API terminate (reaper) or spored's ownprovider.Terminatecall — it doesn't disambiguate.The one diagnostic that settles it
The instance is gone, but spored's log is the tell if you captured it (it streams to the console/serial log, and if your
--pre-stopitself didn't redirect, CloudWatch agent/console). Look for one of:Running pre-stop hook (timeout: 5m0s): aws s3 sync …followed byPre-stop hook timed out after 5m0s — proceeding with shutdown→ timeout (Q3), orRunning pre-stop hookline at all near the end → reaper bypass (Q1).If you don't have the log, the timeout is the safer bet to fix first.
Suggested fixes (I'll implement once you confirm direction)
--pre-stop-timeout(and ideally periodic incremental upload, which you noted). I'd also add apre_stop_timeoutwarning notification when it fires so the truncation isn't silent.TerminateInstances, fire pre-stop via SSM RunCommand with a bounded wait, then terminate regardless. Keeps the hard backstop but tries the flush first. More work; only matters when spored is actually dead.Want me to start with the timeout hardening + docs (covers your most-likely case and is low-risk), and file the reaper-graceful-tier as a separate tracked enhancement? Also: do you have the spored log line from that instance? It'd confirm which path before I touch code.
fix(spored): run --pre-stop as the instance user, not root (#63) (#185)
chore(release): v0.54.0 (#188)
feat(spored): loud pre-stop failure/timeout notifications (#186) (#189)
feat(ttl-reaper): reclaim orphaned FSx Lustre filesystems (refcount-a…