Skip to content

feat(launch): announce the shell options --command inherits (#707) - #721

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/707-announce-shell-options
Oct 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/707-announce-shell-options

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #707. Your ask (1) — the one you said would have ended your afternoon — plus (2), and it turns out (3) needed no flag.

What lands now

Two lines at the top of /var/log/spawn-command.log:

spawn: shell options for --command: $-=ehB
spawn: errexit is ON. set -uo pipefail does NOT clear it; use set +e to opt out.

Printed rather than changed, as you asked. Fail-fast is a defensible default and running on after a broken step until TTL would be worse — the problem was never the policy, it was that the policy was invisible.

The --command help now says the same thing, including that ... | head -n N and wait $pid are the common casualties, so it is discoverable before a run rather than after one.

Ask (3) turns out to be free

You offered --no-errexit as optional. It isn't needed: your command is appended to the same script that sets -e, so set +e as your first line already takes over error handling. It was never undiscoverable by design, only undocumented — so the announcement names it and the flag help repeats it. If you'd still prefer an explicit flag, say so and I'll add one, but I'd rather not add surface for something a one-line idiom already does.

I nearly shipped something worse than the bug

Worth telling you because it bears on how the fix is tested. My first version piped both announcement lines through tee -a /var/log/spawn-command.log. But the command script runs as $LOCAL_USERNAME via su and cannot write that path — and under the set -e at the top of the very same script, a failed tee would have killed the command before it started. Every --command launch, broken by the line explaining why commands break.

The caller already pipes the script's combined output through tee as root, so plain stdout reaches the log anyway.

I only caught it because I executed the generated script instead of reading it — which is also how the tests work:

  • one runs the real heredoc under bash and reproduces your measurement: $-=ehBc, and still ehuBc after set -uo pipefail, so the inherited e is asserted rather than assumed;
  • a second gates the tee from returning, naming why it would be fatal;
  • both verified to fail when reverted.

That first test also pins the claim honestly: if errexit ever stops surviving set -uo pipefail, it fails — because the announcement would then be telling users something untrue.

On your accounting

You noted the project's own notes already recorded that a task command runs under set -e, in the rm -f/EPERM context, and that you didn't connect it to launch --command. That connection was ours to make, not yours: the note lived in task-run territory and nothing on the --command path said a word. Four runs and a withdrawn page is a steep price for a line of output we could have printed on day one, and the $- probe you wrote is now effectively shipped as that line.

One incidental for the record: backticks in a Go raw string broke the build on the way — third time this session. Prose inside these generated-shell templates can't use them.

--command runs with errexit ALREADY enabled, and `set -uo pipefail` does not clear
it — so a script opening with that idiomatic line, believing it chose its own error
policy, actually runs -e -u -o pipefail.

The failure mode is silent and actively misleading: the script exits BEFORE the line
that would have reported why. Two ordinary idioms are the casualties — a SIGPIPE'd
pipeline under pipefail (`... | head -n N` returns 141) and `wait $pid` on a failed
background job, which is specifically a pattern for CAPTURING a failure and which -e
destroys at the moment it matters. It cost the reporter four r8gd.8xlarge runs and
three misdiagnoses, one of which reached a published page and had to be withdrawn.

Printed rather than changed, which is what they asked for: fail-fast is a defensible
default and running on after a broken step until TTL would be worse. Two lines now
open /var/log/spawn-command.log — the real $- and a note that set -uo pipefail will
not clear errexit, with `set +e` as the opt-out. The --command help says the same,
so it is discoverable before a run rather than after one.

That also answers the optional third ask without a new flag: `set +e` as the first
line of the user's script already takes over error handling, because the command is
appended to the same script that sets -e. It was never undiscoverable by design,
only undocumented.

I nearly shipped something worse than the bug. The first version piped both
announcement lines to `tee -a /var/log/spawn-command.log` — but this script runs as
$LOCAL_USERNAME via su and cannot write there, and under the set -e at the top of
the same script a failed tee would have killed the command BEFORE it started. Every
--command launch, broken by the line explaining why commands break. The caller
already pipes the script's combined output through tee as root, so plain stdout
reaches the log anyway.

That was caught by EXECUTING the generated script rather than reading it, which is
also how the tests work: one runs the real heredoc under bash and reproduces the
reporter's measurement ($-=ehBc, still ehuBc after set -uo pipefail), and a second
gates the tee from coming back, naming why. Both verified to fail when reverted.

Backticks in a Go raw string broke the build again on the way — third time this
session. Prose in these templates cannot use them.
@scttfrdmn
scttfrdmn force-pushed the fix/707-announce-shell-options branch from 4935656 to 82a56bb Compare October 5, 2026 17:53
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit a6c87a7 into main Oct 5, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/707-announce-shell-options branch October 5, 2026 18:03
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 launch --command runs under bash -e, invisibly: 'set -uo pipefail' does not clear it, and the script dies before it can report why

1 participant