Skip to content

fix(linux): preserve setup failures through executable launch - #248

Merged
kevin-orellana merged 3 commits into
mainfrom
feature/linux-setup-reporting
Nov 3, 2026
Merged

kevin-orellana merged 3 commits into
mainfrom
feature/linux-setup-reporting

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Box could report that a Linux command started before its startup work finished. A later setup failure could disappear or appear as the command's own exit code. Callers could mistake a Box startup failure for a command result.

Solution. Keep the setup-error connection open until Box attempts to launch the command. Require completion messages from the command's setup process and the Linux supervisor, which waits for the command to exit. Box waits for these messages and connection closure before it reports startup success. Preserve reported setup failures in both execution APIs: the API that collects output and the API that streams it. Interactive commands can still start while they wait for input.

Trade-off. A successful startup result does not prove that the application is ready. If the process dies after setup but before executable launch, it can close the connection without an error message. Box cannot distinguish that final interval from a successful launch. Box and its helper executable must come from the same build.

Description

The status connection carries setup messages from the new processes to Box. The Linux supervisor waits for the workload process to exit. The workload keeps its writing end of the connection until executable launch or failure. The waiting launcher and Linux supervisor release their copies before they wait for process exit. This lets streaming startup complete while the command still waits for input.

Each setup process sends a distinct completion byte: 128 for workload preparation and 6 for Linux supervisor preparation. The reader requires both on Linux. It rejects duplicate, unknown, and legacy status messages. Incomplete setup fails both buffered execution, which collects output, and streaming execution, which delivers output as it arrives. For an agent launcher killed by a signal, Box preserves its signal exit status. Reported setup failures and malformed messages still take precedence.

The helper and Box must come from the same build. The change preserves root-launch policy, filesystem grants, process cleanup, and signal forwarding. The conflict resolution preserves the supervisor memory protection and read-only process filesystem already merged into main.

Related Issues

None.

Type of Change

Bug fix

Testing

Current conflict resolution (b05a5b855a7715ed5386f02b115b6d77adf7e9f7). This commit merges main at ef009143f5ed960d18c145c4fcc7063da1e9ec93. It preserves the supervisor memory guard before the workload fork, descriptor cleanup, and the workload status writer through executable launch. The executed seven-route process-memory probe and root prerequisite remain unchanged from main. supervisor_memory_refusal_reports_apply_before_workload_start verifies that a refused guard reports apply-stage failure before workload output, with a successful launch control.

Current local validation. Amazon Linux 2023 on ARM64, Rust 1.98.1, EXPERIMENTAL_LINUX_SUPPORT=TRUE, four build jobs and four test threads. The tested tree is 1de851bd1c5d4eba7b80cc387dfc188e48e89db2.

Check Result
Format, workspace all-feature build, and configured workspace Clippy Passed. Clippy used the repository's documented vendored-shell allowances.
cargo test --workspace --all-features --no-fail-fast -- --nocapture 4,637 passes, 0 failures, and 17 ignored tests across 142 Rust result summaries; 1,254 seconds. One nested result is excluded. The separate box_library assertion program also completed successfully.
Native setup reporting 12 passed without skips, including the supervisor-guard failure and successful streaming startup.
Namespace module 270 passed.
Box setup and cancellation 14 setup tests and the four-signal cancellation test passed without skips.
Memory probes All three tests passed as the ordinary user and as root. The root run verified host kernel.yama.ptrace_scope=0; it did not skip either memory probe.
Independent integration review No remaining source finding.

The original workspace output audit rejected one avoidable skip: the alias image was absent beside the unit-test binary. After installing the built helper with the repository's CI recipe, the exact existing unit-test binary passed run::broker::aliases::tests::the_installed_image_materializes_when_present, with no skip, and its supplemental output audit passed. The original audit error remains recorded; it is not relabeled as a clean audit. The two expected limits remain: the alias-read assertion is omitted on Linux, while its write assertions run, and the live credential-daemon fixture is absent. No local deterministic or macOS run was added for this conflict repair.

