Repository navigation
feat(sandbox): sandbox the on_turnend stop gates and fold in the #845 review items (#748) - #859
Merged
Merged
Conversation
…y that says so, pin 125/126/127 and fd 3 (#748) Port the stop-gate sandbox onto the merged verify consumer: the gate goes through command_in_cwd with the launcher report, a non-zero exit with no command exit code from bwrap is a deny naming the sandbox, optional counts as required for the gate, and the doctor toolchain warning covers both consumers with exact text. Reword the launcher-report docs: the status descriptor is closed inside the sandbox with bwrap 0.9.0 and an unparsable report fails closed.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This was referenced Nov 15, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Second slice of #748, part 2 of 2: the
on_turnendstop gates run in thecommandprofile through[sandbox.consumers] turnend = "off" | "optional" | "required"(user config only, defaultoff). Also folds in the three low items from the independent review of #845. Refs #748 (stays open for cron scripts and deliveries). Replaces the stacked branchfeat/748-sandbox-turnend, which was built on the pre-merge verify branch; this one is a fresh branch from develop (#845 merged).Why
A stop gate usually runs code the agent wrote (
cargo test) with no approval and nobody to answer (#676). Opt-in first, as decided on 2026-11-14; sandboxed by default stays a later phase (docs/sandbox-design.md§9.4, not done here).Changes
tole-corehooks.rs:ProcessHook::run_rawgoes throughcommand_in_cwd(Consumer::TurnEnd, ...)and uses the launcher report. A refusal is a deny, never a pass: no working sandbox, a workspace layout the profile refuses (uninitialized or nested submodule, linked worktree inside the workspace), a launcher that cannot be spawned, or a non-zero exit for whichbwrap --json-status-fdreported no exit code of the command, all return exit 126 with a reason, and the turn is denied (3-denial cap, thenStopGateBlocked,tole runexit 6). A launcher failure says "the sandbox failed before or while starting the gate", not a gate verdict. A gate that ran and exited 125, 126 or 127 is its own verdict with its own output. A timeout or an unsandboxed spawn failure keeps the old non-blocking contract (feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) #110); that is unchanged and not a refusal.sandbox/command.rs:Consumer::always_unattendedis now verify AND turnend: a stop gate runs while the model is finishing with nobody to answer, sooptionalcounts asrequiredfor it (an attended chat gets no unsandboxed fallback for a gate;run_commandandjob_startkeep theirs). A stop gate may be a program path (./gate.sh); it must be an executable file and its directory is bound read-only (inside the workspace or a system dir: nothing extra). Doctor: the optional-without-sandbox tail now says "a mission or a stop gate runs unattended"; the toolchain warning and the deterministic-failure note cover verify and turnend, by name.config/mod.rs:turnendkey (validated,config check, user layer only).LauncherReportdoc comment anddocs/sandbox-design.md§9.4 no longer say the command inherits fd 3 and "can only make the report agree". They saybwrapwrites its ownexit-codeline last and the last one wins, that whether the command can reach the descriptor depends on thebwrapversion (0.9.0 closes it inside the sandbox:echo >&3isEBADF), and that a report that cannot be parsed or has noexit-codefails closed (Refused for verify, a deny for a gate), never a pass.doctor_lines_forhad runs of literal spaces where a\continuation was meant. Fixed, and the test asserts the exact text (and that no line contains a run of spaces).Failed(3 strikes,verify_failed), not Refused, and that a command writing forgedexit-codelines to fd 3 cannot change the classification (fail stays fail, pass stays pass); the same for gates.docs/sandbox-design.md§9.4 (call site, unattended rule, refusal and launcher failure for both consumers), threat model, CHANGELOG (new entry for the stop gates; the verify entry now points to it), epics. The README has no sandbox status line that goes stale. CI: theSandbox (bubblewrap)job already runsstopgate_sandbox(5 targets) andverify_sandbox; the new tests live in those targets.Callers and impact (cora is absent here; grep, each checked):
ProcessHook::run_raw: onlyToolRegistry::turnend_denial(registry.rs), which treats any non-zero code as a deny; the tool hooks userun, which is not touched (consumerhook, never wrapped).Consumer::always_unattended:launch_command(the only caller);plan_commanditself still takes the flag, so unit tests pin both.command_in_cwd/Launched:mission.rs(run_verify) andhooks.rs.command_tests.rs,command_sandbox{,_none}.rs,stopgate_sandbox.rs,sandbox_consumers.rs,verify_sandbox.rs,mission_e2e.rs, doctor and config tests.Testing
command_tests.rs): the unattended rule for both consumers, doctor lines with exact text for verify, turnend and both, the launcher report parser.command_sandbox_none.rs,verify_sandbox.rs, real binary + mock provider):turnend = "optional"with nobwrapis refused as a deny even attended (reason namessandbox.consumers.turnend), the gate never ran;requiredexits 6 with the reason.stopgate_sandbox.rs,verify_sandbox.rs;SKIPPED:line when absent, CI'sSandbox (bubblewrap)job runs them withTOLE_REQUIRE_BWRAP=1): a sandboxed gate cannot write.git/.tole, keeps its stdin payload and exit status; a gate exiting 125/126/127 is its own verdict; fake-bwraptests: a launcher failure and an unspawnable launcher are denies that say so, and the gate never ran; verify 125/126/127 isverify_failedand fd 3 writes change nothing.run_rawremoved =>a_stop_gate_whose_launcher_fails_is_a_deny_that_says_sofails;always_unattendedfor turnend removed => the unit test, the doctor test andcommand_sandbox_nonefail.cargo fmt --all --check;cargo clippy --workspace --all-targets --all-features -- -D warnings;cargo clippy -p tole-core -p tole-cli -p tole-tui --no-default-features --all-targets -- -D warnings;cargo testof tole-core and tole-cli (default) and of tole-core, tole-cli, tole-tui with--no-default-features, withTOLE_REQUIRE_BWRAP=1: green, no SKIPPED.scripts/review-local.shcould not run (cora is not installed here: exit 1, not a pass), so I self-reviewedgit diff origin/develop...HEADas an adversarial reviewer, checking: a refusal or a launcher failure cannot reach exit 0 (the report check only runs for a non-zero exit, and exit 0 frombwrapis the command's exit 0);reportisSomeonly when the command is wrapped, so an unsandboxed gate is byte for byte the old path; the gate's stdin payload still reaches the program throughbwrap; the scrub is on thebwrapprocess;run_rawnever callssession_policy(), so--sandbox/--no-sandboxcannot reach a gate; a gate in$HOMEis refused by the grant check; a forged fd 3 line cannot flip a verdict (closed on 0.9.0, last line wins otherwise). Residual, documented: a gate timeout stays non-blocking as before; toolchains outside system dirs are not visible; the security: the command sandbox profile protects .git/hooks and .git/config by leaf mounts only; renaming .git aside bypasses them #849 residuals of thecommandprofile apply to gates too. A fresh independent reviewer will review this PR before merge.