Skip to content

T3 — Stop a box and keep its record - #2733

Merged
mitodrummer merged 16 commits into
mainfrom
agent/2390-stop-a-box-and-keep-its-record
Oct 29, 2026
Merged

mitodrummer merged 16 commits into
mainfrom
agent/2390-stop-a-box-and-keep-its-record

Conversation

@minimal-foundry

@minimal-foundry minimal-foundry Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

T3 — Stop a box and keep its record

slice: S0
kind: task
covers: BOX-013, BOX-018, BOX-154
size: L
est: 420 code, 360 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: daemon log names each stop step
observability: one span per stop, with ending signal
layers:
- actor:
- crates/minimald/src/box_actor.rs: stop message
- crates/minimald/src/box_actor/host.rs: TERM, grace, KILL
- crates/minimald/src/box_runtime/enforcement.rs: signals the whole cgroup
- crates/minimald/src/box_actor/tests.rs: tests
test: cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal
test: cargo nextest run -p minimald stop_force_kills_at_once
- manager:
- crates/minimald/src/box_manager.rs: stop dispatch; orphan to stopped
- crates/minimald/src/box_manager/tests.rs: tests
- crates/minimald/src/rpc.rs: stop handler
test: cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal
test: cargo nextest run -p minimald stopped_box_record_readable_until_reaped
- wire:
- crates/minimald-rpc/src/lib.rs: stop request
test: cargo nextest run -p minimald-rpc stop_box_request_round_trips
produces: none
consumes:
- crates/boxes/src/core/record.rs
- crates/boxes/src/events.rs
proof: A stopped session keeps its record and ending signal.
depends on:
- blocked by #2387
- blocked by #2389
- blocked by #2634

Proof

A client can now send the StopBox RPC for a running session. The daemon sends SIGTERM to every process in the box, waits 10 s, and sends SIGKILL to what is left. With force it sends SIGKILL at once. The record then reads stopped, with the signal or exit code that ended the entrypoint, and an exited event with reason stopped carries the same value. The record, its spec, events and parent stay readable through GetSessionRecord and the events read until the session is destroyed. The proof does not cover a daemon restart: the restart flip of BOX-154 exists and is tested, but nothing calls it at daemon start yet (see notes).

Notes from the agent: 1) BOX-154 is not wired at daemon start. stop_orphaned_running_records (box_manager.rs) sets each running record to stopped with no signal and writes the exited event. The test calls it over a restarted store. I did not call it from BoxManager::init. Box processes die with the daemon (PR_SET_PDEATHSIG), so at start the flip would match every running record. BoxActor::run refuses a stopped record until #2393 (T6, BOX-025). Every session would then fail to attach after a daemon restart, and the restart-resume NET tests (NET-129, NET-138, resume_* in box_manager and box_actor tests) would break. The function has an expect(dead_code) that names #2393. A person must decide whether this flip ships with T6 or here. It skips ends_with_run records, which the resume still destroys (inbox#731).
2) enforcement.rs does not signal a cgroup. Only host-address boxes have a classifier leaf, and the UDP 443 cohort can move several boxes into one shared blocked leaf, so a cgroup signal could kill another box. BoxProcesses signals every live process in the PID namespace that the container supervisor creates for its children. That covers the entrypoint, its descendants, setsid processes and execs. When that namespace is the daemon's own (the test mock launcher), it signals the supervisor's process tree. A process in a nested PID namespa…[truncated]

Tests

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-ed1f... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-e9f6... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-2ce3... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-26b1... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-214f... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify

min task run agent-verify passed ([tasks.verify]).

Out of scope

These files are outside the task's layers:, so this PR is a draft:

  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Residuals

Closes #2390

Maintainer accepted the out-of-layer edits to box_actor/kind.rs, box_runtime.rs and box_runtime/handle.rs (the StopBox name and the container pid a stop signals from), 2026-10-28. Undrafted.

