Repository navigation
Description
Reported from the 2026-10-07 demo: spawn status chem-arm, run immediately after
that instance's job failed and it self-terminated, answered
no instance found with name: chem-arm
Accurate as worded, and unhelpful — the presenter was asking why it vanished.
Confirmed, and it has a second consequence that is worse than the message.
The mechanism
resolveInstance (cmd/utils.go:162) lists with an empty state filter:
instances, err := client.ListInstances(ctx, "", "")and the empty filter means running and stopped only
(pkg/aws/client.go:1177-1182):
case "":
// Default: show running and stopped instances (not terminated)
filters = append(filters, types.Filter{
Name: aws.String("instance-state-name"),
Values: []string{"pending", "running", "stopping", "stopped"},
})terminated and shutting-down are both excluded. EC2 keeps terminated
instances visible in DescribeInstances for roughly an hour, so the instance,
its state transition reason and its termination time were all available — the
lookup simply declined to ask for them.
The second consequence: unreachable code in terminate
cmd/terminate.go:100 has:
if instance.State == "shutting-down" {
fmt.Fprintf(os.Stderr, "Instance %s is already shutting down — nothing to do.\n", ...)
return nil
}terminate resolves via resolveInstance (cmd/terminate.go:87), whose filter
excludes shutting-down. That branch can never execute. What actually happens
when you terminate an instance that is already terminating is the not-found path —
which, per #648, terminate deliberately treats as success and exit 0. So
re-terminating a shutting-down instance prints "no instance found" and reports
success, and the dead branch is what makes that look intentional in the source.
Suggested fix
- On a name miss, look again with
"all"before reporting not-found, and use
what comes back:shutting-down→ "chem-arm (i-…) is shutting down" and letterminate's
existing branch finally work.terminated→ "chem-arm (i-…) terminated at 01:54" plus
StateTransitionReason, which EC2 populates ("User initiated", "Client.
InstanceInitiatedShutdown", a spot reclaim, …). That is the answer the
presenter wanted.- still nothing → the current message, now meaning "no such instance,
recently or otherwise".
- Keep retryIAM doesn't retry ConcurrentModification, so concurrent
task runlaunches fail on CreateInstanceProfile #648's exit-code contract unchanged: a name that resolves to a terminated
instance is still success forterminate. This is about what is said, not
what is returned.
Related, and the harder half
Also reported, and I agree it is the more valuable gap: once the instance is gone,
its console output and /var/log/spawn-command.log are gone with it, so there is
no way to find out why an --on-complete terminate job failed. The exit code
survives in tags; the diagnosis does not.
pkg/taskproto/flush.go already does the right thing for the task path — it
uploads /var/log/spawn-command.log and a completion.json to the results
prefix in S3 (flush.go:125, :156). The gap is that a plain
spawn launch --command … --on-complete terminate has no results bucket and so
no flush. Options, roughly in order of cost:
- Reuse the task flush for the launch path when a results bucket exists, and
auto-create/derive one when--on-complete terminateis set — the destructive
combination is exactly where the log is needed. - Failing that, tail the last N lines of
spawn-command.logto the serial
console on non-zero exit.GetConsoleOutputsurvives termination for a while,
so this costs nothing and needs no bucket.
Both are bigger than the lookup fix above and probably want their own issue once
the direction is chosen; recording them here so the connection to "why did it
vanish" is not lost.
Environment: spawn v0.123.0, spored v0.124.0.
Activity
test(sweep): count live instances, not reservations, in the leak-check
test(sweep): add the detached-sweep hardware test, and list the Lambd…
scttfrdmn commentedon Oct 8, 2026
Direction, with the console-retention caveat now measured instead of assumed
I recommended tailing the command log to the serial console (option B) but flagged
that there is no
GetConsoleOutputcall anywhere in this codebase, so theretention window was from AWS docs rather than measured here. I measured it
against instances terminated earlier today.
What survives
So console output outlives the instance's visibility in
DescribeInstances— a stronger result than I expected, and it covers the exactwindow where "why did it vanish?" gets asked.
The part that changes the recommendation
The command log is not on the console.
--commandruns undersuwith itsoutput teed to
/var/log/spawn-command.log, which never touches the consoledevice. So option B is not "read what is already there" — it needs a write:
the instance must push the tail to
/dev/consolebefore terminating.That is a change to the generated bootstrap, not a read-only CLI addition. Still
small, still needs no bucket and no IAM, but I described it as cheaper than it is.
Revised recommendation — still B, now with a size budget
spored's pre-terminate path writes the last ~50 lines of/var/log/spawn-command.logto/dev/console, framed so it is findable:A 50-line tail is a deliberate budget, not a guess: console output is capped
(~64 KB), the measured baseline boot already consumes ~13 KB of it, and the
failure reason is almost always in the last few lines. Writing the whole log
would risk evicting the cloud-init messages that are also diagnostic.
sporedalready has a pre-terminate hook — the same placepkg/taskproto/flush.gouploads the log on the task path — so this is one more step there, gated on a
non-zero exit so a successful job writes nothing.
Ordering against A (always upload to S3) is unchanged and the measurement
reinforces it: A is the only option that worsens the un-reaped
spawn-results-*problem, and it does so on every launch rather than on the failures you care
about. If A is ever wanted it should ship with the S3 lifecycle policy #653 lists.
C (upload only on non-zero exit) remains the right second step if the 50-line
tail proves too thin in practice — better to learn that from real failures than
to assume it now.
D (refuse
--on-complete terminatewithout a results bucket) stays wrong: itconverts a missing diagnostic into a launch failure.
fix: replace the sleeps that were waiting on AWS state (#752 items 2-…
scttfrdmn commentedon Oct 8, 2026
Probe result: console writes DO surface — option B is viable
Measured on a real instance: wrote a nonce to
/dev/consoleover SSM, terminated,then polled
get-console-output.A userspace write to
/dev/consoledoes appear inGetConsoleOutput, sooption B works. Combined with the earlier measurement — console output outlives
the instance's visibility in
describe-instancesby hours — the whole path issound.
I nearly called this a failure
My first read was at ~3 minutes and returned 0 bytes, and I reported the probe
as negative. That was wrong, and the mistake is worth recording because it is the
same one I made earlier in this backlog: treating an empty result as a negative
result. A 0-byte console is not "the nonce is missing", it is "nothing has been
captured yet".
Two facts that only emerged from waiting:
get-console-outputreturns nothing at all for a just-terminated instance.this lag — the 12 KB reads were on instances terminated hours before.
What that means for the implementation
Option B as planned, with one documented caveat: the log is not readable for
roughly five minutes after termination. That is fine for "why did it vanish?",
which is asked minutes-to-hours later, but it means the CLI must not promise an
immediately-readable log. Any message pointing a user at
aws ec2 get-console-outputshould say to allow a few minutes.Still a 50-line tail, for the reason already established: console output is capped
around 64 KB and a baseline boot consumes 13–17 KB, so dumping the whole log risks
evicting the cloud-init messages that are also diagnostic.
Option C is no longer needed. It stays the fallback if the console path turns out
to be unreliable in a way one instance cannot show.
feat(spored): copy a failed job's log tail to the serial console
feat(cmd): spawn logs — a spore's log, including after it terminated
feat(spored): copy a failed job's log tail to the serial console (#759)
feat(cmd): spawn logs — a spore's log, including after it terminated
test(e2e): classify logs in the Tier 0 coverage gate
feat(cmd): spawn logs — a spore's log, including after it terminated (#…