Main later advanced to db481935ec27d183e8b3aa4a87a518c0f55ece21 through PR #217. A read-only merge check was clean, producing tree 28a99494f9b62ecb0603c8ded7ae2254af211eb7. Local tests cover the stated ef00914 integration base; hosted pull-request checks will cover the current-main combination. Current hosted checks. At 2026-11-02T19:38:59.812645+00:00, the continuous integration run is pending. Packaging and change detection passed; substantive Rust, native filesystem, and deterministic jobs remain incomplete. See the CodeQL run for its current results. The automatic review trigger passed its access check, but current-head review remains pending. No environment approval is pending for continuous integration or the review trigger. There is no current-head automated assessment yet. The latest earlier assessment below covers d806fc2 only. Hosted validation remains pending.

Prior hosted checks. The continuous integration gate passed for d806fc2ebd3ae07825248edb937a0f6169f74829 on November 1, 2026. This status is separate from the local and historical test results below. The optional Verdict job skipped and provides no coverage.

Local and historical validation. The full workspace results below cover 4aedf8b. Later focused checks and combined testing appear separately.

Validation used non-root Amazon Linux 2023 on ARM64, Linux 6.12, and Rust 1.98.1. Exact kernel revisions are recorded per run.
EXPERIMENTAL_LINUX_SUPPORT=TRUE enabled the Linux paths; tests used four threads.
The final source preserves the current-main executable lookup change.

Check Result
Format, all-feature build, and workspace Clippy Passed. Clippy used the documented vendored-shell allowances.
bash scripts/test-all.sh rust at 4aedf8b 4,607 outer-suite passes, 0 failures, and 17 ignored entries; completed in 1,384 seconds.
Native setup-reporting regressions 11 passed, 0 failed, 0 ignored or skipped.
bash test-integ/run.sh --locked 124 passed, 0 failed or errored, and 9 declared macOS-only skips. All 133 expected cases were recorded.

The review follow-up passed all 119 tests in the Box containment module and all 11 native setup tests. Format, all-feature build, and strict Clippy also passed. Namespace tests now probe host support, and fault checks first run a clean positive control. A syscall filter that refuses namespace creation produced 11 native and two boundary skips, with explicit messages; those runs establish skip behavior only.

The native suite checks six induced setup failures, abrupt launcher death, death during filter installation, refused status closure, buffered exit codes, and interactive streaming startup.
The Box tests exercise the actual buffered and streaming callers.
An independent baseline run failed 10 of the 11 native regressions; its abrupt-launcher-death case passed as a control.
Restoring the fix passed all 11.

Tests also ran with deliberate defects. Each affected regression failed, and the restored code passed.
Restoring premature success fails setup_completion_does_not_hide_a_later_exec_failure.
Ignoring malformed bytes fails setup_completion_rejects_duplicate_or_unknown_markers; the restored reader passes.
Disabling the signal-exit correction fails cancelling_before_the_launch_gate_preserves_the_signal_exit; restoring it passes. This test kills the real gated helper with four signals and confirms that no workload output appears.

The log contains 4,608 reported passes across 142 result summaries. One nested rerun is already counted by its parent suite; the table excludes it.
Ignored entries include six child-only helpers that parent tests run separately, live fixtures, long performance tests, known upstream defects, and one documentation example.
Four runtime messages identify remaining coverage limits.
The installed alias image and cardinality probe were absent. The Linux alias-read assertion did not run, and no credential daemon was available.
The alias-write assertions still ran. None of these messages came from the setup-reporting suite.

The integration runner reports an unknown commit for the copied binaries.
The evidence records their SHA-256 hashes and the final source manifest separately.
The reviewed earlier source also passed a no-default-features build.
The example command found no scripted examples; the manual SDK tutorial was not run.
No macOS build or execution ran locally. All hosted checks passed at 4aedf8b, including Linux and macOS unit and deterministic tests. The prior head d806fc2 also passed the hosted continuous integration gate on November 1, 2026.
Combined validation with PR #243 at be5ab399 and this PR at d806fc2 passed in a separate checkout: 14 Box setup tests, one four-signal cancellation test, 12 native setup tests, and 124 deterministic cases. Nine declared macOS-only cases skipped; all 133 expected cases were recorded. The tested conflict resolution keeps supervisor hardening before the workload fork and preserves the setup writer through executable launch. The current diff keeps the setup-reporting scope and adds a failure-reporting regression for the existing supervisor memory guard.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

The lint command uses the vendored-shell allowances required by CONTRIBUTING.md and the just clippy recipe.
The host does not have just, so the equivalent commands ran directly.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

AI assistance: Codex implemented, tested, and reviewed this change under the author's direction.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

Linux startup could report success before privilege, filter, environment, and executable preparation finished.
Late setup failures could disappear or look like workload exit codes.
The native setup-reporting suite exposes ten failures on the previous implementation.
Its abrupt-launcher-death case remains a passing control.

## Solution

Keep the setup-status writer with the workload through preparation and executable launch.
The launcher and namespace supervisor close their copies before waiting for workload exit.
Require workload marker 128, Linux supervisor marker 6, and channel closure before reporting completed setup.
Retain failure stages 1 through 5, including an executable failure after marker 128.
Reject incomplete and incompatible status messages.
Update the helper protocol documentation and retain current-main executable lookup.

This reports completed preparation, not application readiness.
Abrupt death after both preparation markers but before executable launch remains indistinguishable from successful launch.
The helper and Box must come from the same build.
Root-launch policy, grants, signal forwarding, and process cleanup do not change.

## Tests

Native Amazon Linux 2023 on ARM64, Rust 1.98.1.

setup_reporting_linux passes all eleven cases after the fix.
bounding_failure_reports_apply, capability_failure_reports_apply, privilege_failure_reports_apply,
filter_failure_reports_apply, environment_failure_reports_decode, and executable_failure_reports_exec
verify late failure stages and absent workload output.
abrupt_launcher_death_has_no_setup_completion and
abrupt_death_during_filter_installation_has_no_setup_completion cover premature channel closure.
an_unclosed_supervisor_writer_reports_failure_without_waiting_for_workload_exit covers a retained writer.
buffered_success_keeps_ordinary_workload_exit_codes preserves codes 0, 3, 4, 5, and 42.
streaming_setup_finishes_before_workload_exit covers an interactive workload waiting for input.

setup_reporting_preserves_late_failures_in_buffered_and_streaming_execution and
setup_reporting_preserves_successful_buffered_and_streaming_execution exercise the real Box callers.
setup_completion_does_not_hide_a_later_exec_failure fails with premature success restored.
setup_completion_rejects_duplicate_or_unknown_markers fails when malformed bytes are ignored.
The restored reader passes both tests.

Final format, all-feature build, and workspace Clippy passed.
Clippy used the documented vendored-shell allowances; the host has no just installation.
The full Rust workspace gate passed in 1,384 seconds.
Its 142 result summaries, including child reruns, record 4,608 passes, zero failures, and 17 ignored entries.
Four runtime coverage limits remain: missing installed alias image, absent cardinality probe,
unrun Linux alias-read assertion, and missing credential daemon.
These limits are outside the setup-reporting suite.
The deterministic integration gate recorded all 133 expected cases: 124 passed, nine macOS-only skips, and no failures or errors.
An independent feature-critic review found no remaining source issue.
The original reviewed source also passed a no-default-features build.

No macOS build or execution ran locally; hosted checks remain required before merge.
The example command found no scripted examples; the manual SDK tutorial was not run.
Adjacent supervisor-isolation validation remains separate because no candidate was available.
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The protocol change looks correct for each setup failure, success, and version-skew case I traced. I left two non-blocking comments. One: a run cancelled during startup is now reported as a protocol error. Two: the native suite has no host-capability probe, so some tests pass without testing anything.