Maintainer also accepted box_actor/handle.rs (the StopForce flag for --force), 2026-10-29.

The request names the box and whether the stop is forced. The
response carries the exit code or the signal that ended the
entrypoint, as the record stores it. Refs BOX-013.
The actor's StopBox message signals every process in the box's PID
namespace, waits the grace period, and kills what is left. A forced
stop kills at once. The record is set to stopped with the signal or
exit code that ended the entrypoint, and an exited event records it.
One box.stop span covers the stop. Refs BOX-013.
The manager refuses to stop a box that is not running and hands the
stop to the box's actor with a 10 s grace. The StopBox RPC answers
the exit code or signal that ended the entrypoint. A stopped record,
its spec, events and parent stay readable until the box is reaped.

stop_orphaned_running_records sets a running record with no process
left to stopped with no signal. It is not called at daemon start yet:
no actor hosts a stopped box until #2393. Refs BOX-013, BOX-018,
BOX-154.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08e50bfa-eb9f-4c67-9a54-c68e1af909ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · 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 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Reviewed: 1 finding, none blocking at b4f415e672c8.

Address the comments on the diff.

Clobber: none seen.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

Comment thread crates/minimald/src/box_actor/host.rs Resolved

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: CONDITIONS · 1 condition · the full ruling

The stop conforms in its order, its grace period and its record fields. One stored ending is wrong. stop_box_processes() reads the portable code 125 as a signal. An entrypoint that exits 125 by itself then gets a signal and no exit code. Line 495 of architecture.md says the record stores the entrypoint's exit_code where one exists. C1 makes the stop use hakoniwa's ExitReason::exit_code and adds a test for it. The BOX-154 call at daemon start stays open as residual #2393.

Ruled at 62c29d8 against gominimal/arch@109541a48c31 by claude-opus-5-5.

Comment thread crates/minimald/src/box_actor/host.rs Resolved
Comment thread crates/minimald/src/box_actor/host.rs Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 1 of 10 on the runtime's review findings: the coder changed nothing. Revise round 1. The one review thread is invalid, so this round changes no code and runs no tests. The test: lines passed at the earlier round, and the branch head is unchanged by this round.

Review threads the coder judged:

  • 👎 invalid — crates/minimald/src/box_actor/host.rs:1647: The premise that a second stop fails as unknown is wrong. After the StopBox arm evicts the actor, BoxManagerHandle::stop_box_with_grace reads the record (still running) and calls get_session. resolve_session (box_manager.rs:1359-1371) starts a new actor for any record with no live actor, and an evic

@mitodrummer

Copy link
Copy Markdown
Member

/revise Arch-review C1 on 62c29d8: tell an exit from a signal by the reaped reason, not by exit code 125.

hakoniwa reports 125 both for a container ended by a signal and for an entrypoint that exits 125 itself, so code_means_signalled records a real exit 125 as a signal. The architecture (line 495) requires the record to store the entrypoint's exit_code where one exists.

  1. In crates/minimald/src/box_runtime.rs, make the host loop (Host::run → the JoinHandle that stop_box_inner takes from BoxInner::Active) return the reaped ExitReason from self.process.exit_reason() together with its code, e.g. Result<(i32, Option<ExitReason>), io::Error> or a small struct. box_runtime.rs is an accepted out-of-layer file on this PR.
  2. In crates/minimald/src/box_actor/host.rs stop_box_processes(), decide on ExitReason::exit_code: Some(status) gives StopEnding::ExitedFirst { exit_code: status }, and None gives StopEnding::Signalled with the last signal the stop sent. Remove code_means_signalled.
  3. Add a test in crates/minimald/src/box_actor/tests.rs: the entrypoint traps TERM and runs exit 125 inside the grace period. Assert StopEnding::ExitedFirst { exit_code: 125 }, a record with exit_code == Some(125) and signal == None, and an exited event with no signal key.

Leave the PR body's ## Residuals section as it is. Reply on the arch threads at host.rs:1406 and host.rs:1516.

Run the plan's test lines plus cargo nextest run -p minimald stop_.

hakoniwa reports 125 both for a signalled container and for an
entrypoint that exits 125 itself. The host loop now returns the reaped
ExitReason beside its code, and a stop records ExitedFirst when the
reason carries an exit status of its own.

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling

The stop now takes the entrypoint's exit status from the reaped reason, not from the code 125. An entrypoint that exits 125 itself keeps its exit code, as line 495 requires. The stop signals every process in the box's PID namespace, with a 10 s grace and a force path. The stopped record and its events stay readable until reaped. One item stays open: nothing calls the BOX-154 restart flip at daemon start. C1 tracks it under #2393, and the PR can merge with C1 open.

Ruled at 443090e against gominimal/arch@109541a48c31 by claude-opus-5-5.

Comment thread crates/minimald/src/box_manager.rs Resolved

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 2 of 10 on a /revise note, pushed as 443090eeb04b.

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-db35... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling args v0.0.1 (/workbench/crates/args) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-2233... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-6f49... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-cc21... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-463d... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Converted to a draft: something above needs a person before review.

Review threads the coder judged:

  • 👍 valid — crates/minimald/src/box_actor/host.rs: Removed code_means_signalled. The host loop (Host::run) now returns HostExit with the reaped ExitReason, and the stop decides on ExitReason::exit_code.
  • 👍 valid — crates/minimald/src/box_actor/host.rs: The arm now matches the reaped exit_code: Some(status) gives ExitedFirst, None gives Signalled. Added stop_records_an_entrypoint_exit_125_as_its_exit_code, where the entrypoint traps TERM and exits 125.

A stopped session keeps its record and its ending. An entrypoint that exits 125 inside the grace period now has exit_code 125 and no signal on its record, and its exited event carries no signal key. A box that a signal ended still records that signal.

Notes from the agent: C1: the host loop now ends in Host::run, which returns HostExit { code, reason: Option }. Host::spawn and its JoinHandle type use it. Host::mainloop is now a #[cfg(test)] wrapper that returns only the code, so crates/minimald/src/box_runtime/tests.rs did not change. HostExit lives in box_runtime.rs (the accepted out-of-layer file), not in backend.rs. stop_box_processes decides on ExitReason::exit_code: Some(status) gives ExitedFirst, None gives Signalled. code_means_signalled is removed. For the Signalled signal, I kept the signal that the entrypoint ended after. This is the last signal the stop sent before the entrypoint ended. In both existing tests it is equal to the last signal sent. It differs only when the entrypoint ended on SIGTERM and stray processes needed SIGKILL. Then the record keeps SIGTERM. The new test checks the record and the event through the same calls that stop_box_inner makes: Record::set_state(Stopped(ending)) on a record that the daemon created, and stopped_event_data(ending). It does not go through a full daemon stop, because the mock launcher's script (mock.rs, out of layers) cannot trap TERM and exit 125. The PR body's Residuals section is not mine to edit, and I did not touch it.

@minimal-foundry
minimal-foundry Bot marked this pull request as draft October 28, 2026 21:12
@mitodrummer

Copy link
Copy Markdown
Member

/revise One fix on 443090e, from minimal-review (crates/minimald/src/box_runtime/enforcement.rs:834, BoxProcesses::of_container).

If the container supervisor has already exited and been reaped, reading /proc/{root}/ns/pid_for_children fails, namespace becomes None, and the stop still walks and signals from root. If the kernel has reused that pid, SIGTERM or SIGKILL goes to an unrelated process. When the namespace can't be read, treat the box's processes as gone: send no signal, return an empty set, and log at debug that the supervisor was already reaped. Never signal a pid whose namespace you couldn't confirm. Add a test that of_container on a pid with no readable namespace signals nothing. Reply on the minimal-review thread.

Leave the PR body's ## Residuals section as it is. Run the plan's test lines plus cargo nextest run -p minimald stop_ of_container.

A supervisor whose pid namespace cannot be read already exited and was
reaped. Its pid can belong to an unrelated process, so the stop now
treats the box as having no processes instead of walking from that pid.
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 3 of 10 on a /revise note, pushed as d461c0e2055f.

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-28b9... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-5705... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-dcee... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-c9d2... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-6a2c... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Converted to a draft: something above needs a person before review.

Review threads the coder judged:

  • 👍 valid — crates/minimald/src/box_runtime/enforcement.rs:857: of_container now treats an unreadable pid_for_children (a reaped supervisor) as no processes: pids() is empty and signal() sends nothing, with a debug log. Test: of_container_on_a_reaped_supervisor_signals_nothing.

A stopped session keeps its record and ending signal. A stop of a box whose container supervisor was already reaped now signals no process, so a reused pid is never hit.

Notes from the agent: Revise round 3: BoxProcesses now has three scopes (Namespace, Tree, Gone). A namespace read that fails for the supervisor or for the daemon itself gives Gone: pids() is empty, signal() reaches nothing, and a debug log line says the supervisor was already reaped. New test of_container_on_a_reaped_supervisor_signals_nothing covers a reaped child pid and a pid that cannot exist. The PR body Residuals section is untouched (the runner owns the body). just clippy-strict was not run.

The stop tests slept 200 ms and assumed /bin/sh had set its trap by
then. On a loaded runner a SIGTERM can reach the shell first, and the
box ends on SIGTERM. The stand-in box now prints a ready line after it
sets the trap and starts its first child.
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 4 of 10 on a failed check suite, pushed as ea5bad3f9e08.

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-1f75... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-8bae... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-b737... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-80cd... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-f39c... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Converted to a draft: something above needs a person before review.

A stopped session keeps its record and its ending signal: after a stop, the record reads stopped with the signal that ended the entrypoint, and the exited event carries reason stopped and that signal.

Notes from the agent: The directive's CI excerpts do not name the failing test: the tests job excerpt shows only passing lines and cleanup, and ci-linux-native-success only aggregates it. Before the change, the whole minimald suite (1178 tests), minimald-rpc (76), and minimal, minimal-client and minvmd (1556) all passed on this box, and 15 stress iterations of the stop tests under CPU load passed. I found one real race in this task's tests and fixed it: three stop tests slept 200 ms and assumed /bin/sh had installed its trap. On a loaded runner, SIGTERM can reach the shell before the trap, and the box ends on SIGTERM instead of SIGKILL or exit 125. A new helper spawn_stand_in_box now waits for a ready line that the shell prints after it sets the trap and starts its first child. After the fix, 20 stress iterations under CPU load passed. If CI still fails, the failing test name from the full job log is necessary, because this box does not reproduce it.

@mitodrummer
mitodrummer marked this pull request as ready for review October 28, 2026 22:55

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling

The compare since 443090e conforms. The stop now signals nothing when it cannot read the supervisor's PID namespace. Before, it could signal a reused pid. That is fail-closed, and the host kill still ends the box (architecture.md line 495). The test changes keep every assertion. C1 is the open item from the baseline: BoxManager::init does not call the BOX-154 restart flip yet. It is filed as #2393.

Ruled at ea5bad3 against gominimal/arch@109541a48c31 by claude-opus-5-5.

Comment thread crates/minimald/src/box_manager.rs Resolved

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@mitodrummer

Copy link
Copy Markdown
Member

/revise Two fixes on 08c6b46. The first is a regression this branch introduced.

