8000 fix(minimald): end daemon-terminated attaches and execs with a non-zero status and a notice by norrietaylor · Pull Request #1977 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div class="prc-PageLayout-HeaderContent-gdFfN" style="--spacing:var(--spacing-none)">

fix(minimald): end daemon-terminated attaches and execs with a non-zero status and a notice - #1977

Merged
norrietaylor merged 1 commit into
mainfrom
fix/daemon-terminated-exit-status
Oct 5, 2026
Merged

norrietaylor merged 1 commit into
mainfrom
fix/daemon-terminated-exit-status

Conversation

@norrietaylor
Copy link
Copy Markdown
Member

Problem

min session attach exits 0 when the daemon ends the attach: the session is destroyed from another terminal, another connection takes it over, or the daemon shuts down. A script cannot tell those ends from a detach. The binding teardown sent exit_status(0) for every exit reason except a shed binding.

A running min session exec that min stop --force kills ends with status 137 and no message, while an attached shell prints a shutdown notice in the same situation.

Fix

  • session_host.rs: map each MainloopExitReason to an exit status. Detach and ProcessExited stay 0. HostGone, Superceded, and Shutdown report the new DAEMON_ENDED_EXIT_STATUS (254), documented beside SHED_EXIT_STATUS (255, unchanged). 254 is non-zero but is not ssh's 255, so the client's blind terminal unwind stays off for ends where the daemon already sent its own unwind codes. HostGone now prints Disconnecting - the session is gone, the same way shutdown and supersede already print a farewell.
  • sessions.rs: the manager's in_shutdown flag becomes a CancellationToken shared with ManagerHandle, which exposes is_shutting_down(). The manager sets it before it stops any session. The server's shutdown token cannot be used here because it is cancelled only after the drain.
  • exec.rs: ExecTask::run goes through a new bridge_noting_shutdown wrapper. If the daemon is shutting down when the bridge returns, the wrapper writes minimald is shutting down; the command was stopped to the stderr extended-data stream. That happens before the exit status goes out, and the command's own status is still what gets reported.
  • docs/reference/cli-min.md: document the attach exit statuses and the exec shutdown notice.

The min client already exits with ssh's status, so the client needs no change.

Tests

New tests:

  • session_host::tests::daemon_ended_attaches_report_a_non_zero_exit_status: Shutdown, HostGone, and Superceded report 254. Detach and ProcessExited report 0, and Shed reports 255.
  • exec::tests::an_exec_ended_by_shutdown_writes_the_notice_to_stderr: a bridge that ends during shutdown writes the notice after the command's own stderr and keeps the command's status (137). A bridge that ends outside a shutdown writes no notice.

Commands and results (aarch64 musl through cross, on a macOS host):

  • CROSS_CONTAINER_OPTS="--env HOME=/tmp" cross test -p minimald --target aarch64-unknown-linux-musl --locked --lib -- exec:: session_host:: sessions:: returned 135 passed and 2 failed. The failures were expose_ask_after_detaching_is_refused_by_the_live_host (shared log capture) and expose_ask_shed_mid_dialog_is_the_daemons_refusal (a timeout under emulation load).
  • ... cross test ... -- session_host::tests::expose_ask_ reran those tests in isolation: 9 passed, 0 failed.
  • CROSS_CONTAINER_OPTS="--env HOME=/tmp" cross clippy -p minimald --target aarch64-unknown-linux-musl --locked --all-targets -- -D warnings was clean.
  • cargo fmt --check was clean.
  • just minimal-cli builds.

I did not exercise the end-to-end attach and exec paths against a running daemon.

Refs gominimal/inbox#857

…ro status and a notice

An attach the daemon ended (session destroyed, superseded by another
connection, daemon shutdown) reported exit status 0, the same as a
detach. It now reports 254, and a binding whose host went away prints a
one-line notice like the shutdown and supersede farewells already do.

An exec a daemon shutdown stops now writes "minimald is shutting down;
the command was stopped" to stderr before its exit status. The check
reads the sessions manager's shutdown state, now a CancellationToken
shared with its handles, which is set before any session is stopped.
@norrietaylor
norrietaylor requested a review from a team as a code owner October 5, 2026 06:06
@coderabbitai
coderabbitai Bot commented Oct 5, 2026
Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 5 billable files and costs up to $1.25.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 24 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 44e77fda-f736-4edd-8351-d1d59dfa115b
📥 Commits

Reviewing files that changed from the base of the PR and between 908b5a8 and 60d4085.

📒 Files selected for processing (5)
  • crates/minimald/src/exec.rs
  • crates/minimald/src/session_host.rs
  • crates/minimald/src/session_host/tests.rs
  • crates/minimald/src/sessions.rs
  • docs/reference/cli-min.md
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@minimal-foundry
minimal-foundry Bot commented Oct 5, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at 60d408521f32.

Nothing to do.

Clobber: none. git log on the three changed source files shows the touched lines were last modified by this commit; the in_shutdown field and the bridge call site have no prior fix being reverted.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approved

Verdict APPROVE — No findings.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 5, 2026
@norrietaylor
norrietaylor added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit 4564a65 Oct 5, 2026
35 checks passed
@norrietaylor
norrietaylor deleted the fix/daemon-terminated-exit-status branch October 5, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0