Skip to content

feat(spored): copy a failed job's log tail to the serial console (#736) - #759

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/736-console-log-tail
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/736-console-log-tail

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #736's diagnosis gap — option B, after a probe established it works.

The gap

When a --command workload failed and the instance self-terminated,
/var/log/spawn-command.log went with it. The exit code survived in a tag; the
reason did not. From outside, "the job failed" and "the job failed because
the package install 404'd"
were the same event. A reporter hit exactly this: a
job failed, the instance self-terminated, and there was no way to find out why.

pkg/taskproto/flush.go already solves this for the task path by uploading
the log to the results prefix. A plain spawn launch --command … --on-complete terminate has no results bucket, so nothing flushed.

Measured, not assumed

Three facts, all probed on real instances:

A userspace write to /dev/console appears in get-console-output yes — nonce probe
Console output outlives describe-instances visibility yes — 12,848 bytes for an instance already reporting state = None
The post-termination capture is immediate no — it takes ~4–5 minutes, and before that the API returns nothing at all rather than a partial result

That third one matters enough to be in the user-facing log line. I made the
mistake myself
: my first read was at ~3 minutes, returned 0 bytes, and I briefly
reported the whole approach as not working. An empty console is not "the write
failed", it is "nothing has been captured yet" — and an immediate read looks
exactly like a missing log.

t+45s … t+225s   size=0      nonce_hits=0
t+270s           size=16842  nonce_hits=1

A fourth fact, learned while validating the MPI work in #758: only some
cloud-init output reaches the console on its own.
Rank 0's console held
mpirun's result but not the surrounding script's echos. So this has to be an
explicit write — relying on a log line drifting to the console does not work.

Design choices

  • 50 lines is a budget, not a guess: console output caps around 64 KB and a
    baseline boot consumes 13–17 KB, so copying a whole log would evict the
    cloud-init messages that are also diagnostic — the ones that explain a
    boot-time failure.
  • Console over S3. No bucket, no IAM grant, no new write path — and so it
    does not enlarge the un-reaped spawn-results-* footprint on every launch,
    which was the standing objection to option A. The task path's S3 flush is
    untouched.
  • Failed outcomes only. A successful job's log is rarely read and console
    space is shared with the boot messages.
  • No new plumbing for the gate: checkCompletion was already reading the
    completion record just to log it.
  • completionFailed is lenient by design — unparseable, truncated and absent
    records all mean "not a failure", because this runs on a teardown path and must
    never interfere with it. All four cases are tested.
  • tailFile reads forward keeping a ring rather than seeking from the end, and
    raises the scanner's token limit to 1 MB. A workload emitting a 200 KB stack
    trace on one line is exactly the failure worth diagnosing
    , and the default
    64 KB limit would error the scan out and lose the tail entirely.

sysWriteConsole follows the package's existing platform split
(sys_linux.go / sys_windows.go / sys_other.go, alongside sysWarnUsers) and
is a no-op on Windows and dev builds, where /dev/console does not exist.
Cross-compiled for windows/amd64 and linux/arm64 to confirm.

Verification

revert fails
completionFailed never fires completionFailed("{"status":"failed","exit_code":1}") = false, want true — the reported case
default 64 KB scanner limit the tail lost its last line to a long-line scan error — which is the case most worth diagnosing

gofmt, go vet ./..., go test -short ./..., cross-compile ×2,
make check-docs, changelog gate, semgrep (0 findings).

A process note

These six files were briefly committed onto #758's branch by mistake — they were
uncommitted when I switched branches and a git add -A swept them in. Split back
out by extracting them from that commit, resetting this branch to main, and
restoring them here. #758 is being corrected to contain only its own changes;
neither branch has been merged in the interim, so nothing downstream saw the mix.

Not in scope

The ~5-minute capture delay means the CLI should probably tell a user where to
look when a --on-complete terminate job fails, rather than relying on them
knowing get-console-output exists. That is a separate UX change and wants its
own issue.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.67797% with 35 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/consolediag.go 48.00% 24 Missing and 2 partials ⚠️
pkg/agent/sys_linux.go 0.00% 7 Missing ⚠️
pkg/agent/agent.go 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Closes #736's diagnosis gap.

When a --command workload failed and the instance self-terminated,
/var/log/spawn-command.log went with it. The exit code survived in a
tag; the REASON did not. From outside, "the job failed" and "the job
failed because the package install 404'd" were the same event.

spored now copies the last 50 lines of that log to the serial console
before terminating, on a FAILED outcome only.

Both facts this depends on are MEASURED, not assumed:

- A userspace write to /dev/console does appear in
  ec2 get-console-output. Probed with a nonce on a real instance.
- That output outlives the instance's visibility in describe-instances
  by hours (12,848 bytes returned for an instance already reporting
  state=None).
- The post-termination capture takes ~4-5 MINUTES to populate, and
  before that the API returns NOTHING rather than a partial result. The
  log line says so, because an immediate read looks exactly like a
  missing log — I made that mistake myself while probing and briefly
  concluded the whole approach did not work.

50 lines is a budget, not a guess: console output caps around 64 KB and
a baseline boot consumes 13-17 KB, so copying a whole log would evict
the cloud-init messages that are ALSO diagnostic.

Chosen over an S3 upload because it needs no bucket, no IAM grant and no
new write path, so it does not enlarge the un-reaped spawn-results-*
footprint on every launch. The task path keeps its existing S3 flush
(pkg/taskproto/flush.go), unaffected.

sysWriteConsole follows the package's existing platform split and is a
no-op on Windows and dev builds, where /dev/console does not exist.
Cross-compiled for windows/amd64 and linux/arm64 to check that.

The failure gate needed no new plumbing: checkCompletion was already
reading the completion record just to log it. completionFailed is
lenient by design — unparseable, truncated, and absent records all mean
"not a failure", because this runs on a teardown path and must never
interfere with it.

tailFile reads forward keeping a ring rather than seeking from the end,
and raises the scanner token limit to 1 MB. A workload emitting a 200 KB
stack trace on one line is exactly the failure worth diagnosing, and the
default 64 KB limit would error the scan out and lose the tail entirely.

Gates confirmed to fail on revert: completionFailed never firing, and
the default scanner limit losing the tail on a long line.
@scttfrdmn
scttfrdmn force-pushed the feat/736-console-log-tail branch from d88a648 to fcac400 Compare October 8, 2026 19:25
@scttfrdmn
scttfrdmn merged commit d7c0448 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/736-console-log-tail branch October 8, 2026 19:31
scttfrdmn added a commit that referenced this pull request Oct 8, 2026
Promotes [Unreleased] to [0.126.0] and adds the compare link.

MINOR, not PATCH, because this release contains a breaking change to a
package other repos compile against: pkg/taskproto's three script
generators now take a WrapperOptions struct and return an error (#765/#764).
Pre-1.0 the project's rule is that a breaking change bumps MINOR.

Also in this release: the cross-repo API surface gate that will report the
next such change before it ships (#763/#679), `spawn logs` (#761), the
spored console log tail it reads (#759), the MPI peer-SSH readiness poll
(#758), and the remaining sleep-audit fixes plus the creation-stamp/orphan
reaper work (#752, #755, #756, #757, #762).

Release guard passed: both binaries report 0.126.0 for tag v0.126.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant