Skip to content

Parse every TTL and lifecycle duration with one day-aware parser; never tag spawn:ttl without a deadline (#990) - #1027

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/990
Oct 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/990

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #990. Stacked on #993. Merge #993 first; this PR's base is fix/983.

The bug

spawn launch --ttl 1d tagged spawn:ttl=1d and no spawn:ttl-deadline. buildTags wrote the deadline only when time.ParseDuration accepted the value, and that parser has no day unit. spored read spawn:ttl the same way, so the launch went ahead with nothing enforcing the TTL. Only the reaper's 7-day max-age ceiling bounded the instance.

Decision: accept day units

Users type them, and --fsx-ttl, extend's old regex and pkg/config already accepted them. So every input and every reader now uses one parser.

  • pkg/ttl.ParseDuration: Go durations plus d (1d, 2d12h, 1.5d, 12h1d). It rejects signs, spaces, unknown units, empty input and overflow.
  • ParseTTL: the same, but the value must be positive. A zero TTL puts the deadline at the launch instant, and a zero idle timeout means no idle timeout.
  • TagValue: stores a day-unit value in Go form (1d becomes 24h0m0s). A reader still on time.ParseDuration (an older spored, lambda/dashboard-api, another repo) then gets the same duration.

Inputs (each rejected before any AWS call):

  • spawn launch: --ttl, --idle-timeout, --pre-stop-timeout, --completion-delay, --webhook-timeout, --fsx-ttl. runLaunch checks them first, before its STS identity call and before the sweep/batch/wizard branches. The assembled config is checked again, which also covers ~/.spawn defaults and the wizard, which now re-prompts.
  • spawn extend (single instance and job array)
  • spored config set ttl/idle-timeout/completion-delay, validated before the provider/IMDS call
  • spawn defaults set idle-timeout
  • sweep ttl/idle_timeout, in the CLI and in the detached-sweep Lambda. ttl: 3600 (a YAML int) is now an error instead of being silently dropped.
  • spawn task lifecycle.ttl
  • spawn app/service/pool --ttl
  • batch-queue job and global timeouts (global becomes the TTL), on the CLI side and in the on-instance runner
  • pipeline stage timeout, in validation and in the orchestrator
  • Client.Launch and launcher.Provision call the new public LaunchConfig.ValidateDurations first. That is an addition to the API snapshot.

Readers:

  • spored's tag reader (pkg/provider, now configFromTags so it is testable): ttl, idle, pre-stop, webhook and completion-delay tags
  • the TTL reaper: REAPER_MAX_AGE, REAPER_GRACEFUL_MAX_WAIT, pre-stop-timeout
  • spawn status, the launch, task and service cost estimates, the wizard estimate

Reaper agreement: when an instance has no usable spawn:ttl-deadline but does have a positive spawn:ttl, the reaper now uses launch-time + spawn:ttl as the deadline. That is the deadline spored already synthesizes in that case (agent.NewAgent). Instances launched with --ttl 1d before this fix are therefore reaped on time, including stopped ones, which run no spored. spawn:ttl=0 (config set ttl 0) stays exempt, and a valid deadline tag still wins.

Refusal and the strengthened gate

Test evidence (each new test watched failing against a revert that compiles)

  • Restored the old conditional deadline write in buildTags: the AST gate fails on pkg/aws/tags.go buildTags. EveryAcceptedTTLFormYieldsADeadline fails for 3d, 1.5d, 2d12h, 1d30m, 12h1d and 1d2h30m15s. RefusesATTLItCannotEnforce fails.
  • Disabled the validation in Launch: TestLaunchRejectsAnUnparseableTTLBeforeAnyAWSCall fails because the call reaches STS.
  • Disabled the reaper fallback, then reverted it to time.ParseDuration: the reaper tests fail both times, and TestParseMaxAgeAcceptsDays fails on the second revert.
  • Reverted the provider, the sweep-orchestrator, extend, sweep and launch-config validation, configSetTag, the wizard, defaults set, taskproto and queue changes one at a time: each one's test fails.
  • make check: green apart from the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker. make check-nested: all 9 nested modules clean, ttl-reaper and sweep-orchestrator included. check-tidy is clean, golangci-lint --new-from-rev=HEAD reports 0 issues, and semgrep --config=auto on the changed files reports 0 findings. docs-gen and api/public-surface.txt are regenerated.

Caveats

  • lambda/dashboard-api (a separate module with no spawn dependency) still reads spawn:ttl with time.ParseDuration. That is display only, and new tags are written in Go form.
  • Pacing knobs (--launch-delay, --wait-timeout, plugin health interval, queue retry delays, pool --idle-timeout, which is a DurationVar) keep Go syntax. They are not lifecycle bounds.
  • A zero --ttl/--idle-timeout at launch is now an error. Use --no-timeout.
  • Mixed versions: a new CLI writing a batch-queue job timeout in day units, read by an old spored queue runner, would fail that job. TTL and idle tags are normalized, so they are unaffected.

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

…er tag spawn:ttl without a deadline (#990)

`spawn launch --ttl 1d` tagged spawn:ttl=1d with no spawn:ttl-deadline:
buildTags wrote the deadline only when time.ParseDuration (no day unit)
accepted the value, and spored parsed the tag the same way, so only the
reaper's 7-day max-age ceiling bounded the instance.

- pkg/ttl.ParseDuration is the one parser: Go durations plus days ("1d",
  "2d12h", "1.5d"), no signs, overflow checked. ParseTTL requires a
  positive value; TagValue stores day forms in Go form so older readers
  agree. pkg/config.ParseDurationE delegates to it.
- buildTags returns an error instead of writing spawn:ttl without a
  deadline, and refuses unparseable idle/pre-stop/completion/webhook
  durations. LaunchConfig.ValidateDurations (new, public) runs first in
  Client.Launch and launcher.Provision, and before any AWS call in
  launch (flags and assembled config, wizard included), app, service,
  pool, extend, spored config set, defaults set, sweeps (CLI and the
  detached-sweep Lambda), task specs, batch queues and pipelines.
- Readers use the same parser: spored's tag reader (pkg/provider), the
  TTL reaper (REAPER_MAX_AGE, pre-stop-timeout), status and estimates.
- The reaper now enforces launch-time + spawn:ttl when there is no usable
  deadline tag, the deadline spored already synthesizes, so instances
  launched with a day-unit TTL before this fix are reaped on time even
  when stopped. spawn:ttl=0 (disabled) stays exempt.
- The #983 writer gate now requires the deadline write on the same path
  (same block or an enclosing one) as each spawn:ttl write, and a pkg/aws
  test asserts every accepted TTL spelling (enumerated from ttl.Units())
  yields a deadline. Both fail against the old conditional write.

(#990)
@scttfrdmn
scttfrdmn merged commit 9266de8 into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/990 branch October 17, 2026 06:27
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.

spawn launch --ttl 1d writes spawn:ttl=1d with no spawn:ttl-deadline, so neither spored nor the reaper enforces the TTL

1 participant