Skip to content

feat(minimald): relay a task's exit code through the in-box min

Minimal Arch / arch-review failed Nov 4, 2026

CONDITIONS

Governs: architecture.md Runtime line 39 (a task's stdin, stdout and stderr are wired through, and min task run propagates its exit code). Exit codes lines 365, 371 and 377 (4 for not found, 125 for a min-side runtime failure, and run-style commands propagate the program's code). min box run/min task run line 493 (min writes nothing else to stdout, and a pty_enabled entry is refused with exit 2). Design principles 4 and 7 (lines 334 and 337: diagnostics go to stderr, subtree-limited file access, secrets redacted from all output). Output conventions line 384. D9 line 795 (content, such as command arguments, stays behind flags that are off by default in exported telemetry). Running min inside a box line 395 (the grammar behaves exactly as it does on a laptop). The checkout 7a86ec7b has no arch-map.md. No since.diff or findings.json was staged, and no prior ruling covers this PR.

Ruling: the placement is correct. BoxChannel::run_task and the in-box helper own this path, and the task's layers name both files. The core relay conforms to line 377: relayed_exit_code maps Error::Execution to its code, and the helper returns that code. Eight conditions remain. C1: the task cites BOX-015, but spec 29's BOX-015 is about idleness, and BCLI-035 is the requirement this change implements. C2 and C3 (fail closed and the exit-code table): a channel that closes mid-run gives exit 0, and every refusal or runtime failure gives 1, not 4, 2 or 125. C4: the new start-directory notice goes to stdout, which is the task's payload stream. C5: the stdio gaps (stderr merged into stdout, and no stdin) are pre-existing, but nobody owns them. File them as a residual with an issue. C6: an unset inherit variable now drops silently. The laptop path (crates/minimal/src/task.rs:257) refuses, and the in-box path refused before this change. C7: the run request now carries the caller's whole environment, and BoxChannel::run traces the raw line (env.rs:1578), so secret values reach the daemon log. This follows #2960, which applied D9 line 795 and line 384 to the same kind of content. C8: start_dir_in_box calls is_dir() on a path that follows a symlink from the box, so a box on a native host can probe host directories.

Not checked: I could not confirm whether hakoniwa reports a signal-killed child as code 128 + n (the 137 case in the test is synthetic). The hakoniwa source is not in this sandbox, and a build is out of bounds. The new path uses the same status.code that sandbox uses, so the two paths agree. I did not check whether the host client's [vars] ignore policy must apply inside a box. The PR body states that this path does not apply it, and line 395 does not decide whether that policy reaches a nested min. The timeout → 124 case is not addressed by this task.

Conditions

  • C1: Name the requirement this change implements. In crates/minimald/src/env.rs, replace BOX-015 (T62) with BCLI-035 (T62) in the comment in run_task (head line 2238) and in the doc comments of task_entrypoint_relays_the_task_exit_code (line 4233) and task_entrypoint_carries_env_cwd_and_args (line 4293). Spec 29's BOX-015 (docs/specs/29-spec-box-local-first line 140) is "never stop a box for idleness or for the loss of a client", and this change does not touch that. Spec 28's BCLI-035 ("WHEN a run-style command's entrypoint exits THE SYSTEM SHALL propagate its exit code") is the requirement it implements. Amend T62's covers: line in #2953 to BCLI-035 to match.
  • C2: crates/minimald/src/env_min_helper.sh: a run request fails closed. In __min_rpc, when method is run and the read loop ends with no exit: and no error: line, or with an exit: value that is not 0 to 255, return 125, not 0. Today the final if [[ "$relayed" =~ ... ]] (head line 207) falls through, and the function returns 0, so a channel that closes mid-run reports success. Keep the current behaviour for the other methods. Add a case to task_entrypoint_relays_the_task_exit_code where the reply is msg:task output\n, with no terminal line, and assert exit 125.
  • C3: crates/minimald/src/env.rs run_task: when request.relays_exit() is true, end each refusal and each runtime failure with the code from the exit-code table as an exit:<n> line, after the msg: lines that explain it. A missing task (no such task '{task_name}', line 2122) ends with exit:4. The interactive-task refusal (cannot run interactive tasks from within an environment) ends with exit:2. A result for which relayed_exit_code returns None (line 2249, the write_error fallthrough) ends with exit:125. Keep the error: replies for a request from an older helper. Pin 4, 2 and 125 in task_entrypoint_relays_the_task_exit_code.
  • C4: Send the new start-directory notice to stderr, not to stdout. crates/minimald/src/env.rs run_task writes <dir> is not a directory under /workbench, so the task runs in /workbench. as a msg: line (line 2161), and __min_rpc echoes msg: lines to stdout. That puts a diagnostic into the task's payload stream. Add an err: reply tag. The channel writes the notice as err:{notice}, and __min_rpc in env_min_helper.sh prints err: lines with echo "$rest" >&2. Assert in a test that the notice reaches stderr and that stdout stays empty.
  • C5: File an issue for the stdio gaps that remain in in-box min task run, and name it as a residual in the PR body. The issue covers three gaps. The task's stderr reaches the caller's stdout as msg: lines, both through StreamWriter::pair and through the new run_invocations_in (forward_msg_lines(p, &err), line 3081). The task gets no stdin, because __min_rpc pipes only the request line into socat. The task-run notices are not split out. This change leaves these gaps open, and the design requires stdin, stdout and stderr to be wired through. A residual without an issue is not accepted.
  • C6: crates/minimald/src/env.rs inherit_from_caller refuses the run, and does not drop the variable, when the caller does not set a declared inherit variable. Return Err(name) in place of None => false (line 2988). Then run_task writes the refusal that the laptop path writes (crates/minimal/src/task.rs line 257: "task '' declares env_vars.<name> = { inherit = true }, but is not set in this shell; export it before running the task"), followed by exit:1 when the request relays an exit code, or by error: when it does not. The code before this change also refused, through the inheriting environment variable error in crates/mctx/src/env.rs. Update the NOT_SET_BY_CALLER assertion in task_entrypoint_carries_env_cwd_and_args to expect the refusal.
  • C7: crates/minimald/src/env.rs BoxChannel::run: stop logging the raw request line. tracing::trace!("session channel handling: {line}") (line 1578) now records every exported variable of the caller, with its value, because the run request carries the caller's whole environment. That includes client_env secrets and tokens. Log only channel_method of the request (for example tracing::trace!(method = channel_method(request), "session channel handling")), after channel_request_span strips the traceparent. Add a test that a run request with SECRET=v in its environment group puts no v into a captured trace.
  • C8: crates/minimald/src/env.rs start_dir_in_box checks the directory inside the session tree only. working.join(rel_path).is_dir() (line 3020) follows a symlink that the box makes, so a box can learn whether any host path is a directory from whether the notice prints. Canonicalize working.join(rel_path) with canonicalize_utf8 (or std::fs::canonicalize). Accept the directory only when the result is a directory that starts with the canonical working. Otherwise return the notice. Add a case to task_entrypoint_carries_env_cwd_and_args with a symlink under working that points outside it, and expect the notice.

Ruled at 49d9e43 against gominimal/arch@7a86ec7bb3c0 by claude-opus-5-5; arch_rulings 817, job 264fda9a-56f7-4548-9675-473c5a803127.