Skip to content

fix(sandbox): a stop gate that times out inside the sandbox is a deny, not a pass (#860) - #861

Merged
ajianaz merged 1 commit into
developfrom
fix/860-sandboxed-gate-timeout-deny
Nov 15, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/860-sandboxed-gate-timeout-deny

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #860: with [sandbox.consumers] turnend on, a stop gate that times out inside the sandbox now DENIES the turn instead of passing it. Refs #748.

Why

A sandboxed gate killed at its 30 s budget made ProcessHook::run_raw return Err, which turnend_denial logs as a non-blocking infrastructure failure (the #110 contract). Code the agent wrote (the tests a gate runs) could therefore time the gate out on purpose and approve the final message. "A refusal is never a pass" covered a missing sandbox, a refused layout and a failing launcher, not a timeout. Reproduced by the reviewer of #859.

Changes

  • tole-core hooks.rs: run_raw hands a failed run to sandboxed_failure(e, sandboxed, timeout). When the gate went through the launcher (report.is_some()): a timeout returns exit 126 with "turnend: the stop gate timed out after Ns inside the sandbox and was killed; a timeout is not a pass"; a spawn failure keeps its existing deny reason; any other failure while running (lost child) is a deny "did not finish inside the sandbox ... not a pass". The turn is denied and it counts toward the 3-denial cap like any denial (turnend_denial treats every non-zero code as a deny). Unsandboxed (turnend = off) the Err is passed through unchanged: the feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) #110 non-blocking contract, byte for byte.
  • Test seam: ProcessHook::with_timeout (#[doc(hidden)], consumes and returns the hook), so no test waits 30 s.
  • Docs: docs/sandbox-design.md §9.4 (timeout is a deny when sandboxed; the feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) #110 note kept for the unsandboxed path; a gate script inside the writable workspace (./gate.sh) can be rewritten by the agent and is outside the profile's protection; tole serve and tole acp bind the process working directory, so a gate there is refused if it is $HOME or /), threat-model row (same), CHANGELOG (a Fixed entry that also carries the API note: Consumer::TurnEnd and hooks::SANDBOX_REFUSED are new public items in tole-core, so an exhaustive match on Consumer needs a new arm; run_raw returns 126 for a refused, unstartable or timed-out sandboxed gate; with_timeout is a hidden test seam).

Callers and impact: ProcessHook::run_raw is called only by ToolRegistry::turnend_denial (tool.rs), which already denies on any non-zero code; the tool hooks use run, untouched. sandboxed_failure is private. No format change.

Testing

  • Unit (hooks.rs): a_sandboxed_gate_that_does_not_finish_is_a_deny (exact timeout text, exit 126, lost-child and spawn-failure reasons; unsandboxed returns the same Err), an_unsandboxed_gate_timeout_stays_a_non_blocking_failure (a real script that sleeps past a 300 ms budget with the consumer off returns Err, as before).
  • Real bubblewrap (stopgate_sandbox.rs, a target of CI's Sandbox (bubblewrap) job, TOLE_REQUIRE_BWRAP=1): a_sandboxed_gate_that_times_out_is_denied_not_passed runs a gate that sleep 30s with a 2 s budget: Ok((126, ...)) with the exact reason, returned well before the sleep ends, the gate did run; a quick gate in the same setup keeps its own verdict.
  • Fail without the fix (mutated by hand, restored): sandboxed_failure treating every run as unsandboxed => the unit test and the real-bwrap test fail; treating no run as unsandboxed => the unsandboxed unit tests fail (the old contract is pinned both ways).
  • Gates on the final head: 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 test of tole-core and tole-cli (default) and of tole-core, tole-cli, tole-tui with --no-default-features, with TOLE_REQUIRE_BWRAP=1: green, no SKIPPED. The attribution grep over origin/develop..HEAD is empty.
  • How it was reviewed: scripts/review-local.sh cannot run here (cora is not installed: exit 1, not a pass), so I self-reviewed git diff origin/develop...HEAD as an adversarial reviewer: the sandboxed branch is chosen by report.is_some(), which is Some only for a wrapped command, so off cannot reach it; every Err of run_with_timeout_stdin is now covered for a wrapped gate (no Err escapes a sandboxed run); the 126 code cannot be confused with a pass; the reason text carries only the timeout and an error string, no gate output or paths; no change to the verify path. A fresh independent reviewer will review this PR before merge.

…, not a pass (#860)

A gate that went through the launcher and was killed at its timeout (or lost
while running) now returns exit 126 with a reason and counts toward the
3-denial cap. The unsandboxed path keeps the #110 non-blocking contract.
Docs: the gate script in the writable workspace is not protected, serve/acp
bind the process cwd, and the new public items are noted for tole-core users.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 015786e into develop Nov 15, 2026
27 checks passed
@ajianaz
ajianaz deleted the fix/860-sandboxed-gate-timeout-deny branch November 20, 2026 08:38
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.

fix(sandbox): a stop gate that times out inside the sandbox passes the turn

2 participants