Skip to content

Anchor status/cost/list age, TTL and cost to the first launch (#1029) - #1213

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1029-launch-anchor
Oct 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1029-launch-anchor

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1029

What changed

EC2's LaunchTime is the most recent START, so it resets on every start of a stopped instance. These display paths measured from it and, after a stop/start, disagreed with what spored and the TTL reaper enforce:

Path Was Now
lifecycleDeadline fallback (no spawn:ttl-deadline) — spawn status, spawn list TTL column, spawn start notice EC2 LaunchTime + spawn:ttl first launch + spawn:ttl
spawn status "Max compute cost" rate × (deadline − EC2 LaunchTime) rate × (compute so far + now→deadline) — the worst case spawn extend already sizes --cost-limit with (decideCostLimit)
spawn cost <instance> rate × time since EC2 LaunchTime rate × compute time across every boot, + EBS since first launch
spawn list Age, sort order since EC2 LaunchTime since first launch
spawn task diagnose Age / Est. cost since EC2 LaunchTime since first launch / rate × compute time

One rule, shared with enforcement. New ttl.LaunchAnchor(tag, ec2Launch) in pkg/ttl: the EARLIER of spawn:launch-time and EC2 LaunchTime. That is exactly the reaper's rule after GHSA-c93q-4jh7-6pvj; lambda/ttl-reaper's launchTime now delegates to it (behaviour unchanged, so no redeploy is needed) and so does cmd's originalLaunchTime (used by extend and the stopped-instance status since #992/#947). The only change to originalLaunchTime itself: a spawn:launch-time LATER than EC2's LaunchTime (forged, or a few seconds of clock skew at launch) no longer wins, so the CLI can't show an instance as younger than the reaper treats it.

What "cost so far" means across stop/start (the choice). EC2 bills compute only while running, and EBS on the wall clock including stopped time. So:

  • compute = spawn:price-per-hour × spored's cumulative spawn:compute-seconds. That is the same total --cost-limit is enforced against (pkg/agent.accumulatedComputeCost). There are no other spawn:cost-* tags besides spawn:cost-limit, so this tag is the source. Shown as-is (no computeTagLag padding; the report says it can be up to 5 min behind while running).
  • With no usable tag (no spored, or an older one), compute = wall clock since first launch, printed as "at most …" with the reason. That is the most it can have run. The time since EC2 LaunchTime would be a lower bound for the current boot only, and has no meaning for a stopped instance.
  • EBS = spawn:ebs-hourly-cost × time since first launch, shown when the tag is present (matching the stopped-instance spawn status from Status for stopped instances from EC2; compute kept across stop/start; stop's TTL message (#928) #947).
  • The status "Max compute cost" ceiling uses computeSoFar (tag + 5 min lag, capped at wall clock) plus the remaining time, the same as spawn extend. That makes it a ceiling, not an estimate.

spawn list Age is now the time since first launch. That is the age the reaper's max-age ceiling acts on, as the issue suggests. -o json keeps launch_time (EC2's, the latest start) and adds first_launch_time. Both are recorded in the CHANGELOG (Changed / Added).

Coordination with #947 (merged): it kept the Max compute cost line as is and deferred it to this issue. The stopped-instance status it added already used originalLaunchTime/taggedComputeSeconds, and this PR reuses them.

Gates

  • TestRestartedInstanceIsShownFromItsFirstLaunch: LaunchTime = 1h ago, spawn:launch-time = 3d ago, spawn:ttl=96h, 5h of spawn:compute-seconds. It asserts the deadline is tag + 96h, spawn list's rendered Age column is 3d and its TTL ~23h, spawn cost shows 3d since launch / 5h compute / $5.00 (and "at most" figures without the compute tag), and status max cost is ~$29.08.
  • TestNoDisplayDurationFromRawLaunchTime: an AST discovery over every non-test cmd/*.go. Each .LaunchTime selector must be in originalLaunchTime, or else used only for ordering (.After/.Before/.Equal), raw export (.Format) or a struct copy. It fails if discovery finds nothing.
  • TestOriginalLaunchTimeIsTheEarlierOfTagAndEC2, pkg/ttl TestLaunchAnchor.

Each gate was watched failing against a revert that compiles:

  • (a) list Age back to time.Since(inst.LaunchTime): Age = "1h" + discovery flags list.go:274.
  • (b) deadline fallback back to instance.LaunchTime.Add(d): deadline/TTL "3d22h"/max cost subtests + discovery flag status.go.
  • (c) diagnose age := time.Since(inst.LaunchTime): discovery flags task.go:84.
  • (d) max cost back to deadline.Sub(instance.LaunchTime): max-cost subtest + discovery.
  • (e) cost ignoring the compute tag: cost subtest.
  • (f) originalLaunchTime tag-first: the earlier-of test.

Checks

  • make check: fmt/vet (all GOOS)/staticcheck/hermetic short tests/tidy all pass. check-build-tags fails, and it fails identically on unmodified main on this machine (/private/tmp worktree paths).
  • make gen-docs (cost.md regenerated) and then make check-docs clean. semgrep: 0 findings. lambda/ttl-reaper tests pass.
  • Not verified live: no AWS calls were made.

@scttfrdmn scttfrdmn added this to the v0.137.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.78571% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/cost.go 85.71% 3 Missing and 1 partial ⚠️
cmd/task.go 0.00% 4 Missing ⚠️
cmd/list.go 57.14% 2 Missing and 1 partial ⚠️
cmd/status.go 75.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

EC2's LaunchTime is the latest start. spawn status's TTL fallback and max
compute cost, spawn list's Age, spawn cost and spawn task diagnose all
measured from it, so after a stop/start they disagreed with what spored and
the TTL reaper enforce.

ttl.LaunchAnchor is now the one rule (the earlier of spawn:launch-time and
EC2 LaunchTime, GHSA-c93q); the reaper's launchTime and cmd's
originalLaunchTime both call it. Compute figures come from spored's
spawn:compute-seconds. A discovery test keeps every other cmd/ reader of
.LaunchTime off arithmetic.
@scttfrdmn
scttfrdmn force-pushed the fix/1029-launch-anchor branch from bcc7c12 to 93ebdc6 Compare October 20, 2026 05:33
@scttfrdmn
scttfrdmn merged commit 9007387 into main Oct 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1029-launch-anchor branch October 20, 2026 05:52
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.

status/cost/list still anchor TTL and cost figures to EC2 LaunchTime, which resets on every start

1 participant