Skip to content

fix(cmd): exit non-zero on a declined prompt, and fix connect's command string (#737, #738) - #745

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/738-connect-command-string
Oct 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/738-connect-command-string

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #737. Closes #738.

#737 — a declined prompt exited 0

spawn terminate <name> with non-interactive stdin printed Aborted. and
exited 0 while the instance kept running and kept billing. The only thing
separating success from a no-op was a line on stderr, which the reporter's output
filter hid — so it read as "terminate silently did nothing". An agent or CI step
checking the exit code concludes the spore is gone and stops watching.

Now exits 75 (EX_TEMPFAIL, "the user is invited to retry"). Deliberately
not 1: "you said no" and "it failed" need different handling, and collapsing them
forces a caller to parse text to tell a deliberate decline from a broken command.
Messages name the consequence — aborted: web-1 (i-abc) is still running (terminate it with --yes) — instead of a bare Aborted.

The issue said eleven sites. There are nineteen. My original count came from
grepping a hand-picked list of files; an exhaustive grep found terminate
(single + job array), cleanup, cancel, state, arraygroup ×2, team ×2,
stage, schedule, plugin, dns, alerts, autoscale, pipeline, reaper
and bot. All converted.

#648's opposite case is preserved and worth restating: a name that resolves to
nothing stays success for terminate, because the instance is already gone,
which is what the caller wanted. An abort is the reverse — the instance is
definitely still there.

A regression I introduced, caught by existing tests

An unanswered prompt (EOF, nothing read) now says No answer on stdin — pass --yes to confirm non-interactively rather than the same Aborted. as a typed
"no".

My first version gated that on stdinIsInteractive() and therefore refused to
read a piped answer — breaking echo y | spawn terminate …, which is a
legitimate scripted confirmation. The pre-existing confirmYes tests failed
immediately, because they feed stdin through an os.Pipe, which is not a
character device. Narrowed to the EOF case, which is the one the issue was
actually about.

The static gate took four attempts to make real

Each failed differently, and each is recorded in the test's comment because the
pattern is the point:

  1. Grepped confirmYes( only — missed terminate.go, which goes through
    confirmTerminate, and so passed against a deliberate revert of the very
    site the issue was filed for.
    Same blind spot that made my count eleven.
  2. Used strings.HasSuffix — return nil // pre-#737 slipped past, which is
    exactly the shape a revert (or a well-meant annotation) takes.
  3. Used -A 2 — the two lines after terminate's prompt are comments, so the
    return sat outside the window. Passed again.
  4. Now -A 8, any confirm* helper, a regex allowing a trailing comment, and a
    stop at the branch's closing brace so a return nil after the block is not
    blamed on it.

Verified against two revert shapes (via confirmTerminate with a comment,
and a plain return nil at a confirmYes site). A companion test asserts the
gate's own reach — 33 sites across 4 helpers — so it cannot silently shrink when
a helper is renamed.

#738 — connect -- 'cmd; cmd' ran the string as a command name

A single post--- argument was quoted into one word, so the remote shell looked
for a command literally named free -m; tail /var/log/x and exited 127 with No such file or directory naming the user's whole command.

That was #369's fix over-correcting: #369 was the opposite bug (argv
re-split by space-joining, so -- bash -lc "a && b" left -c with no argument),
and per-argument quoting fixed it at the cost of the command-string form.

The rule is now explicit on argument count — one argument is a shell command
line, several are an argv
— so both work. Both directions are pinned by tests,
since each has now been broken by fixing the other.

This deliberately does not match ssh exactly, and shouldn't: real ssh
does no quoting at all, which is why ssh h bash -lc "a && b" is broken for
ssh too and why everyone single-quotes for it. Matching it literally would
reintroduce #369. (Thanks for conceding the point in the issue — the argument
count is what reconciles the two.)

One more thing worth knowing: the single-argument passthrough is unquoted by
design
, and there is an explicit test asserting it stays that way, so nobody
"hardens" it back into #738.

Verification

revert fails
terminate's abort returns nil (with a comment) 1 declined-prompt site(s) still return nil: ./terminate.go:114
team delete's abort returns nil (plain) ./team.go:309
single connect arg quoted again #738: quoting it made the remote shell look for a command with that literal name (exit 127)

gofmt, go vet ./..., go test -short ./... (all green), make check-docs,
changelog gate, semgrep scan --config=auto --error (0 findings).

Also fixed a malformed expectation in my own new test: I wrote 'echo' 'it'\'''
where the real output is 'echo' 'it'\''s' — I'd dropped the trailing s'. The
code was right; the test wasn't.

Remaining from the demo notes

#733 (spawn status performs a DNS write), #734 (CPU sentinels), #735 (boot time
reported as stopped time), #736 (terminated instances invisible to lookup).

…onnect's command string

#737: declining a prompt exited 0. `spawn terminate <name>` with
non-interactive stdin printed "Aborted." and exited 0 while the instance
kept running and kept billing — and the only thing separating success
from a no-op was a line on stderr, which the reporter's output filter
hid. An agent or CI step checking the exit code concluded the spore was
gone.

A declined prompt now exits 75 (EX_TEMPFAIL, "the user is invited to
retry"). Not 1: "you said no" and "it failed" need different handling,
and collapsing them forces a caller to parse text. Messages name the
consequence — "aborted: web-1 (i-abc) is still running" — instead of a
bare "Aborted.".

The issue counted ELEVEN such sites, from a hand-picked file list. An
exhaustive grep found NINETEEN: terminate (single + job array), cleanup,
cancel, state, arraygroup ×2, team ×2, stage, schedule, plugin, dns,
alerts, autoscale, pipeline, reaper, bot. All converted.

#648's opposite case is preserved: a NAME that resolves to nothing stays
success for terminate, because the instance is already gone, which is
what the caller wanted. An abort is the reverse.

An unanswered prompt (EOF, nothing read) now says "No answer on stdin —
pass --yes" rather than the same "Aborted." as a typed no. My first
version gated this on stdinIsInteractive() and so refused to read a
PIPED answer — breaking `echo y | spawn terminate`, which is legitimate.
The pre-existing confirmYes tests caught it: they feed stdin through an
os.Pipe, which is not a character device. Narrowed to the EOF case.

#738: `connect -- 'cmd; cmd'` quoted a single argument into one word, so
the remote shell looked for a command literally named
"free -m; tail /var/log/x" and exited 127. That was #369's fix
over-correcting — #369 was the opposite bug (argv re-split by
space-joining, leaving bash's -c without an argument). The rule is now
explicit on argument count: ONE argument is a shell command line,
SEVERAL are an argv. Both directions are pinned, since each has now been
broken by fixing the other.

This deliberately does not match ssh exactly: real ssh does no quoting
at all, which is why `ssh h bash -lc "a && b"` is broken for ssh too.

The static abort gate took FOUR attempts to make real, each failing for
a different reason, all recorded in its comment:
  1. grepped `confirmYes(` only — missed terminate.go, which goes via
     confirmTerminate, and so PASSED against a revert of the very site
     the issue was filed for;
  2. used strings.HasSuffix — `return nil // pre-#737` slipped past it,
     which is exactly what a revert looks like;
  3. used -A 2 — the two lines after terminate's prompt are comments, so
     the return sat outside the window;
  4. now -A 8, any confirm* helper, regex allowing a trailing comment,
     stopping at the branch's closing brace. Verified against two revert
     shapes, and a companion test asserts the gate's own reach (33 sites,
     4 helpers) so it cannot silently shrink.
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.23810% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/terminate.go 0.00% 4 Missing ⚠️
cmd/arraygroup.go 0.00% 2 Missing ⚠️
cmd/team.go 0.00% 2 Missing ⚠️
cmd/aborted.go 93.33% 1 Missing ⚠️
cmd/alerts.go 0.00% 1 Missing ⚠️
cmd/autoscale_lifecycle.go 0.00% 1 Missing ⚠️
cmd/bot.go 0.00% 1 Missing ⚠️
cmd/cancel.go 0.00% 1 Missing ⚠️
cmd/cleanup.go 0.00% 1 Missing ⚠️
cmd/connect.go 80.00% 1 Missing ⚠️
... and 8 more

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit acf2e16 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/738-connect-command-string branch October 8, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant