Skip to content

feat(reaper): report when spored has stopped checking in (#682) - #729

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/682-heartbeat-visibility
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/682-heartbeat-visibility

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Addresses the remaining half of #682 — but not the way we agreed, and the
reason matters more than the code.

The premise changed

The plan was to have spored write a heartbeat into DynamoDB. While implementing
the producer I found there already is one: spored has written the
spawn:last-heartbeat EC2 tag unconditionally on every tick since #497
(pkg/agent/agent.go:434), described in that issue as "an always-on liveness
signal a caller can poll"
. A search of the whole suite for consumers found
zero — the only other hit was an unrelated LastHeartbeat dynamodbav field
in pkg/autoscaler/drain.go.

So #682's gap is a reader, not a writer. A table would have added IAM grants
on every launch role and a per-instance write cost to carry data a free tag
already carries. Neither of us knew that when DynamoDB was chosen.

What a table would have bought is history — "when did it stop", trend across
runs, and a record that survives termination. The tag only answers "is it
ticking now", and dies with the box. Put to the maintainer with that trade-off
stated; the call was no table, the tag is enough, so this closes #682 and the
DynamoDB plan is dropped rather than deferred.

Closes #682.

What this does

A running instance whose agent has died enforces none of its own limits —
TTL, idle-stop and cost are all applied in the instance — so the reaper's
deadline scan becomes the only thing that will ever stop it. That condition was
invisible: "spored is dead" looked exactly like "the job is still running". The
reported case was a 0.5 GiB instance wedged during a package install, still
billing at twice its 6-minute TTL with no completion record and no signal of
any kind, until a human noticed.

  • classifyHeartbeat — fresh / stale / unknown, 10 minutes (ten missed
    refreshes at the throttled 1/min rate).
  • noteHeartbeat — counts all three into the run Summary; a stale one logs
    the SPORED NOT CHECKING IN sentinel with instance, account, region and
    lapse. Only RUNNING spawn:managed instances are considered.
  • template.yaml — metric filter + alarm, three consecutive hourly runs, so
    one lost tag write or a throttled TagResources pages nobody.

Three judgement calls

A missing tag is unknown, not stale. Either spored has not finished its
first tick, or the instance was launched by something that installs no agent at
all — a detached sweep row (#725) is exactly that. A missing signal and a lapsed
one mean different things and only one is a symptom.

An unparseable stamp is also unknown. That is evidence of a format change,
not a dead agent; reporting it as a death would cry wolf every cycle until
someone found the real cause.

It is deliberately NOT a reap trigger. A stale heartbeat is a diagnosis, not
a deadline. spawn:ttl-deadline and the max-age ceiling stay the only
authorities — an agent wedged while its workload runs fine would otherwise have
its work destroyed to tidy a symptom. v0.121.0's memory-floor warning is the
preventive half of #682; this is the part that makes it observable when the
instance gets starved anyway.

The same defect, one level up

TestSentinelSpellingsAreStable pinned the sentinel strings but never checked
the template actually matched them. A sentinel wired to nothing is
indistinguishable from no sentinel — which is precisely the heartbeat tag's
own defect. TestEverySentinelHasAMetricFilter now reads template.yaml and
requires a literal FilterPattern for each of the four, matching the quoted
CloudWatch form so a mention in a comment or an AlarmDescription cannot
satisfy it.

Verification

Four gates, each confirmed to fail when reverted:

revert fails
missing tag → stale TestClassifyHeartbeat (2 cases) + TestNoteHeartbeatCounts
drop the RUNNING guard HeartbeatStale = 2, want 1 — a stopped box would read as a dead agent
drop the clock-skew guard age = -5m0s, want >= 0
rename the FilterPattern TestEverySentinelHasAMetricFilter

The skew guard initially passed on revert — the returned state was unaffected,
so only the negative duration was observable. The test now asserts the age, so
the guard is actually covered rather than nominally.

cfn-lint caught the AlarmDescription exceeding CloudFormation's 1024-char
limit; sam validate alone did not.

Gates: gofmt, go vet, go test ./... (reaper + root), go test -short ./...,
make check-docs, cfn-lint template.yaml, semgrep scan --config=auto --error
(0 findings — re-run after staging, since semgrep only scans git-tracked files).

No deploy yet. The alarm needs a reaper redeploy to exist, which is the same
redeploy #685 needs.

Opened against #727's branch and auto-closed when that merged and the branch was
deleted; this is the same commit, rebased onto main. Supersedes #728.

A running instance whose agent has died enforces none of its own limits —
TTL, idle-stop and cost all live IN the instance — so the reaper's deadline
scan becomes the only thing that will ever stop it. That condition was
invisible: "spored is dead" looked exactly like "the job is still running".

No new producer and no new storage: spored has written spawn:last-heartbeat
every tick since #497, described there as "an always-on liveness signal a
caller can poll", and a search of the tree found ZERO consumers. The gap was
a reader, so this adds one.

- classifyHeartbeat: fresh / stale / unknown. A missing tag is UNKNOWN, not
  stale — pre-first-tick, or an instance with no agent at all such as a
  detached sweep row (#725). An unparseable stamp is also unknown: that is
  evidence of a format change, and calling it a death would cry wolf every
  cycle until someone found the real cause.
- noteHeartbeat: counts all three states into the run Summary; a stale one
  logs the SPORED NOT CHECKING IN sentinel with instance, account, region
  and lapse. Only RUNNING spawn-managed instances are considered.
- template.yaml: metric filter + alarm, 3 consecutive hourly runs so one
  lost tag write pages nobody.

Deliberately NOT a reap trigger. A stale heartbeat is a diagnosis, not a
deadline; spawn:ttl-deadline and the max-age ceiling stay the only
authorities. Terminating on a missed tick would destroy the work of a box
whose agent is merely wedged.

Also makes the sentinel/template contract real: a test now requires every
sentinel to have a matching FilterPattern. A sentinel wired to nothing is
indistinguishable from no sentinel — the same defect as the tag itself.

Gates confirmed to fail on revert: missing-tag-as-stale, the running-state
guard, the clock-skew age guard, and the metric-filter contract. cfn-lint
caught the AlarmDescription exceeding CloudFormation's 1024-char limit.
@scttfrdmn
scttfrdmn merged commit ffe0337 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/682-heartbeat-visibility branch October 8, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A box too small to run spored cannot enforce its own TTL: 0.5 GiB instance outlived a 6m TTL by 2x, silently

1 participant