Skip to content

feat(task): spawn task diagnose (#391) - #396

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/391-task-diagnose
Jul 19, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/391-task-diagnose

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Implements #391 (docs-review follow-up).

What

spawn task diagnose <name|instance-id> — a one-screen summary of a single instance, aggregating signals that are otherwise scattered across spawn status, spawn cost, tags, and logs:

Task:        train-42 (i-0abc123)
Type:        g5.xlarge (spot)
State:       terminated
Region/AZ:   us-east-1 / us-east-1a
Age:         3h12m
TTL:         4h
Est. cost:   ~$3.20 (3h12m × $1.0060/hr, estimate)
Job array:   train (index 42 of 64)

Likely: instance is terminated — if this was unexpected, a Spot interruption is a
common cause (check the spored log for a spot_interrupt event).

Logs (on the instance):
  spored:   /var/log/spored.log
  command:  /var/log/spawn-command.log
  fetch:    spawn connect train-42 -- tail -n 200 /var/log/spawn-command.log

Design

  • Read-only, composes existing data (resolveInstance → InstanceInfo + spawn:* tags). No new data plane.
  • No SSH in the base path, so it works even when the instance is unreachable — the log pointers tell you where to look once you can connect (rather than failing to fetch).
  • Cost is an honest estimate: spawn:price-per-hour tag × age, explicitly labeled "estimate", and 0 (omitted) when the rate tag is absent. Standalone instances have no DynamoDB cost record (that's keyed by sweep-id), so a per-instance figure would otherwise be fabricated.
  • Likely-cause is hedged, never asserted — the logs are authoritative.

Tests

cmd/task_test.go: pricePerHour (good/missing/malformed tag), estimateInstanceCost (rate×age, unknown-rate→0, negative-age→0), likelyCause (running/terminated/spot/stopped), cliName fallback.

Notes

  • New docs-gen/task.md.
  • gofmt/vet/go test ./cmd/ clean.

Closes #391

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 34.00000% with 66 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/task.go 34.00% 66 Missing ⚠️

📢 Thoughts on this report? Let us know!

A one-screen "what happened to this instance" view that aggregates the
signals spawn already has into one place: identity, lifecycle state,
region/AZ, age, TTL, an on-the-fly compute-cost estimate (price-per-hour
tag × age, clearly labeled and 0 when unknown), job-array/sweep
membership, a hedged likely-cause hint from state (terminated → TTL or
Spot; stopped → idle), and pointers to the spored + command logs.

Read-only; composes InstanceInfo + spawn:* tags. It does NOT open an SSH
session in the base path, so it works even when the instance is
unreachable — the log pointers say where to look once you can connect.

Closes #391
Every top-level command must be classified in TestTier0_CommandCoverageGate.
Defer 'task' to Tier 1/2 (diagnose reads a live instance's state/cost/logs);
the pure cost/heuristic helpers are unit-tested in cmd.
@scttfrdmn
scttfrdmn force-pushed the feat/391-task-diagnose branch from 7629508 to f458cb0 Compare July 19, 2026 16:23
@scttfrdmn
scttfrdmn merged commit f4f57a1 into main Jul 19, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/391-task-diagnose branch July 19, 2026 16:25
scttfrdmn added a commit that referenced this pull request Aug 1, 2026
* chore(deps): bump substrate test dependency to v0.81.0

Test-only; no runtime or API change (root + lambda/dns-updater).

The reason to take it now is substrate#412: RunInstances previously accepted an
empty ImageId and launched an instance, so our guard against launching without a
resolved AMI had no offline test that could fail -- the bug we filed it for
shipped, and was caught only by a paid smoke test against real AWS. Substrate now
returns MissingParameter / HTTP 400 when no AMI resolves from any source
(request or launch template), so that path is reachable in -short tests.

Fixing it also surfaced a substrate request-parser defect: an explicitly-empty
query-protocol body parameter was coerced to the bare-key sentinel "1", so
ImageId= arrived as the string 1 and launched from an AMI named 1 -- affecting
every EC2/IAM/STS/SQS/SNS parameter sent empty.

Also newly testable offline: Invalid*ID.NotFound for explicit EC2 IDs (#391),
symbolic Error.Code per service (#392), Lambda invoke omitting FunctionError and
LogResult (#393), S3 Range and conditional requests (#396, #397),
x-amz-checksum-* verification (#399), storage classes and CopyObject metadata
directives (#398), Content-Encoding surviving a multipart upload (#406), and a
seedable SQS create-then-lookup consistency window with the correct
QueueDoesNotExist code -- the legacy dotted form was uncatchable as a typed
error in either SDK, which is what the taskpool queue-lifecycle tests assert on
(#413).

Note: cmd's TestCatalogValid fails on main already (two private ECR images in
the shipped app catalog, #392) and is unrelated to this bump.

* fix(ttl-reaper): bump accountlifecycle past the substrate import move

The Security job on this branch (and on main — this is not PR-introduced) failed
with `go: updates to go.mod needed` in lambda/ttl-reaper. Cause is Go MVS plus
upstream tag timing, not any commit here:

  ttl-reaper requires spore-host/lambda/accountlifecycle at a pseudo-version
  whose *test* imported substrate at its old root path. Substrate moved that
  package to /emulator in v0.70.0, so once v0.80.0 (2026-08-01 02:11Z) and
  v0.81.0 (06:12Z) were tagged — after spawn main's last green Security run
  (2026-07-31 17:52Z) — resolution broke with no local change involved.

#509 fixed the import; this bumps the pin to that merged commit
(14e273c). Verified: `go mod tidy -diff` clean, `go build ./...` clean, and
govulncheck (v1.3.0, as CI pins) reports no vulnerabilities.

Note the go.sum-only tidy drift in alert-handler, autoscale-orchestrator and
sweep-orchestrator is pre-existing on main and does not affect govulncheck,
which is what the job actually runs. Left alone here to keep this fix scoped.
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.

spawn task diagnose: unified per-task failure view

1 participant