Skip to content

ttl-reaper terminates without running --pre-stop (out-of-band path bypasses the flush) #187

Closed

Description

@scttfrdmn

Follow-up to #184. Confirmed gap, lower urgency than #63 but real.

Problem

There are two TTL-terminate paths with different --pre-stop guarantees:

  1. spored (in-instance): TTL expiry → Agent.terminate() → runPreStop() runs to completion before provider.Terminate() (pkg/agent/agent.go). pre-stop is honored. ✅
  2. 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.go terminate() calls TerminateInstances directly — no pre-stop, no SSM RunCommand, no grace. git log -S SendCommand/PreStop on 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-stop tag and is SSM-reachable, fire the hook via SSM RunCommand (as the spawn:local-username user, per --pre-stop runs as root, should run as the instance user #63), with a bounded wait (the tag's pre-stop-timeout, capped — the reaper is still a backstop, not a babysitter).
  • Then TerminateInstances regardless 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.

Relates to #184, #63, #70/#71/#72.

Activity

  1. added
    enhancement
    area:lifecycle
    area:storage
    on Jun 16, 2026
  2. scttfrdmn commented on Jun 16, 2026

    @scttfrdmn
    ContributorAuthor

    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.

  3. added a commit that references this issue on Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:lifecyclearea:storageenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions