Skip to content

Declining a confirmation prompt exits 0, so a script cannot tell "terminated" from "did nothing" (11 call sites) #737

Closed

Description

@scttfrdmn

Reported from the 2026-10-07 demo for spawn terminate. Confirmed, and it is a
class, not one command.

Reproduced

cmd/terminate.go:111:

if !confirmTerminate(fmt.Sprintf("Permanently terminate %s?", label)) {
    fmt.Fprintln(os.Stderr, "Aborted.")
    return nil          // <- exit 0
}

With non-interactive stdin the read fails, confirmYes returns false, Aborted.
is printed, the process exits 0, and the instance keeps running and billing.
The reporter first read this as "terminate silently did nothing", because an
output filter hid the prompt — which is the real hazard: the only thing
distinguishing success from a no-op was a line on stderr.

Every abort site in the CLI does the same. All eleven return nil:

file:line command
cmd/terminate.go:112 terminate (single)
cmd/terminate.go:177 terminate (job array)
cmd/cancel.go:132 cancel
cmd/cleanup.go:152 cleanup
cmd/dns.go:217 dns
cmd/alerts.go:342 alerts
cmd/team.go:282, :310 team
cmd/autoscale_lifecycle.go:131 autoscale
cmd/pipeline.go:682 pipeline
cmd/reaper.go:193 reaper arm
cmd/bot.go:607 bot

The cost-safety ones matter most — terminate, cleanup, cancel, and the
job-array path, which can leave an entire cohort running.

Why exit 0 is wrong here

spawn terminate exiting 0 means "the instance is not running any more". On an
abort that is false. An agent or a CI step that checks the exit code — the normal
way to drive this — concludes the spore is gone and stops watching. Cost control
is existential for this project, and this is the one path where a wrong exit code
costs money indefinitely.

Note the asymmetry already established in #648 is about something different and
should be preserved: a name that resolves to nothing is success (the instance is
already gone, which is what the caller wanted). An abort is the opposite — the
instance is definitely still there.

Suggested fix

Return a distinct non-zero exit for "user declined". Concretely:

  1. A shared errAborted sentinel returned from all eleven sites, mapped to a
    dedicated exit code in main — not 1, so "you said no" stays
    distinguishable from "it failed". Something in the 70s, or reuse the 3 that
    --check-complete already uses for its own meaning elsewhere; the number
    matters less than it being stable and documented.
  2. Distinguish a declined prompt from an unreadable one. confirmYes
    currently collapses "user typed n" and "stdin is not a terminal" into the same
    false. Non-interactive with no --yes is a usage error — the caller forgot
    a flag — and deserves a clearer message than Aborted.:
    terminate: refusing to prompt on non-interactive stdin; pass --yes.
  3. Document the codes in each command's help, since the whole point is that a
    script can branch on them.

spawn terminate <name> --yes works correctly today and finds the instance across
regions, so there is no gap in capability — only in what the exit code says.

Environment: spawn v0.123.0.

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