Repository navigation
fix(cmd): name the instance that just vanished instead of denying it existed (#736) - #747
Merged
Merged
Conversation
…existed
`spawn status chem-arm`, run right after its job failed and it
self-terminated, answered "no instance found with name: chem-arm".
Accurate, and the wrong answer to the question being asked — which was
why it vanished.
resolveInstance lists with the DEFAULT state filter
(pending/running/stopping/stopped), so `terminated` AND `shutting-down`
are both invisible. EC2 keeps terminated instances in DescribeInstances
for about an hour with a StateTransitionReason ("User initiated",
"Client.InstanceInitiatedShutdown", a spot reclaim), so the answer was
already available and simply not requested.
A not-found name or ID is now checked once more against every state:
no instance found with name: chem-arm — chem-arm (i-abc) is
terminated: Client.InstanceInitiatedShutdown
`spawn terminate` uses it too, because it prints its own message on the
idempotent-success path and that message was false for a shutting-down
instance: "No instance \"web\" exists" becomes "Nothing to terminate —
web (i-abc) is shutting-down: User initiated".
Running and stopped instances deliberately produce no hint: they would
have been found by the normal lookup, so reporting them on a not-found
path would be contradictory.
Adds InstanceInfo.StateTransitionReason, which EC2 populates for
terminated/stopped instances only.
This also explains dead code. terminate's "Instance %s is already
shutting down — nothing to do" branch is UNREACHABLE, because the filter
that hides the state is the one its lookup uses. Kept and annotated: it
is correct if a caller ever resolves with the all-states filter, and
deleting it would remove the only in-code record that the state needs
handling. The hint now covers the case it was written for.
Selection and wording are split into formatRecentlyGone, taking a slice
rather than the client, so the decisions — shutting-down preferred over
terminated, most recent preferred among same-state matches, nothing for
a live instance — are testable without AWS.
Gates confirmed to fail on revert: skipping terminal states, and not
preferring shutting-down.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
scttfrdmn
added a commit
that referenced
this pull request
Oct 8, 2026
You asked whether spawn could fetch the console output itself rather than making the user run get-console-output by hand. This is that, as a command. While the instance is alive it tails the log over SSH-or-SSM — the same path `spawn array logs` uses, reusing runArrayMemberCommand and arrayLogPath, and sharing its --which/--lines flags so the two behave alike. A new top-level verb rather than stretching `array logs`, whose name, --index flag and error messages are all job-array-shaped. Once the instance is gone, tailing is impossible: the log died with it. So it reads back the tail spored wrote to the serial console before terminating (#736). The framing spored writes turns out to be a PARSED DELIMITER, not decoration — so the output is the 50 relevant lines, not the 40 KB of UEFI and cloud-init around them. --console prints the whole dump, for failures that happened before the workload started. An absent log is reported as one of TWO things, because they send the user in opposite directions: - terminated <6 min ago -> "try again shortly" (the capture takes ~4-5 minutes to appear); - older -> "spored only writes this when the workload FAILED". Distinguished by the termination time EC2 embeds in StateTransitionReason. When that is absent the hint is withheld rather than guessed: a confidently wrong "try again shortly" is worse than no hint. I made exactly that mistake while probing #736 — read at three minutes, saw an empty dump, and briefly concluded the whole approach did not work. Cache: ~/.spawn/cache/console, 7 days, pruned on every invocation so it cannot outlive its own policy without a daemon. Seven days rather than matching the existing 6h indexCacheTTL — a diagnostic does not go stale the way a package index does, and 6h would expire it BEFORE ITS SOURCE: measured, AWS served console output for instances DescribeInstances had entirely forgotten more than twelve hours later. An empty dump is never cached, so "no log yet" is not pinned for a week. Supporting pieces: - pkg/aws.GetConsoleOutput, which did not exist. The SDK returns Output BASE64-ENCODED and does not decode it — "the tool decodes the output for you" refers to the AWS CLI. My first draft assumed the CLI's behaviour carried over and would have returned base64 garbage; checked against the SDK's own doc comment. - The console markers move to pkg/taskproto, the package the writer (pkg/agent) and reader (cmd/) already share, since cmd does not import pkg/agent. Duplicated literals are how a reader and writer drift apart silently: the block would still be written and simply never found. - selectRecentlyGone split out of #747's formatRecentlyGone, so this reuses the selection and not just its wording. Gates verified to fail on revert: a 6h TTL (shorter than measured source retention), and pruning disabled.
scttfrdmn
added a commit
that referenced
this pull request
Oct 8, 2026
You asked whether spawn could fetch the console output itself rather than making the user run get-console-output by hand. This is that, as a command. While the instance is alive it tails the log over SSH-or-SSM — the same path `spawn array logs` uses, reusing runArrayMemberCommand and arrayLogPath, and sharing its --which/--lines flags so the two behave alike. A new top-level verb rather than stretching `array logs`, whose name, --index flag and error messages are all job-array-shaped. Once the instance is gone, tailing is impossible: the log died with it. So it reads back the tail spored wrote to the serial console before terminating (#736). The framing spored writes turns out to be a PARSED DELIMITER, not decoration — so the output is the 50 relevant lines, not the 40 KB of UEFI and cloud-init around them. --console prints the whole dump, for failures that happened before the workload started. An absent log is reported as one of TWO things, because they send the user in opposite directions: - terminated <6 min ago -> "try again shortly" (the capture takes ~4-5 minutes to appear); - older -> "spored only writes this when the workload FAILED". Distinguished by the termination time EC2 embeds in StateTransitionReason. When that is absent the hint is withheld rather than guessed: a confidently wrong "try again shortly" is worse than no hint. I made exactly that mistake while probing #736 — read at three minutes, saw an empty dump, and briefly concluded the whole approach did not work. Cache: ~/.spawn/cache/console, 7 days, pruned on every invocation so it cannot outlive its own policy without a daemon. Seven days rather than matching the existing 6h indexCacheTTL — a diagnostic does not go stale the way a package index does, and 6h would expire it BEFORE ITS SOURCE: measured, AWS served console output for instances DescribeInstances had entirely forgotten more than twelve hours later. An empty dump is never cached, so "no log yet" is not pinned for a week. Supporting pieces: - pkg/aws.GetConsoleOutput, which did not exist. The SDK returns Output BASE64-ENCODED and does not decode it — "the tool decodes the output for you" refers to the AWS CLI. My first draft assumed the CLI's behaviour carried over and would have returned base64 garbage; checked against the SDK's own doc comment. - The console markers move to pkg/taskproto, the package the writer (pkg/agent) and reader (cmd/) already share, since cmd does not import pkg/agent. Duplicated literals are how a reader and writer drift apart silently: the block would still be written and simply never found. - selectRecentlyGone split out of #747's formatRecentlyGone, so this reuses the selection and not just its wording. Gates verified to fail on revert: a 6h TTL (shorter than measured source retention), and pruning disabled.
scttfrdmn
added a commit
that referenced
this pull request
Oct 8, 2026
…761) * feat(cmd): spawn logs — a spore's log, including after it terminated You asked whether spawn could fetch the console output itself rather than making the user run get-console-output by hand. This is that, as a command. While the instance is alive it tails the log over SSH-or-SSM — the same path `spawn array logs` uses, reusing runArrayMemberCommand and arrayLogPath, and sharing its --which/--lines flags so the two behave alike. A new top-level verb rather than stretching `array logs`, whose name, --index flag and error messages are all job-array-shaped. Once the instance is gone, tailing is impossible: the log died with it. So it reads back the tail spored wrote to the serial console before terminating (#736). The framing spored writes turns out to be a PARSED DELIMITER, not decoration — so the output is the 50 relevant lines, not the 40 KB of UEFI and cloud-init around them. --console prints the whole dump, for failures that happened before the workload started. An absent log is reported as one of TWO things, because they send the user in opposite directions: - terminated <6 min ago -> "try again shortly" (the capture takes ~4-5 minutes to appear); - older -> "spored only writes this when the workload FAILED". Distinguished by the termination time EC2 embeds in StateTransitionReason. When that is absent the hint is withheld rather than guessed: a confidently wrong "try again shortly" is worse than no hint. I made exactly that mistake while probing #736 — read at three minutes, saw an empty dump, and briefly concluded the whole approach did not work. Cache: ~/.spawn/cache/console, 7 days, pruned on every invocation so it cannot outlive its own policy without a daemon. Seven days rather than matching the existing 6h indexCacheTTL — a diagnostic does not go stale the way a package index does, and 6h would expire it BEFORE ITS SOURCE: measured, AWS served console output for instances DescribeInstances had entirely forgotten more than twelve hours later. An empty dump is never cached, so "no log yet" is not pinned for a week. Supporting pieces: - pkg/aws.GetConsoleOutput, which did not exist. The SDK returns Output BASE64-ENCODED and does not decode it — "the tool decodes the output for you" refers to the AWS CLI. My first draft assumed the CLI's behaviour carried over and would have returned base64 garbage; checked against the SDK's own doc comment. - The console markers move to pkg/taskproto, the package the writer (pkg/agent) and reader (cmd/) already share, since cmd does not import pkg/agent. Duplicated literals are how a reader and writer drift apart silently: the block would still be written and simply never found. - selectRecentlyGone split out of #747's formatRecentlyGone, so this reuses the selection and not just its wording. Gates verified to fail on revert: a 6h TTL (shorter than measured source retention), and pruning disabled. * test(e2e): classify logs in the Tier 0 coverage gate Both of `spawn logs`' paths are outside Substrate's surface, so the gate gets a deferred entry rather than a Tier 0 test: - the live path is an SSH/SSM tail of /var/log/spawn-command.log on a booted instance (Tier 2, same as connect/status's SSH path); - the terminated path is ec2:GetConsoleOutput, which Substrate does not model at all — there is no reference to the action anywhere in the emulator, so it can only answer with an unimplemented-action error. A stub would not help either: it would return no serial console, which is the entire artifact being read. Verified against real hardware instead (#736/#758): spored's framed tail appeared in the console ~4.5 min after termination and was still readable 12h later. The pure logic is unit-tested — cache path/TTL/pruning and the recently-gone selection in cmd/logs_test.go, the marker framing and extraction in pkg/taskproto/consolemarkers_test.go.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #736.
The defect
spawn status chem-arm, run immediately after that instance's job failed and itself-terminated:
Accurate, and the wrong answer to the question being asked.
resolveInstancelists with the default state filter —
pending/running/stopping/stopped— soterminatedandshutting-downare both invisible. EC2 keeps terminatedinstances in
DescribeInstancesfor roughly an hour, with aStateTransitionReason("User initiated",Client.InstanceInitiatedShutdown, aspot reclaim). The answer was already available and simply not requested.
Now:
spawn terminateneeded it separately, because it prints its own message onthe idempotent-success path (#648) and ignores the error text. That message was
false for a shutting-down instance —
No instance "web" exists— and is nowNothing to terminate — web (i-abc) is shutting-down: User initiated.A running or stopped instance deliberately produces no hint: it would have
been found by the normal lookup, so reporting it on a not-found path would be
contradictory nonsense. There is a test for each.
It also explains some dead code
terminate's branch:is unreachable, because the filter that hides the state is the one its own
lookup uses. So re-terminating a shutting-down instance took the not-found path
and — per #648 — reported success, with the dead branch making that look
deliberate in the source.
Kept and annotated rather than deleted: it is correct if a caller ever resolves
with the all-states filter, and removing it would remove the only in-code record
that the state needs handling at all. The hint now covers the case it was written
for.
Shape
Selection and wording are split into
formatRecentlyGone, taking a[]aws.InstanceInforather than the client, so the parts with decisions in themare testable without AWS:
branch could never run);
older instances are not what the user just lost;
Adds
InstanceInfo.StateTransitionReason, which EC2 populates forterminated/stopped instances only.
Verification
hint "" does not contain "chem-arm"hint " — web (i-old) is terminated: User initiated" does not contain "i-new"Also asserted: a missing transition reason leaves no dangling
:separator, sinceEC2 omits it for some states.
gofmt,go vet ./...,go test -short ./...(all green),make check-docs,changelog gate,
semgrep scan --config=auto --error(0 findings).Not in this PR — the harder half you raised
Once the instance is gone, its console output and
/var/log/spawn-command.loggowith it, so there is still no way to find out why an
--on-complete terminatejob failed. The exit code survives in tags; the diagnosis does not.
pkg/taskproto/flush.goalready uploadsspawn-command.logand acompletion.jsonto the results prefix for the task path. The gap is that aplain
spawn launch --command … --on-complete terminatehas no results bucket,so nothing flushes. Two directions, recorded in #736:
--on-complete terminateis set — the destructive combination is exactly wherethe log is needed;
GetConsoleOutputsurvives termination for a while, so it needs no bucket.That is a design choice rather than a fix, so it wants its own issue once you pick
a direction.
Remaining from the demo notes
Only #733 —
spawn statusperforming a DNS registration write on every poll.