Skip to content

extend: spawn:ttl tag is overwritten with the extend argument, not the cumulative total — every other reader still treats it as the launch-anchored duration #506

Closed

Description

@scttfrdmn

Summary

`spawn extend ` writes TWO tags for what should be one fact:

  • `spawn:ttl-deadline` (absolute RFC3339 timestamp) — correctly advanced by `` from the existing deadline. This is authoritative: it's what `spored`'s `Agent.checkAndAct` and the out-of-band reaper both read.
  • `spawn:ttl` (a duration string) — overwritten with the literal `` argument itself, not the new cumulative total TTL from launch.

These two are supposed to describe the same fact (how long this instance is allowed to live) and after even one `extend` call they diverge, because `spawn:ttl`'s value now means "the last amount I extended by," not "the instance's total TTL duration" — which is what it means everywhere else it's read.

Confirmed live in a field report (2026-08-18): an instance launched with `--ttl 8h`, then `spawn extend 8h` run twice. `spawn:ttl-deadline` correctly advanced launch+8h → launch+16h → launch+24h across the two calls. `spawn:ttl` stayed `"8h"` the whole time (each call rewrote it to the same literal argument) — which by coincidence looked unchanged and read as "extend did nothing," when in fact the deadline had genuinely moved. Reported as: "extend rewrites spawn:ttl-deadline and leaves spawn:ttl at the original 8h... two tags for one fact, only one of them moving."

Why this is a real bug, not just a confusing coincidence

`cmd/extend.go` itself treats `instance.TTL` (the `spawn:ttl` tag) as the authoritative total when there's no deadline tag yet:

