Repository navigation
Closed
Labels
area:lifecycleTTL / idle / on-complete / hibernation / reaperarea:storageFSx / EFS / S3 stagingenhancementNew feature or request
Description
Follow-up to #184. Confirmed gap, lower urgency than #63 but real.
Problem
There are two TTL-terminate paths with different --pre-stop guarantees:
- spored (in-instance): TTL expiry →
Agent.terminate()→runPreStop()runs to completion beforeprovider.Terminate()(pkg/agent/agent.go). pre-stop is honored. ✅ - ttl-reaper (out-of-band Lambda, Server-side TTL reaper: out-of-band backstop so a spore can never outlive its deadline (even if spored is dead) #70/Idle-stopped instances have no daemon → TTL can never fire locally; they bill EBS indefinitely #71/Guardrail: TTL must always terminate — never add a TTL→stop mode #72):
lambda/ttl-reaper/main.goterminate()callsTerminateInstancesdirectly — no pre-stop, no SSM RunCommand, no grace.git log -S SendCommand/PreStopon that dir is empty; it never did.
The reaper is deliberately a dumb "kill it no matter what" backstop for when spored is dead/wedged. But that means: whenever the reaper is the one terminating, --pre-stop never runs, and the user's data flush is skipped. Today the reaper runs in dry-run, but it gates to enforce mode once the authenticity-key work lands — at which point this becomes a live data-loss path for any instance spored failed to reap gracefully.
Suggested
Give the reaper a graceful tier before the hard kill:
- If the instance has a
spawn:pre-stoptag and is SSM-reachable, fire the hook via SSM RunCommand (as thespawn:local-usernameuser, per --pre-stop runs as root, should run as the instance user #63), with a bounded wait (the tag'spre-stop-timeout, capped — the reaper is still a backstop, not a babysitter). - Then
TerminateInstancesregardless of the hook's outcome — the hard-deadline guarantee (Guardrail: TTL must always terminate — never add a TTL→stop mode #72) is preserved; we just try the flush first. - Skip gracefully (and terminate immediately) if SSM isn't reachable or the instance has no pre-stop — don't let a graceful attempt weaken the backstop.
Caveats / scope
- This only matters when spored didn't run pre-stop itself (spored dead, or never installed). When spored is healthy, path 1 already covers it.
- Keep it strictly best-effort: the reaper exists because in-instance enforcement failed, so it must never block or fail to terminate because the graceful tier had trouble.
- Pairs with --pre-stop runs as root, should run as the instance user #63 (run-as-user) — the SSM RunCommand should use the same
su - <user>semantics so it flushes the right$HOME.
Metadata
Metadata
Assignees
Labels
area:lifecycleTTL / idle / on-complete / hibernation / reaperarea:storageFSx / EFS / S3 stagingenhancementNew feature or request
Activity
feat(ttl-reaper): graceful pre-stop flush via SSM before terminate (#187
scttfrdmn commentedon Jun 16, 2026
Done — #190 merged. The reaper now has an opt-in graceful tier (REAPER_GRACEFUL=true): runs a running instance's pre-stop hook via SSM as spawn:local-username, bounded by REAPER_GRACEFUL_MAX_WAIT (default 2m), then terminates regardless. Strictly best-effort — never weakens the hard-deadline backstop. Off by default; enforce-mode rollout + cross-account ssm:SendCommand perms are deploy-side.
chore(release): v0.55.0 (#191)
Stop the reaper running instance-writable tags as root (#832)