Assumptions and rules checked that held
  • Reader at 4aedf8b: 128,6→EOF is success; 128,5 is an exec failure; 4 before 128 is a target-environment failure; legacy 0, duplicate 128/6, and unknown bytes are refused; an x86_64 PlatformUnsupported is reported as Apply. I ran cargo test -p strands-box --all-features --lib with the reader tests: 6/6 passed on x86_64.
  • Writer lifetime: the launcher closes its copy after confirm_parent_death. The reaper closes its copy after it drops authority and writes 6. The workload inherits the writer through keep and closes it via FD_CLOEXEC at exec. So a long-lived streaming leaf does not keep the reader blocked.
  • The relay-failure path (if let Ok(Some(stage))) and the Completion::Hosted path work as before.
  • containment/AGENTS.md "post-fork code is syscall-only": held. close_confirm_descriptor and the new write_confirm_byte calls do not allocate.
  • containment/AGENTS.md "one verb" Containment::apply(..., confirm_fd, ...): the signature is unchanged and no status flag or second entry point was added.
  • Root AGENTS.md frozen surfaces: no CLI, box.toml, record, or pub use change. The status bytes are internal between Box and helper builds from the same release.
  • Gating to aarch64 matches the facade: Linux containment runs only on aarch64.

The documented trade-off (an abrupt death between the marker and exec cannot be told apart from a successful exec) is stated clearly in both READMEs.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review of d806fc2)

d806fc2 fixes both findings from the review of 4aedf8b. I found no new issues in this commit.

What I checked in this commit, and what held
  • Cancellation during startup: the new contained_exit_code returns the signal exit status only when there is SetupIncomplete and the leader ended by a signal. The Linux launcher keeps the default signal handling, so the group SIGTERM from Box ends it with a signal status (128+n).
  • The narrower branch stays narrow: if the workload dies during seccomp install, the reaper turns that into a normal exit 159. That still reaches SetupIncomplete and is reported as an error. A reported stage byte or a malformed marker still takes priority over a signal status.
  • Buffered and streaming leaves still report SetupIncomplete as an error, which matches docs/design/binaries.md.
  • CONTRIBUTING.md "skips instead of failing": the native suite and the two boundary.rs tests now check the host first and print skipping: when it can't build a namespace. check_failure now runs a [6, 128] success control first, so an Apply byte can no longer pass the fault tests on its own.
  • Tests run on x86_64 Linux: 9 status-reader/exit-code unit tests in strands-box --lib all pass. That includes cancelling_before_the_launch_gate_preserves_the_signal_exit, which runs against the real trampoline binary. The aarch64 native tests could not run on this host.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review of b05a5b8, the merge of main into d806fc2)

The merge keeps the setup-status protocol intact. It also brings main's new reaper failure under that protocol. I found no new issues.

What I checked in the merge, and what held
  • New reaper exit from fix: harden Linux namespace supervisor memory #243: if refuse_process_memory_access fails, the reaper now writes APPLY_FAILURE_BYTE before _exit(127). This happens before the workload fork, so no 128 marker is sent and the run is reported as an Apply failure.
  • The new fault test: supervisor_memory_refusal_reports_apply_before_workload_start uses check_failure, which runs the [6, 128] success control first. The test then asserts byte 3, no 128, and no workload output. On the trampoline path, authority.rs is the only caller of PR_SET_DUMPABLE, so the fault cannot hit a different step.
  • The legacy protocol from main is dropped: EXEC_CONFIRM_BYTE (0) and close_confirm_writer from main are gone, and the PR's protocol is kept. keep still includes confirm_fd (mod.rs:212), so the reaper's descriptor sweep keeps the writer open until it writes 6. The reworked test from main now asserts that the workload holds the writer with FD_CLOEXEC, which matches the PR's design.
  • Terminal and console filters from fix(containment): restrict Linux terminal and console controls #255: they are installed in the workload's own apply. If they fail, the error returns through apply, and the trampoline reports it as an Apply failure. The merge adds no new _exit path that skips a status byte.
  • containment/AGENTS.md "post-fork code is syscall-only": the new reaper branch adds only write_confirm_byte. Its eprintln! was already there on main.
  • Tests run on x86_64 Linux: the 9 status-reader/exit-code unit tests in strands-box --lib still pass at b05a5b8. I could not build or run the aarch64 native suite here.

@kevin-orellana
kevin-orellana merged commit d821a40 into main Nov 3, 2026
24 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-setup-reporting branch November 3, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants