Repository navigation
fix(box): stop workload descendants and protect state ancestors - #130
Conversation
## Problem Cancelled tool calls can keep running. Surviving children can hold output pipes open after their leader exits. Killing Box on Linux can leave workload descendants running. Mutations of parent directories can move or remove protected Box state. ## Solution Cancel broker calls before shutdown joins them. Stop shell pipeline tasks when the caller cancels or the existing command deadline expires. Stop surviving children before output collection waits for pipe closure. Link the Linux launcher and namespace reaper to their parents. Require a startup handshake before the workload starts. Reuse the ancestor mutation refusal from PR123 and preserve ancestor reads and permitted sibling operations. Keep the new timer behind the native platform guard. WebAssembly retains its existing wait path and the shared cancellation guard. No public interface or policy format changes. Record the shell correction in UPSTREAM.md. ## Tests Targeted all-feature runs passed 103 Linux checks and 87 macOS checks without skips. The full workspace suite was not run. Clippy completed with preexisting warnings. Formatting and diff whitespace checks passed. broker_shutdown_cancels_active_shell_calls_before_joining pins broker shutdown. cancelling_a_host_command_drops_its_spawn_future and cancelling_a_pipeline_drops_every_host_spawn_future pin cancellation. the_command_deadline_stops_every_host_pipeline_stage pins deadlines. captured_exit_stops_descendants_that_hold_the_output_open pins output cleanup. The 13-case box_process_cleanup suite exercises real Box termination, separate tools, local servers, detached descendants, timeout, and preserved exit status. killing_box_stops_children_and_descendants_in_a_separate_session fails when either Linux parent-death link is removed. shell_cannot_mutate_box_state_or_its_ancestors and python_cannot_mutate_box_state_or_its_ancestors fail without the ancestor check. The matching sibling tests preserve permitted file and directory operations. All four protected-state cases pass after restoration. Setup failure and fatal durable-history failure remain component-level evidence. Forced-death cleanup on macOS and deployment-package validation are not covered. Fresh precommit review passed 604 Box library tests and 110 containment library tests. Removing the shell fix made all three host-command regressions fail. The broad deterministic containment suite exceeded its 180-second review limit in existing performance case CN-PF-01. Its verdict remains incomplete. The examples script found no scripted examples. Full WebAssembly compilation was not run. The PR remains a draft for these validation gaps.
|
The adversarial review reproduced two cleanup defects, both fixed in 5b00c69. Queued calls cleared cancellation when first polled. Cancellation now resets before dispatch, and an already-cancelled call cannot execute. The regression buffers a call and disconnect, then verifies bounded shutdown and no marker write. Background commands survived shell destruction or cancellation of Final code inspection found no unresolved defect. Local validation passed 605 Box library tests and 1,970 shell tests, with three existing helper tests ignored. Linux passed 44 broker, five shell cleanup, 13 actual Box cleanup, and four protected-state tests. Final GitHub checks passed on both platforms, and PR #130 is now ready for review. Both automated inline comments are addressed and resolved; dec25a2 documents the spawning-thread lifetime and timeout-output trade-offs. The documented merge order remains #123, then #130. |
|
Assessment: Comment (Draft — not ready to merge) Solid, well-tested work on a genuinely tricky problem. The cancellation path ( Review themes
The honesty in the description about what was and wasn't run is appreciated and makes reviewing much easier. |
|
Assessment: Approve (with one external merge-order dependency) Re-reviewed at Status of prior review points
Only loose end: the fmt/clippy checklist box is still unticked, though the Testing section states both ran clean — worth ticking for consistency. The implementation and its tests are in good shape; my only gating item is the #123 merge ordering the author has already called out. |
|
Assessment: Approve Re-reviewed at Verification
Nicely sequenced landing — the branch now carries only its own process-cleanup and protected-state work. Good to merge from my side. |
|
How is this issue solved for mac? |
|
@siwachabhi, replying to your question about macOS: On macOS, cleanup is best-effort: Box actively stops managed workloads during cancellation, shutdown, or failure, but that cleanup depends on Box remaining alive to execute it. If Box itself is forcibly killed, our current macOS implementation does not guarantee that descendants stop. Linux provides kernel mechanisms that make this guarantee easier to implement. This PR uses those mechanisms for Linux; equivalent macOS protection requires additional design and testing. |
Problem statement: Box could leave programs running after cancellation or failure, and workloads could move or delete directories that contain Box’s protected files.
Solution: This stops leftover programs, even when Box is forcibly killed on Linux, and prevents workloads from changing protected files or directories.
Trade-offs: Timeouts can discard captured output; background programs stop when their shell closes; forced-death cleanup is available only on Linux.
Description
A queued command could clear an existing cancellation request when it first ran. Active pipelines and background commands could survive cancellation or shell closure. Children could also hold output pipes open after their leader exited, which blocked cleanup. Forcibly killing Box on Linux could leave workload descendants running.
Cancellation is now prepared before a call is queued, and an already-cancelled call cannot start. Pipeline stages, background jobs, and pending
waitcalls retain task ownership until completion or cancellation. Background jobs remain available across completed foreground calls while their shell stays open. Output collection stops surviving children after their leader exits.Linux links the launcher and namespace reaper to their parents. A startup handshake prevents workloads from starting without that protection. Integration tests verify the parent-directory protection from #123, including refusal of protected-state mutations and permitted sibling operations.
Commands, configuration, policy actions, and protocol formats are unchanged. Vendored shell corrections are recorded in
crates/shell/UPSTREAM.md.Related Issues
Addresses the Linux parent-death portion of #53. Root execution remains outside this change, so this PR does not close #53.
PR #123 merged into
main. This branch includes that merge, so its diff excludes the ancestor guard and six unit tests already inmain. This PR adds process cleanup and integration tests for protected state. Its merge destination remainsmain.Type of Change
Bug fix
Testing
The final adversarial review found no unresolved code defect after the queued-cancellation and background-job fixes. Each new regression failed before its fix and passed afterward. The queued-call test also verifies that cancellation prevents its marker write. Background tests keep the runtime alive and verify that the surviving shell remains usable.
The five targeted shell tests are included in the macOS shell total. They are not additional passes.
The actual Box tests cover cancellation, failure, timeout, normal exit, and forced Linux termination. They include separate tools, local servers, detached descendants, ignored termination requests, and children retaining output pipes. Protected-state tests cover shell and Python mutations, unchanged files, and successful sibling operations.
Earlier controls removed each Linux parent-death link and observed surviving descendants. Removing ancestor protection caused both protection cases to fail while sibling operations remained permitted. Restoring each fix restored passing tests.
The final Linux build and tests ran as appropriate in separate build and test containers. Test execution used UID 1000 on ARM64 Debian 12. Docker's outer syscall filter and process-filesystem masks were disabled to permit nested containment; Box installed its own controls. Both containers stopped after testing, and no workload survived the process check.
Commands used for local validation:
Linux test binaries ran their complete integration suites and the broker unit filter. Formatting passed. Clippy completed with warnings only on unchanged code.
GitHub checks before the main-branch merge passed, including both workspace test jobs, both deterministic containment suites, lint, and the CI Gate. Adversarial review and automated-comment triage are complete, with both inline discussions resolved and no unresolved code finding. Local validation covers the executable changes in
5b00c69;dec25a2adds only explanatory comments. Merge commit0df60b0brings inmainwithout changing source code. The only file change from the prior PR revision is the signed-test receipt inherited from #123; that receipt is not a claim of fresh validation for this PR. GitHub checks are running again for the merge commit.Setup-failure and fatal-history evidence comes from component tests. A full WebAssembly build, SDK tutorial, and deployment-package validation were not run. Forced-death cleanup on macOS remains outside this change.
just check, orcargo test --workspace --all-features) — GitHub Actions passed both workspace test jobs.cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.