Skip to content

Server-side TTL reaper: out-of-band backstop so a spore can never outlive its deadline (even if spored is dead) #70

Closed

Description

@scttfrdmn

Why

#65 proved the structural weakness: TTL is not independent machinery. TTL expiry is a branch inside checkAndAct(), inside the in-instance monitor loop (pkg/agent/agent.go:299 → a.terminate("TTL expired")). When #65 stopped that loop from running, it killed TTL, idle, cost, on-complete, and pre-stop all at once — and 5 real instances ran 11–15 days past a 10-minute TTL (confirmed State: running, full compute, in spore-host-dev). They were the in-the-wild casualties.

Lifetime is currently enforced from inside the instance, by the very thing whose failure is unobservable from outside. That's the inversion to fix. The project invariant should be: a spore can never outlive its spawn:ttl-deadline, regardless of spored's health. ("…everything dies, eventually.")

What

An out-of-band, server-side reaper (EventBridge-scheduled Lambda, e.g. every 5–15 min) that:

  1. Lists EC2 instances tagged spawn:managed=true across all spawn regions.
  2. Reads spawn:ttl-deadline directly from the EC2 tag (the authoritative, launch-anchored value — pkg/provider/ec2.go:453, survives stop/start).
  3. Terminates anything past deadline — including stopped instances (see sibling issue for #B, the idle-stop-forever class).
  4. Emits a notification on every reap (so a reap is visible, not silent).

Design constraints (from discussion)

  • Backstop, NOT replacement. spored remains the primary enforcer (fast, local, handles idle/cost/pre-stop/graceful pre-stop hook + DNS dereg). The reaper only catches what spored missed. Do not remove or weaken in-instance enforcement.
  • Communicated at launch. spawn launch output should state that a server-side reaper enforces the hard deadline as a backstop — so users understand the deadline is guaranteed even if the box wedges, and that --no-timeout does NOT escape it (decide: should the reaper honor --no-timeout? Leaning no — a hard org-level max age regardless).
  • Pre-stop on reaper-kill: the reaper terminates from outside, so the in-instance pre-stop hook won't run (instance may be wedged/stopped anyway). Acceptable for a backstop; document it. Primary path (spored) still runs pre-stop normally.
  • Idempotent + rate-limited terminate calls; tolerate eventual consistency.
  • Consider a hard maximum age (org policy ceiling, e.g. 7d) that applies even to --no-timeout / extended instances — defense against tag tampering or a deadline pushed absurdly far.

Acceptance

  • A spawn:managed instance past spawn:ttl-deadline is terminated within one reaper interval even with spored stopped/killed/uninstalled.
  • Reaps are notified + logged.
  • Launch output communicates the backstop.
  • Does not interfere with healthy spored-driven termination (no double-terminate races; benign if instance already gone).

Related

Activity

  1. scttfrdmn commented on Jun 6, 2026

    @scttfrdmn
    ContributorAuthor

    Sibling issues now filed: #71 (idle-stopped instances have no daemon → TTL can't fire locally; reaper must terminate stopped instances too) and #72 (guardrail: TTL must always terminate, never add a TTL→stop mode). #70 is the mechanism that backstops both.

  2. scttfrdmn commented on Jun 6, 2026

    @scttfrdmn
    ContributorAuthor

    Folding in #71 — the idle-stop-forever case is the same problem solved by this reaper's mechanism (reading spawn:ttl-deadline from the EC2 tag is state-agnostic), so it's a requirement here, not a separate issue. Promoting to explicit acceptance criteria:

    MUST: the reaper's instance filter includes stopped (and stopping), not just running. A naive instance-state-name=running filter would leave idle-stopped zombies billing EBS forever — that's the #71 case. Terminating past-deadline stopped instances requires no user start.

    OPTIONAL (the one idea unique to #71): a shorter 'stopped max age' policy — reap an instance that's been stopped for > N days even if its TTL deadline is further out (a stopped spore provides zero value). Separate policy knob; decide later.

    Closing #71 as folded here.

  3. scttfrdmn commented on Jun 8, 2026

    @scttfrdmn
    ContributorAuthor

    Implemented in PR #74 (branch feat/70-ttl-reaper), targeting v0.37.0 (tracked in #75). Built as a scheduled multi-account Lambda (lambda/ttl-reaper/): scans every spore-launching account × region for spawn:managed instances (running AND stopped, per the folded-in #71) past spawn:ttl-deadline or a hard REAPER_MAX_AGE ceiling, with dry-run/canary mode and notify-on-reap. Backstop, not a replacement for spored.

  4. 2 remaining items

  5. scttfrdmn commented on Jul 31, 2026

    @scttfrdmn
    ContributorAuthor

    ✅ Pool validated end-to-end on real AWS (spawn v0.96.3)

    The 4th real-AWS smoke passed — the pooled-execution engine works end-to-end for the first time:

    [20s]  4 waiting, 0 in-flight | completion-dirs=0
    [60s]  3 waiting, 1 in-flight | completion-dirs=0
    [80s]  0 waiting, 0 in-flight | completion-dirs=4   ✅ GREEN: queue drained AND 4 completion records written
    

    Workers provisioned as a cohort → installed spored → resolved the run queue → pulled tasks → ran them → wrote durable completion records → the pool drained. Then auto-torn-down and leak-checked clean (0 workers, 0 queues, no orphans, independently re-verified). ~2× t3.micro for a few minutes.

    What it took: 4 releases, one bug per layer

    Each paid smoke surfaced the next layer's bug — all fixed and released:

    1. fix(pool): workers now boot (AMI+IAM), no queue leak on failure, fault detail (#70) #461 — workers launched with no AMI/IAM → MissingParameter (taskcohort Actuator calls RunInstances directly, bypassing the auto-fill spawn task run gets from launcher.Provision).
    2. fix(bootstrap): retry transient spored download/checksum fetches (#462) #463 — spored bootstrap's checksum fetch had no retry → a transient S3 empty-reply aborted the install (not pool-specific — affects all spored instances).
    3. fix(taskpool): retry OpenQueue through queue-creation consistency window (#70) #464 — worker OpenQueue raced queue creation (SQS eventual consistency) → NonExistentQueue at boot.
    4. fix(pool): scoped worker IAM profile with SQS + S3 (#70) #467 — workers had the bare spored role with no SQS permissions → NonExistentQueue (access-denied masked as not-found). The last blocker; fixed with a scoped worker profile (SQS on the run queue + S3), released as v0.96.3.

    Why Substrate didn't catch these (+ filed enhancements)

    Substrate's control-plane tests were green because 3 of the 4 gaps are exactly what it doesn't model: IAM-as-enforced (it has an evaluator but nil-Principal always passes), RunInstances required-param validation, and instance-internal bootstrap. Filed scttfrdmn/substrate#411 (principal-aware test mode), #412 (validate empty ImageId), #413 (seedable GetQueueUrl consistency). The spored-internal bugs (#463) are genuinely out of any emulator's scope — a real-AWS smoke gate is the complement.

    Remaining

    • Open follow-up Pool worker should survive an early spored pool-worker exit (restart-on-exit), not run once at boot #465 — the on-instance worker runs spored pool-worker once at boot; it should be restart-on-exit so a transient failure doesn't strand a billing-but-idle worker (didn't bite this green run, but worth hardening).
    • Documented limitation — per-task input/output buckets beyond the results bucket aren't granted to workers at pool-create; fine for the results/work-bucket case.
    • The N=108 nf-core acceptance run (real bcftools pipeline + genomes) remains the owner's to run via nf-spawn/docs/pool-validation-runbook.md — the engine it exercises is now proven.
  6. scttfrdmn commented on Jul 31, 2026

    @scttfrdmn
    ContributorAuthor

    ✅ Scaled validation green (spawn v0.97.0) — the #70 win, measured

    Ran a larger synthetic pool run to measure concurrency + dispatch at fan-out (12 workers / 24 trivial tasks, dev account, auto-torn-down + leak-checked clean). This exercises the scaling behavior #70 is about; the N=108-with-the-real-bcftools-pipeline remains the owner's to run (needs the real pipeline + genomes) via nf-spawn/docs/pool-validation-runbook.md.

    create: 12 workers requested (min-viable 3) → all 12 up
    dispatch of 24 tasks took 25s                      # ~1s/task (S3 stage + SQS send)
    [20s] 24 waiting,  0 in-flight | live=12 peak=12 completions=0
    [40s] 18 waiting,  6 in-flight | live=12 peak=12 completions=20
    [60s]  0 waiting,  0 in-flight | live=12 peak=12 completions=24
    ✅ GREEN: all 24 tasks completed; peak concurrent workers=12
    

    Before → after (the core #70 fix, now demonstrated)

    Metric Original bug (N=108, one-instance-per-task) Pool (this run)
    Dispatch rate ~3s/task → 5m44s for 108 ~1s/task → 25s for 24
    Peak concurrency ~60/108 (launch-rate capped) 12/12 (full pool, all working)
    Steady state short tasks self-terminate faster than new launches workers reused; no per-task boot

    Dispatch is now O(SendMessage), decoupled from instance launch, and concurrency is bounded by the pool size you ask for — not by how fast RunInstances can fire. The follow-ups from the earlier round both held under load: workers ran the restart-supervised pull loop (#465) and drained cleanly to $0.

    Status

    The pooled-execution engine is validated end-to-end and at scale on real AWS, shipped in v0.97.0 (pool --s3-read/--s3-write + resilient workers included). The remaining item — the full nf-core/bcftools N=108 acceptance run on real data — is the owner's to run via the runbook; the engine it exercises is proven.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions