Repository navigation
Description
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+— thecompletion.jsonheredoc
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:
- A task whose command fails writes no completion record at all, so the box rides to TTL instead of self-terminating #566 — a command that fails writes no record
- Task path discards failure information: a lost output is reported as completed/exit 0, and a stage-in failure can produce no record at all #561 — a lost output recorded as
completed/exit 0
Here the command neither succeeded nor failed; it was still running.
Suggested shape (one of these, not all)
- A
trapin the generated wrapper onSIGTERM/EXITthat flushescommand.logand writes acompletion.jsonwithstate: "terminated"/retry_class: "ttl_expired". Cheapest, and keeps the record-writing in the one place that already knows$RESULTS_PREFIX. - Periodic log flush (every N seconds, or on each
spawn_phasetransition). More useful for long jobs generally, but more S3 writes. - Agent-side record.
pkg/agent/agent.go:1768terminate(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: nothingContext: 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.
Activity
chore(release): v0.116.0
feat(task): results_prefix — put a task's durable records where you w…