Skip to content

fix(mctx,minimald,sandbox): the in-box min task run uses one sandbox run path for every task, and - #3271

Draft
minimal-foundry[bot] wants to merge 5 commits into
mainfrom
agent/3270-the-in-box-min-task-run-uses-one-sandbox-run-pat
Draft

minimal-foundry[bot] wants to merge 5 commits into
mainfrom
agent/3270-the-in-box-min-task-run-uses-one-sandbox-run-pat

Conversation

@minimal-foundry

Copy link
Copy Markdown
Contributor

Defect

Fixes #3270

  • Epic: none; not charged to an epic
  • Size: M; estimated 140 code, 120 tests
  • May touch:
    • crates/sandbox/src/lib.rs
    • crates/mctx/src/env.rs
    • crates/minimald/src/env.rs
Task marker
### D2983 — The in-box min task run uses one sandbox run path for every task, and run_invocations_in is gone
  kind: task
  size: M
  est: 140 code, 120 tests
  executor: agent
  defect: bug
  layers:
    - sandbox:
      - crates/sandbox/src/lib.rs: adds a working-directory option and a first-invocation stdin hook to the sandbox run, which run_with_cancel applies to each command it spawns
      - crates/mctx/src/env.rs: Env::run takes or sets the start directory and the stdin hook and passes them to Sandbox::run, so callers keep one run path
      test: cargo test -p sandbox run_with_cancel_starts_in_the_given_dir
    - minimald:
      - crates/minimald/src/env.rs: BoxChannel::run_task sends inherit_cwd and forwarded-stdin runs through env.run with StreamWriter, drops run_invocations_in and forward_lines, and StreamWriter::poll_shutdown flushes buf
      test: cargo test -p minimald run_task_relays_exit_on_both_paths
      test: cargo test -p minimald stream_writer_shutdown_flushes_last_line
  proof: An in-box min task run of an inherit_cwd task starts in the caller directory, saves its stdout and stderr files like any other task, and the test sees the relayed exit: line on both paths.

Proof

An in-box min task run of an inherit_cwd task, or a run with forwarded stdin, now goes through env.run like every other task. The task starts in the caller directory (Sandbox::set_run_dir applies the directory to each command), and the sandbox saves its stdout and stderr files. The minimald test sees the relayed exit: line on the path with no stdin and on the forwarded-stdin path. The sandbox test shows a real sandbox run that starts in the given directory, feeds stdin to the first invocation only, and saves the output to the stdout file.

Notes from the agent: Design: sandbox::Sandbox has two new setters, set_run_dir and set_first_stdin(FirstStdin). run_with_cancel applies the run dir to every command and gives only invocation 0 a stdin pipe, which goes to the hook after attach. A hook error kills the child, tears down the network and fails the run. mctx::Env has set_start_dir and set_first_stdin, so Env::run keeps one signature. In minimald, forwarding_hook starts ForwardedStdin and sends stdin:. settle_forwarded then moves the copy out, calls task_ended and maps a hook failure to the old 'min task run could not pass its stdin to the task' error. One behaviour change: task_ended now runs after the whole run, not after the first invocation. A forwarded-stdin read failure during a later invocation of a multi-invocation task can now fail the run. mctx::Error is not Send, so run_task cannot await shutdown after env.run. end_writers calls the same emit_rest that poll_shutdown calls, synchronously. The test serve_task helper now uses forwarding_hook, StreamWriter and settle_forwarded in place of forward_lines. The forward_lines assertion in the old refusal test is removed. Pre-existing failure, not from this change: env::tests::task_entrypoint_carries_env_cwd_and_args fails on this box with my minimald changes stashed too ('not a run request' at the request parse). No scope widening.

Tests

line exit tail
cargo test -p sandbox run_with_cancel_starts_in_the_given_dir 0 running 1 test test tests::run_with_cancel_starts_in_the_given_dir ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 77 filtered out; finished in 0.12s running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.00s warning: unknow
cargo test -p minimald run_task_relays_exit_on_both_paths 0 running 1 test test env::tests::run_task_relays_exit_on_both_paths ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1461 filtered out; finished in 0.01s running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 10 filtered out; finished in 0.00s running 0 t
cargo test -p minimald stream_writer_shutdown_flushes_last_line 0 running 1 test test env::tests::stream_writer_shutdown_flushes_last_line ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1461 filtered out; finished in 0.00s running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 10 filtered out; finished in 0.00s runni

Verify

min task run agent-verify timed out after 1800s, so this PR is a draft.

sccache-gominimal-minimal\u{1f}SCCACHE_ENDPOINT=https://4103a6df4dd77276970745a22603bea9.r2.cloudflarestorage.com\u{1f}SCCACHE_REGION=auto\u{1f}SCCACHE_S3_USE_SSL=true\u{1f}SHELL=/usr/bin/bash\u{1f}SHLVL=2\u{1f}SSL_CERT_DIR=/etc/ssl/certs\u{1f}SSL_CERT_FILE=/etc/ssl/cert.pem\u{1f}XDG_CACHE_HOME=/state/cache\u{1f}XDG_CONFIG_HOME=/home/.config\u{1f}XDG_DATA_HOME=/home/.local/share\u{1f}XDG_RUNTIME_DIR=/run\u{1f}XDG_STATE_HOME=/home/.local/state\u{1e}stdin\n"
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

  Cancelling due to test failure: 3 tests still running
        PASS [   0.364s] ( 662/1627) minimald env::tests::search_finds_known_package
        PASS [   0.243s] ( 663/1627) minimald env::tests::task_entrypoint_relays_the_task_exit_code
        SLOW [> 60.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>120.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>180.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>240.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>300.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>360.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>420.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>480.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>540.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>600.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>660.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>720.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>780.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>840.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>900.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>960.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1020.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1080.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1140.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1200.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1260.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1320.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task
        SLOW [>1380.000s] (─────────) minimald env::tests::minenv_run_forwards_stdin_to_the_task

…first invocation

Sandbox::run_with_cancel applies a run directory to each command it
spawns and hands the first invocation's stdin pipe to a hook. Env
exposes both, so an in-box task run can keep the one run path.
An inherit_cwd task or a run with forwarded stdin went through
run_invocations_in, which skipped the task's saved stdout and stderr
files. run_task now sets the start dir and the stdin hook on the env
and runs through env.run with StreamWriter. run_invocations_in and
forward_lines are gone. StreamWriter::poll_shutdown sends the last
line that has no newline.
@coderabbitai

coderabbitai Bot commented Nov 11, 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: 7d142065-b283-46a8-a22d-8146209e1865

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

@bryan-minimal bryan-minimal 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.

Read at da82580, with a lab run.

What it does holds up. BoxChannel::run_task goes through env.run for an inherit_cwd task and for forwarded stdin alike; the sandbox applies the run dir to each command and gives only the first invocation the stdin pipe; StreamWriter::poll_shutdown flushes what it holds. The two unit tests cover the relayed exit: on both paths and a real sandbox run that starts in the given directory, feeds stdin to the first invocation only and saves the output file.

Lab, Linux, against the current release: the full CI mirror (workspace nextest, the native daemon e2e, clippy, doctests) passes at this tree, and five scenarios that drive an in-box task run pass on Ubuntu 24.04 and Fedora on both sides: the baseline, a task fed stdin through a pipe (zero exit and non-zero), a task after its worker's retirement, and a build whose grandchild keeps the pipe open (the task returns on its own). Nothing regressed.

Two notes, neither against the change:

  • The body's pre-existing failure, env::tests::task_entrypoint_carries_env_cwd_and_args, passes in the full workspace run on Linux here, so it is the agent host's, not the tree's.
  • The one failure the first run here hit was net::classifier::tests::host_ip_lookup_outside_a_steered_box_resolves_real_fence_admits_only_the_box_leaf on Broken pipe, a race in run_nft_script (a refusing stand-in exits before the daemon finishes writing its script, and the write's EPIPE wins over nft's own words). It is unrelated to this PR and fixed separately; the rerun here passed.

One behaviour change the body names is worth a line in the PR description's summary rather than the agent's notes: task_ended now runs after the whole run rather than after the first invocation, so a forwarded-stdin read failure during a later invocation of a multi-invocation task fails the run. That reads as the right order, and it is the kind of change a reader of the history should find at the top.

Approving.

@norrietaylor

Copy link
Copy Markdown
Member

/revise minenv_run_forwards_stdin_to_the_task hangs (verify timed out at 1800s) — the forwarded-stdin path through forwarding_hook/settle_forwarded never completes; fix it so the test finishes. Also check task_entrypoint_carries_env_cwd_and_args ("not a run request") against main without this change; if it passes there, this change broke it.

A host with MINIMAL_OTEL=off made the helper prefix its request with
otel%off%. The test channel then panicked, and the forwarding helper
waited for a reply that never came.
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 1 of 10 on a /revise note, pushed as aaba57911791.

line exit tail
cargo test -p sandbox run_with_cancel_starts_in_the_given_dir 0 running 1 test test tests::run_with_cancel_starts_in_the_given_dir ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 77 filtered out; finished in 0.14s running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.00s warning: unknow
cargo test -p minimald run_task_relays_exit_on_both_paths 0 running 1 test test env::tests::run_task_relays_exit_on_both_paths ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1467 filtered out; finished in 0.01s running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 10 filtered out; finished in 0.00s running 0 t
cargo test -p minimald stream_writer_shutdown_flushes_last_line 0 running 1 test test env::tests::stream_writer_shutdown_flushes_last_line ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1467 filtered out; finished in 0.00s running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 10 filtered out; finished in 0.00s runni

Verify min task run agent-verify passed.

An in-box min task run of an inherit_cwd task, or of a task with forwarded stdin, goes through env.run. The task starts in the caller directory and saves its stdout and stderr files like any other task. run_task_relays_exit_on_both_paths sees the relayed exit: line on both paths. minenv_run_forwards_stdin_to_the_task now finishes in under a second.

Notes from the agent: Revise round 1. The hang was not in forwarding_hook or settle_forwarded. This box exports MINIMAL_OTEL=off, so the min helper prefixed its request with otel%off%. run_request_data then panicked with 'not a run request' in the server thread. After that, the helper waited forever on socat -t 2000000000, which kept the socket half open, so the test hung. task_entrypoint_carries_env_cwd_and_args failed for the same reason. The branch changes neither of these tests, their runners, nor env_min_helper.sh, so main fails the same way on a host with MINIMAL_OTEL=off. I did not run main to confirm this. The fix removes minimald_rpc::trace::OTEL_ENV from the environment in run_min_against and run_min_against_channel, the same way the opt-out test does. That is a test-only change in crates/minimald/src/env.rs (commit 34a556e). One other risk remains: a server-side panic in run_min_against_channel still makes the helper wait forever, and does not fail the test. I did not change that, because it is outside what the note asks. The 17 full-suite failures are in network and namespace tests outside this task's layers. I did not check whether they also fail on main.

This branch has not been deployed

No deployments
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.

D2983 — The in-box min task run uses one sandbox run path for every task, and run_invocations_in is gone

2 participants