Repository navigation
Description
Summary
When the ttl-reaper terminates a stray/expired instance, it does not delete that instance's Route53 DNS record, so every reaper-terminated (or otherwise non-gracefully-stopped) instance leaks an A record into spore.host. DNS cleanup only happens in spored's graceful shutdown (Cleanup → DeleteDNS); the reaper is precisely the path that fires when graceful shutdown didn't run, so the record is guaranteed orphaned.
Evidence
The live spore.host zone currently holds 61 instance A-records (76 total − 15 infra records), almost all e2e-*/test throwaways from past runs, while the dev account has zero running spawn-managed instances. They're orphans — terminated instances whose records were never cleaned up.
Root cause
lambda/ttl-reaper/main.go:
evaluate()(line ~437) reads thespawn:dns-nametag only to label the candidate for logging —name = tags[tagprefix.Tag("dns-name")].- the reap action calls
ec2:TerminateInstancesand never touches Route53. template.yamlIAM grantsec2:TerminateInstances(+ FSx) but noroute53:*— so even if the code tried, it couldn't.
spored's DeleteDNS runs in pkg/agent Cleanup() on SIGTERM, but a reaped instance is terminated out from under the daemon, so that path doesn't run.
Fix
When the reaper terminates an instance that carries a spawn:dns-name tag, also delete its Route53 records (the base36 A record and, if spawn:account-name is present, the alias CNAME) — mirroring what spored's graceful DeleteDNS/DeleteJobArrayDNS does. Requires:
- reaper logic: after a successful (non-dry-run) terminate, issue the Route53 delete for the instance's FQDN(s). Best-effort + logged; a missing record is not an error.
- IAM (
template.yaml): addroute53:ChangeResourceRecordSets+route53:ListResourceRecordSetsscoped to the hosted zone(s). The reaper runs in the infra account where the zone lives, so this is same-account (no cross-account hop needed for the Route53 call). - honor
REAPER_DRY_RUN(log "WOULD delete DNS …").
Consider sharing the FQDN-construction + delete logic with the dns updater / pkg/dns so the base36 encoding stays consistent.
Cleanup of existing orphans
Separately, the ~61 existing stale records should be swept once (a one-off, or a reaper "orphan DNS" pass that deletes records whose IP no longer maps to a running managed instance). Filing that as part of this or a follow-up is fine.
Refs
Lifecycle invariant ("everything dies eventually" — and shouldn't leak). Related: the reaper FSx-cleanup path (#192/#212) is the precedent for the reaper owning downstream-resource cleanup, not just the instance.
Activity
scttfrdmn commentedon Jun 25, 2026
Design refinement: the reaper must do teardown MANUALLY, not delegate to spored
Key principle (clarifying the fix direction): the reaper is a backstop that only runs when spored failed — dead, wedged, IMDS-blocked, crashed, or never started (the #65 class). So the fix is NOT "have the reaper trigger spored's graceful
Cleanup→DeleteDNS": that asks the already-broken daemon to do the cleanup. By the time the reaper fires, we must assume spored is gone and perform every downstream cleanup out-of-band, from the reaper itself.This is the same ownership model the reaper already uses for FSx (#192/#212): it deletes the filesystem directly rather than relying on spored. DNS should follow suit.
So the reaper's terminate path becomes a full manual teardown:
REAPER_GRACEFUL=true) best-effort pre-stop flush via SSM — but ONLY because the box might still be reachable; treat success as a bonus, never a precondition.A+ aliasCNAME— via a Route53 call from the infra account. Do NOT route this through spored.All best-effort +
REAPER_DRY_RUN-aware + logged; a missing record / unreachable box never blocks the terminate.Why not "wake spored to self-clean"
Considered and rejected: it inverts the backstop contract. If spored were healthy enough to gracefully clean up, the deadline would already have been enforced and the reaper would never have selected this instance. Relying on the dead daemon is the bug, not the fix.
Net: the reaper construct already deletes the IP→record after-the-fact; the FQDN is derivable from
spawn:dns-name(+spawn:account-namefor the alias) + the account id (base36), so no spored round-trip is needed.plugin: run local deprovision on remove + terminate (stop orphaning)
plugin: make registry plugins work end-to-end (verified live) (#347)
feat(ttl-reaper): DNS reconciliation sweep for orphaned records (#438) (