Skip to content

spawn status -o json ignores -o json entirely: prints the human table plus spored log lines on stdout (0.100.4) #540

Closed

Description

@scttfrdmn

Summary

spawn status <id> -o json prints the ordinary human-readable table on stdout, preceded by four spored agent log lines. There is no JSON anywhere in the output and the exit code is 0, so a caller that does json.loads(subprocess.check_output(...)) fails at character 4 with a misleading Extra data — 2026 (from the leading 2026/08/19 … log timestamp) parses as a valid JSON number, so the error points at the rest of the output rather than at "this is not JSON".

-o, --output string Output format (table, json) (default "table") is a documented global flag and appears in spawn status --help. spawn list -o json honours it and emits a clean array. spawn status is the outlier.

Version: spawn version → 0.100.4.

Reproduction

$ spawn status i-06e86302dd879d75f -o json > out.txt 2> err.txt ; echo "exit=$?"
exit=0
$ wc -c < out.txt
1586
$ python3 -c "import json;json.load(open('out.txt'))"
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)

out.txt in full (complete capture, not truncated — 1586 bytes):

2026/08/19 21:30:10 Agent initialized for instance i-06e86302dd879d75f in us-west-2 (account: 942542972736, provider: ec2)
2026/08/19 21:30:10 Config: TTL=4h0m0s, IdleTimeout=0s, Hibernate=false
2026/08/19 21:30:10 DNS registration skipped: no DNS name configured (no spawn:dns-name tag on the instance)
2026/08/19 21:30:10 Not idle: CPU usage 9.09% >= 5.00%

  sweep-0  (i-06e86302dd879d75f)
  ──────────────────────────────────────────────

  spored:           v0.100.4
  Started:          2026-08-19 21:29 UTC
  Elapsed:          39s
  TTL:              3h 59m remaining  (terminates 2026-08-20 01:29 UTC)
  On complete:      terminate (✓ file present — acting on next check)

  Compute cost:     $0.00  (0s × $1.2762/hr)
  …
  Max compute cost:      ~$5.10 by deadline (on-demand rate, compute only; idle-stop usually ends it sooner)

err.txt contains only Looking up instance i-06e86302dd879d75f..., so the split between streams is deliberate elsewhere in the command — it is the log lines and the table that are on the wrong side of it.

Two distinguishable defects, in case they have different owners:

  1. -o json is not implemented for status — the flag is accepted and silently ignored. Either implement it or reject the value for this subcommand.
  2. spored agent log output goes to stdout. Independent of (1): even once JSON is emitted, those four lines would corrupt it. They belong on stderr (or behind -v), like Looking up instance … already is.

Why it matters

This is the only structured read of a single instance's live state. Guidance we work from says "use the SDK and spawn status -o json; never parse CLI text" — and for a single instance there is currently no supported path that satisfies it. spawn list -o json is a workaround only if you are willing to filter a list across all regions, and it does not carry the per-instance fields status reports (elapsed, TTL remaining, sentinel state, cost-limit consumption).

The practical consequence is that anyone monitoring a run either scrapes the table — brittle, and the reason for the guidance — or reimplements the cost/TTL arithmetic against EC2 tags via boto3, which is what we ended up doing.

Suggested fix

  • Emit the same struct status already builds as JSON when --output json, and include the fields the table shows (sentinel present, TTL deadline, cost-limit consumed, effective rate).
  • Route the agent's log.Printf output to stderr in this code path, so a future JSON document is not preceded by text on the same stream.
  • A --self-test-style guard is cheap here: assert that status -o json output parses as JSON. The current behaviour is exactly the class of bug that passes every human-eyeball review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions