Skip to content

A task killed by its own TTL leaves no completion record and no command.log, so there is nothing to re-size from #632

Closed

Description

@scttfrdmn

What happened

A spawn task run task was killed by its own TTL while the command was still running. It left nothing: no completion.json, no command.log, no task prefix in the results bucket at all.

$ aws s3 ls s3://spawn-results-<acct>-us-west-2/tasks/ | grep muscle
(no output)
$ aws s3 ls s3://spawn-results-<acct>-us-west-2/tasks/cookbook-muscle-gpcr-20261001214539/
(no output)

The instance was gone (past the ~1h window where describe-instances still lists terminated instances), so there was no way to tell how far the command got — which phase, how long stage-in took, whether the tool had even started. The only recoverable fact was "the TTL fired."

Why it leaves nothing

In pkg/taskproto/wrapper.go, the log upload and the completion record are both after the command, in sequence:

  • pkg/taskproto/wrapper.go:253-256 — "Best-effort copy of the command log": aws s3 cp /var/log/spawn-command.log "$RESULTS_PREFIX/command.log"
  • pkg/taskproto/wrapper.go:259+ — the completion.json heredoc

There is no trap on the wrapper and no periodic flush, so /var/log/spawn-command.log only ever reaches S3 if the command returns. When the TTL sentinel terminates the instance mid-command, the log dies with the disk.

That is a shame, because the log is genuinely useful by then: spawn_phase() (wrapper.go:122) has already written timestamped stage-in start / stage-in done / image pull done; command start markers, which is exactly what you need to size the retry.

Why this is worth fixing rather than "working as intended"

This is the one failure mode where diagnostics matter most, and it is structurally the most likely one to recur: TTL is documented as the cost cap, not a safety margin, so sizing it tight is the recommended practice — and a tight TTL on a tool whose runtime you are still learning is precisely how you end up here. I under-sized a 45-minute budget for a tool that needed more; the cost was the TTL ceiling plus having no measurement to re-size from, so the next attempt is another guess.

It is also distinct from the two already-fixed neighbours, both of which assumed the command returns:

Here the command neither succeeded nor failed; it was still running.

Suggested shape (one of these, not all)

  1. A trap in the generated wrapper on SIGTERM/EXIT that flushes command.log and writes a completion.json with state: "terminated" / retry_class: "ttl_expired". Cheapest, and keeps the record-writing in the one place that already knows $RESULTS_PREFIX.
  2. Periodic log flush (every N seconds, or on each spawn_phase transition). More useful for long jobs generally, but more S3 writes.
  3. Agent-side record. pkg/agent/agent.go:1768 terminate(ctx, reason) already has the reason string and writes lifecycle tags; it could write the minimal completion record. This catches a hard kill the in-instance trap would miss, but the agent does not know $RESULTS_PREFIX.

(1) alone would have turned my dead end into "stage-in took 31s, command ran 44m and was still going" — enough to re-size without a second blind attempt.

Repro

# any task whose command outlives its TTL
cat > slow.task.json <<'JSON'
{ "task_id": "ttl-no-record-demo",
  "command": ["bash","-c","set -e; echo working; sleep 3600; echo never"],
  "resources": {"cpu":2,"memory_gib":4,"architecture":"arm64","families":["c8g"]},
  "lifecycle": {"ttl":"5m","on_complete":"terminate","cost_limit":0.05} }
JSON
spawn task run --spec slow.task.json
# after ~5 min:
aws s3 ls s3://spawn-results-<acct>-<region>/tasks/ttl-no-record-demo/
# expect: nothing

Context: spawn 0.112.0. Found while sizing a recipe for muscle5, where -align on 906 sequences did not finish inside 90 minutes (mafft aligns the same input in 3 s) — the TTL death was my sizing error, but the absence of any artifact is what made it expensive.

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