1. minimald exec::tests::a_trickle_reader_fed_one_byte_chunks_is_still_ended fails on every run since d461c0e (a trickle reader fed in one-byte chunks is ended within a window: Elapsed(()), crates/minimald/src/exec/tests.rs:2165). It failed on d461c0e, on its re-run, and on 08c6b46 and its re-run, while main passed it in all six recent ci-linux-native runs. This branch touches no exec file, so the likely cause is the new guards in BoxProcesses::of_container (crates/minimald/src/box_runtime/enforcement.rs): the unreadable-namespace guard in d461c0e and the parent-must-be-the-daemon guard in 08c6b46. Exec teardown, or the test's stand-in, may signal through this path with a root whose parent isn't the daemon, so it now signals nothing and the reader is never ended. Confirm the cause by running the test locally. Then fix it without weakening the guard for a box stop. For example, scope the parent check to the stop's container supervisor, or give the exec path its own confirmed root. Don't change the test's window.

2. minimal-review MEDIUM, crates/minimald/src/box_actor/host.rs:1654 stop_box_inner. Once the host is taken and the processes are killed, a ? on the record read, the record write, the object open or the event write returns early. The record then stays running, and the StopBox arm still ends the actor, so min shows a running box with no process. Make the stopped state the thing that can't be skipped: write the record's stopped state and ending first and return its error, then write the event and log, rather than return, if only the event write fails. If the record write itself fails, keep the actor hosting the box, don't end it, so a retried stop can finish. Add a test with a failing event write: the record still reads stopped. Reply on that thread.

Leave the PR body's ## Residuals section as it is. Run the plan's test lines plus cargo nextest run -p minimald a_trickle_reader stop_.

A stop now sets the record to stopped before anything else can fail.
A failed record write keeps the ending on the actor and returns the
error, and the actor keeps hosting the box, so a retried stop can
write the record. A failed exited-event write is logged, and the stop
still answers with its ending.
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Revise round 4 ran against ci-linux-native-success, tests and left it red; a coder round cannot clear it, a person should look. No round was started for the failed suite on bc304a83f70a.

@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 6 of 10 on a /revise note, pushed as bc304a83f70a.

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-768b... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-a948... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-2b0f... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-7736... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-4cee... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Converted to a draft: something above needs a person before review.

Review threads the coder judged:

  • 👍 valid — crates/minimald/src/box_actor/host.rs: stop_box_inner now writes the stopped record first and returns its error. The actor keeps the ending and stays alive, so a retried stop can write it. A failed exited-event write is only logged. A new test with a failing event write checks that the record reads stopped.

A stopped session keeps its record and ending signal. A stop now writes the stopped record first. If the exited event write fails, the record still reads stopped, and the stop still answers with its ending. If the record write fails, the actor stays, so the box keeps an actor and a retried stop writes the record.

Notes from the agent: Item 1 (a_trickle_reader_fed_one_byte_chunks_is_still_ended): the guess about the guard in BoxProcesses::of_container is wrong, so I did not change the guard. Only the stop path in box_actor/host.rs and the stop tests call of_container. The trickle test is pure tokio: it spawns no process and sends no signal. The exec sources on this branch are identical to origin/main. The test is timing-sensitive. Its stall window counts only the time the pump waits at the bound, so the time it takes depends on how the feeder's and the reader's 50 ms sleeps line up. It passed in the full local minimald run (2.3 s of its 5 s window). In a 30-run stress loop (cargo nextest run -p minimald a_trickle_reader_fed --stress-count 30 --no-fail-fast, exit codes not captured) it failed 2 of 30 on this branch and also 2 of 30 on origin/main, with no extra load. With 4 busy loops on 4 cores it failed sooner (1 of 3). So this is a flake in main's test from #2625. It is not a regression from d461c0e or 08c6b46. A fix belongs in crates/minimald/src/exec.rs or exec/tests.rs, which are outside this task's layers, and the directive forbids a change to the window. I recommend a separate issue for it. Item 2: done in bc304a8. The stopped record is written first, and a failed write returns its error. The ending stays on the actor (new field unrecorded_stop), and the StopBox arm then continues and does not end the actor. A retried stop passes the manager's running check, finds that ending, and writes it. A failed exited-event write or object open is logged as a warning, and the stop returns Ok. The new test stop_with_a_failing_event_write_still_records_stop…[truncated]

@mitodrummer
mitodrummer marked this pull request as ready for review October 29, 2026 01:40

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: CONDITIONS · 1 condition · the full ruling

The new retry path in stop_box_inner can skip the stop sequence. After a failed stopped write, the record still reads running, so an exec can launch a new host. The retried stop then drops that host without SIGTERM, grace or SIGKILL, and records the earlier ending. architecture.md line 495 says a stop signals every process in the box and stores the signal that ended it. Apply C1. Then the change conforms again, as it did on 08c6b46f.

Ruled at 787e34d against gominimal/arch@109541a48c31 by claude-opus-5-5.

Comment thread crates/minimald/src/box_actor/host.rs Resolved
Comment thread crates/minimald/src/box_actor.rs Resolved

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 2 findings, 2 inline.

Panel: 2 of 3 personas ran (correctness, security); did not complete: supply-chain.

Comment thread crates/minimald/src/box_actor/host.rs Resolved
Comment thread crates/minimald/src/box_actor.rs Resolved
A stop that ends the processes and cannot set the record to stopped
keeps the box hosted. launch_host now refuses until a retried stop
writes the record, and a retried stop signals any host it finds. A
stop queued behind another answers with the record's ending. Document
that SIGTERM reaches a PID namespace init only through a handler.

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling

The compare fixes the points of the last ruling. A launch is now refused while a stop's record is unwritten, and a queued stop answers with the recorded ending. One gap remains. A --force stop that arrives during a graceful stop waits up to the grace period, and the new comment in box_actor.rs states that as intended. Design line 495 says --force kills at once. Make the change in C1, or file it as a residual before the merge.

Ruled at 0eecd2c against gominimal/arch@109541a48c31 by claude-opus-5-5.

Comment thread crates/minimald/src/box_actor.rs Resolved

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

Comment thread crates/minimald/src/box_actor.rs Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 7 of 10 on the runtime's review findings, pushed as 0eecd2c963be.

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-4caa... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-2fd5... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-d8ad... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-eab8... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-87a3... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Converted to a draft: something above needs a person before review.

Review threads the coder judged:

  • 👍 valid — crates/minimald/src/box_actor/host.rs: stop_box_inner now signals any host in the slot (SIGTERM, grace, SIGKILL) and records its new ending, even when an earlier stop left an unrecorded ending.
  • 👍 valid — crates/minimald/src/box_actor.rs:1187: launch_host refuses while unrecorded_stop is set, so attach, exec and hooks start nothing before the retried stop. New test stop_with_an_unwritable_record_refuses_launches_until_retried.
  • 👍 valid — PRRT_kwDOPdfcxM6xYvbb: The kernel rule holds (pid_namespaces(7)). BOX-013 asks for SIGTERM, the grace, then SIGKILL, so the behaviour stays. stop_box_processes and BoxProcesses now document that a handler-less init ends on SIGKILL after the grace, recorded as signal 9. (not posted on the thread: not an open thread on the pull request)
  • 👍 valid — crates/minimald/src/box_actor.rs:1197: The serialization is deliberate and is now documented at the StopBox arm. A stop queued behind another now answers with the record's stopped ending, not the 'session ended' error (box_manager stop_box_with_grace).

A stopped session keeps its record, set to stopped, with the signal that ended it. When the record cannot be written, the session starts no new processes until a retried stop writes that record.

Notes from the agent: Revise round 7. The launch refusal reuses AttachError::LaunchRecordUnwritable, because attach.rs is outside the layers. It prints: "starting the session failed: the session's saved state could not be updated: a stop ended this session's processes, and its stopped state is not saved yet". No CLI command stops a box yet, so the message names no next step. Thread 3 was not checked on a real box. This box runs only the mock launcher. The kernel rule in pid_namespaces(7) confirms the premise, so the change documents the behaviour. BOX-013 asks for exactly that order (SIGTERM, grace, SIGKILL). The fix also restores a doc comment that an earlier round left on the wrong test in box_actor/tests.rs.

@minimal-foundry
minimal-foundry Bot marked this pull request as draft October 29, 2026 02:46
@mitodrummer

Copy link
Copy Markdown
Member

/revise Two fixes on 0eecd2c.

1. arch-review C1, crates/minimald/src/box_actor.rs:1183: --force kills at once, even during a graceful stop. The comment there says a forced stop does not cut a graceful stop short, but the design (line 495) says --force kills at once. Have BoxHandle::stop_box(force: true) set a shared force flag (for example an Arc<AtomicBool> or a watch channel the actor holds) before it queues its message. Have the grace loop in stop_box_processes end as soon as that flag is set and send SIGKILL. Replace the comment. Add a test: a graceful stop is in its grace period, a forced stop arrives, and the processes die without waiting out the grace.

2. minimal-review MEDIUM, crates/minimald/src/box_actor.rs:1193: mark the name stopped even when the stop fails after the kill. When stop_box fails after stop_box_inner has killed the processes and called stop_running(false), the arm returns before mark_name_stopped. A shared-address box then keeps answering its hostname for a dead box. Do what the existing Stop arm does (NET-128 fail-closed): call mark_name_stopped once the processes are dead, whether or not the record write succeeded, and keep the actor for the retried stop as it does now. Add a test that the name stops answering after a stop whose record write fails.

Leave the PR body's ## Residuals section as it is. Reply on both threads. Run the plan's test lines plus cargo nextest run -p minimald stop_.

BoxHandle::stop_box(force: true) sets a shared force flag before it
queues its message. A graceful stop in its grace period reads the flag
and sends SIGKILL at once. The StopBox arm also marks the name stopped
when the record write fails after the kill (NET-128 fail-closed).
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 8 of 10 on a /revise note, pushed as b4f415e672c8.

line exit tail
cargo nextest run -p minimald stop_sends_term_then_kill_and_records_exited_stopped_with_signal 0 Applying loadouts: default Running task runtime-implement-test-0 in session task-runtime-implement-test-0-a53c... Compiling paths v0.0.1 (/workbench/crates/paths) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling args v0.0.1 (/workbench/crates/args) Compiling client-config v0.0.1 (/wo
cargo nextest run -p minimald stop_force_kills_at_once 0 Applying loadouts: default Running task runtime-implement-test-1 in session task-runtime-implement-test-1-6ed9... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald restart_sets_orphaned_running_record_stopped_without_signal 0 Applying loadouts: default Running task runtime-implement-test-2 in session task-runtime-implement-test-2-4e43... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald stopped_box_record_readable_until_reaped 0 Applying loadouts: default Running task runtime-implement-test-3 in session task-runtime-implement-test-3-0115... Compiling stdlib v0.0.22 (/workbench/crates/stdlib) Compiling version v0.8.0 (/workbench/crates/version) Compiling decode v0.0.1 (/workbench/crates/decode) Compiling mlog v0.
cargo nextest run -p minimald-rpc stop_box_request_round_trips 0 Applying loadouts: default Running task runtime-implement-test-4 in session task-runtime-implement-test-4-ebef... Compiling args v0.0.1 (/workbench/crates/args) Compiling ot v0.0.1 (/workbench/crates/ot) Compiling paths v0.0.1 (/workbench/crates/paths) Compiling client-config v0.0.1 (/wo

Verify min task run agent-verify passed.

Outside the task's layers::

  • crates/minimald/src/box_actor/handle.rs
  • crates/minimald/src/box_actor/kind.rs
  • crates/minimald/src/box_runtime.rs
  • crates/minimald/src/box_runtime/handle.rs

Converted to a draft: something above needs a person before review.

Review threads the coder judged:

  • 👍 valid — crates/minimald/src/box_actor.rs: BoxHandle::stop_box(force: true) now sets a shared force flag before it queues. The grace loop in stop_box_processes ends on that flag and sends SIGKILL. The comment is replaced, and stop_forced_during_a_graceful_stop_kills_at_once tests it.
  • 👍 valid — crates/minimald/src/box_actor.rs: The StopBox arm now calls mark_name_stopped before the error return. The actor still stays for a retried stop. stop_box_with_an_unwritable_record_still_marks_name_stopped tests it.

A stopped session keeps its record and ending signal. A forced stop now ends a graceful stop's grace period at once with SIGKILL. A stop whose record write fails no longer leaves the box's name answering.

Notes from the agent: Out of layers: crates/minimald/src/box_actor/handle.rs. The force flag must live on BoxHandle and WeakBoxHandle, because the handle sets it while the actor is busy in the grace loop. It is a new fourth tuple field, StopForce = Arc, and the actor reads it through weak_self. The actor clears the flag after a stop has signalled the box, so a later stop starts without it. The new test stop_forced_during_a_graceful_stop_kills_at_once drives stop_box_processes with the shared flag directly. It does not go through the daemon, because the mock shell ends on SIGTERM and so never waits out a grace period. The new test stop_box_with_an_unwritable_record_still_marks_name_stopped fails when the fix is removed (checked). I did not run just clippy-strict. The PR body's Residuals section is not changed.

@mitodrummer
mitodrummer marked this pull request as ready for review October 29, 2026 04:22

@minimal-arch minimal-arch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling

The new commit makes --force end a graceful stop's grace period at once, as architecture.md line 495 requires. A failed record write now also marks the box name stopped, so the name fails closed. BOX-013 and BOX-018 conform. BOX-154 is still not called at daemon start. That work is filed as #2393, and C1 records it. You can merge with C1 open.

Ruled at b4f415e against gominimal/arch@109541a48c31 by claude-opus-5-5.

Comment thread crates/minimald/src/box_manager.rs Resolved

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

Comment thread crates/minimald/src/box_actor.rs Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 9 of 10 on the runtime's review findings: the coder changed nothing. every commit this round put on the branch above b4f415e is a merge of the base branch, so it carries no work of its own

Review threads the coder judged:

  • 👎 invalid — crates/minimald/src/box_manager.rs:1401: This is deliberate, and the finding itself places the work in T6 — Resume a stopped box from its stored spec #2393. Today no actor hosts a stopped box, so calling stop_orphaned_running_records from BoxManager::init now would set every session that a restart resumes to stopped, with no way back. The doc comment and the expect(dead_code) reason re
  • 👎 invalid — crates/minimald/src/box_actor.rs:1691: The flag is already cleared. BoxActor::stop_box_inner in box_actor/host.rs stores false into weak_self.3 (the same StopForce as BoxHandle.3) after every stop path signals, and before write_stopped_record. A forced stop whose record write fails therefore leaves the flag false, and the next graceful s

@mitodrummer mitodrummer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at b4f415e. A stop sends SIGTERM, waits the grace period, then SIGKILL, and --force cuts the grace short through the shared flag. It tells an exit from a signal by the reaped ExitReason, not by code 125. It signals only a supervisor whose parent is the daemon, so a reused pid is never signalled. The stopped record is written first, and a failed write keeps the actor, refuses launches and still marks the name stopped. A cleanup destroy keeps ended records. BOX-154's switch-on at daemon start is residual #2393 (T6).

@mitodrummer
mitodrummer added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 5d339df Oct 29, 2026
36 checks passed
@mitodrummer
mitodrummer deleted the agent/2390-stop-a-box-and-keep-its-record branch October 29, 2026 05:30
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.

T3 — Stop a box and keep its record

1 participant