if newDeadline.IsZero() {
    // Older instance without deadline tag — best-effort from current TTL
    if cur, err := time.ParseDuration(instance.TTL); err == nil {
        newDeadline = time.Now().Add(cur).Add(extendDuration)
    }
    ...

And `cmd/state.go`'s stop/hibernate path computes the TTL remaining to preserve across a stop/start cycle from `instance.TTL` + `LaunchTime`, not from `spawn:ttl-deadline`:

if instance.TTL != "" {
    ttlDuration, err := parseDuration(instance.TTL)
    if err == nil {
        uptime := time.Since(instance.LaunchTime)
        remaining := ttlDuration - uptime
        ...

So: launch with `--ttl 8h`, run `spawn extend 8h` (deadline correctly moves to launch+16h, but `spawn:ttl` is rewritten to `"8h"`), then `spawn stop` before the original 8h mark — this computes `remaining = 8h - uptime`, silently ignoring the extension, and on `spawn start` restores a TTL duration that has nothing to do with the actual extended deadline the instance was on before it stopped.

`cmd/status.go`'s `lifecycleDeadline` correctly prefers `spawn:ttl-deadline` when present, so `spawn status`'s "Termination deadline" line is NOT affected by this — only `instance.TTL`'s other readers are.

Suggested fix

Pick one:

  1. Stop writing `spawn:ttl` at all in `cmd/extend.go` once `spawn:ttl-deadline` exists — it's redundant with (and now actively conflicting with) the deadline tag, and every reader that matters (`spored`, the reaper, `status`) already prefers the deadline. Keep `spawn:ttl` only as the pre-deadline legacy fallback it originated as.
  2. Or, if `spawn:ttl` must keep meaning "total duration from launch" for its other readers (stop/start's remaining-TTL preservation, in particular), compute it as `newDeadline - instance.LaunchTime` rather than echoing the raw `` argument.
  3. Either way, fix `cmd/state.go`'s `stopOrHibernate`/remaining-TTL calculation to derive from `spawn:ttl-deadline` (when present) instead of `instance.TTL` + `LaunchTime` — this is the one with a real behavioral consequence (a stop/start cycle after any `extend` call restores the wrong TTL).

Environment

Field report, 2026-08-18: spored v0.100.0, 7 instances, `spawn extend 8h` run twice per instance, verified via `aws ec2 describe-tags` reads of `spawn:ttl` / `spawn:ttl-deadline` / `spawn:stop-at` / `spawn:ttl-extended-at`. Independently reproduced live (same session) with a disposable `t3.micro`: launched `--ttl 20m`, `spawn extend 15m` correctly advanced `spawn:ttl-deadline` by 15m while `spawn:ttl` became `"15m"` (not `"35m"`).

Activity

  1. scttfrdmn commented on Aug 18, 2026

    @scttfrdmn
    ContributorAuthor

    Field corroboration for the reproduction, from the report you're working off — all seven instances, with the CloudTrail record, in case the exact rewrite pattern is useful for a regression test.

    Seven c8g.48xlarge, us-east-1, account 942542972736, launched with --ttl 8h, then spawn extend <id> 8h twice per instance. Every CreateTags call writes both keys together, spawn:ttl always the literal argument:

    # RunInstances tagSpecificationSet
    2026-08-17T22:25:59Z  i-03a29c216d46c3b86  {'spawn:ttl': '8h', 'spawn:ttl-deadline': '2026-08-18T06:25:57Z'}
    # extend round 1
    2026-08-18T05:04:40Z  i-03a29c216d46c3b86  {'spawn:ttl': '8h', 'spawn:ttl-deadline': '2026-08-18T14:25:57Z'}
    # extend round 2
    2026-08-18T05:59:21Z  i-03a29c216d46c3b86  {'spawn:ttl': '8h', 'spawn:ttl-deadline': '2026-08-18T22:25:57Z'}
    

    All seven, after both extends — spawn:ttl = 8h uniformly, spawn:ttl-deadline = LaunchTime + 24h:

    Instance LaunchTime deadline at launch after #1 after #2
    i-03a29c216d46c3b86 22:25:58Z 06:25:57Z 14:25:57Z 22:25:57Z
    i-08efa17ed1bb2f099 22:30:36Z 06:30:35Z 14:30:35Z 22:30:35Z
    i-08b9ad516db6dd2fe 22:35:14Z 06:35:13Z 14:35:13Z 22:35:13Z
    i-03c73299d8b91b416 22:39:53Z 06:39:51Z 14:39:51Z 22:39:51Z
    i-0d79af36b80961170 22:44:31Z 06:44:29Z 14:44:29Z 22:44:29Z
    i-05c34d471ee84e2db 22:49:09Z 06:49:08Z 14:49:08Z 22:49:08Z
    i-03ebed621d8799f31 22:53:46Z 06:53:45Z 14:53:45Z 22:53:45Z

    Two things to add from the operator side:

    1. The failure isn't just confusing — it drove a wrong corrective action. Verifying the extension by effect, I read spawn:ttl (plus spawn:stop-at and spawn:ttl-extended-at, neither of which exists), found 8h unchanged, and derived LaunchTime + spawn:ttl = 06:25–06:53Z. That's the obvious derivation for any external monitor, and it was 16 hours pessimistic. I concluded extend was a no-op and was about to take emergency action to save four in-flight multi-hour DFT runs that were in no danger. Whichever way #506 lands, a spawn:ttl-extended-at breadcrumb would make an extension visible to someone auditing tags rather than reading the CLI's stdout.

    2. A datum for #502's severity, and a check worth adding to the reaper's own tests: with the broken role, nothing enforced either tag. A separate instance in the same account, i-05782b84f7db5c515 (biosurf-gpaw2670-build, launched 00:59:31Z with --ttl 4h, never extended, so both tags agree):

    spawn:ttl           4h
    spawn:ttl-deadline  2026-08-18T04:59:29Z
    state               running          <- observed 2026-08-18T06:24:45Z
    

    1h25m past an unambiguous, uncontested deadline and still running. In-instance enforcement was dead per #502, and the out-of-band reaper did not pick it up either (not deployed for this account, or it failed silently — spawn status hedges this as "if deployed for your account", so from the user side it's unfalsifiable). On the seven-instance fleet the same is true: they sailed past their original 06:25–06:53Z deadlines with no event. So for a #502-affected instance, both layers of "lifecycle protection" were absent simultaneously, and no surface reported that. If the reaper has an alarm for not firing on an overdue instance (#475 covers the reaper not running at all), an overdue-but-alive instance looks like a good second signal.

    On checking spawn:ttl-deadline as the authoritative tag — agreed, and that's now what I do. Worth noting it's the tag that made #506 findable at all: it's the only place the two extends left a trace.

  2. added a commit that references this issue on Aug 18, 2026
    b3efa9d
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