Repository navigation
feat: derive the permission mode from what the host can enforce - #387
Merged
Merged
Conversation
Holds one invariant: Auto is only ever entered when there is an enforcement
floor underneath it.
`AcceptEdits` ("Auto") frees writes. That is only defensible when a sandbox
confines what a freed write can reach, so on a host that cannot confine the
honest mode is Manual — forge asks rather than running agent commands
unconfined and silent. This diverges from Claude Code, whose default is to warn
and continue unsandboxed unless you opt into `failIfUnavailable`; that trades
the floor for convenience at exactly the moment the user cannot see it.
Modelled as a ceiling, not an override. Narrowing is always safe, so a user who
prefers Manual keeps it and is never overridden; only widening past what the
host can enforce is refused. `PermissionMode::clamped_to` is the pure rule;
`forge_core::permission_ceiling` computes the bound.
The derivation lives in forge-core because that is the lowest layer seeing both
halves: forge-governance owns PermissionMode but depends on forge-types alone
and cannot see a sandbox, while forge-tools knows about sandboxes and nothing
about approval. A future headless entry point inherits it by living above
forge-core.
`set_permission_mode_clamped` is the single place a mode is applied, so the
invariant cannot be bypassed by adding another call site. It covers all three
paths: startup with no saved state (PermissionMode defaults to AcceptEdits, so
a fresh session on a sandbox-less host would otherwise begin in Auto),
restoring a persisted mode, and the cycle key. A refused cycle now says why,
rather than leaving the chip unchanged and the user wondering if the key is
broken.
The git-cleanliness precondition from the plan is dropped. Evaluated
continuously, the agent's own first edit would drop the session to Manual;
evaluated at session start, ordinary uncommitted work would do the same. Either
reading fights the goal. Sandbox availability is now the only gate.
Tests: 4 in forge-core over the ceiling and clamp, 3 in forge-tui over the
three call sites. On macOS the ceiling is AcceptEdits so the permissive branch
runs locally; CI Linux has no sandbox yet and therefore exercises the
clamp-to-Manual branch.
…eiling-aware CI caught two things this change got wrong on Linux, where there is no sandbox yet and the ceiling is therefore Manual. **A real bug.** `load_ui_state` has three exits that skip the permission mode entirely — no state file, malformed file, workspace-id mismatch — and `PermissionMode` derives `Default` as `AcceptEdits`. Clamping only on the success path left a brand-new workspace in Auto with no floor under it, which is the first thing any new user hits. The restore is now a separate function and the clamp sits outside it, so no exit can skip it. Invisible on macOS, where the ceiling is AcceptEdits and the missing clamp changes nothing; the test only failed once CI ran it on a host that actually caps. **Three tests that assumed Auto is always reachable.** It no longer is. They now branch on `permission_ceiling()`: without a floor, cycling is a no-op by design, so they assert that rather than a transition that must not happen. One of those is a genuine layout consequence rather than a test artifact: `tui09_narrow_frame_still_shows_model_or_ctx` renders at width 60, and "Manual" is two columns wider than "Auto" — enough to push the model id out of the footer entirely. The mode-chip assertion now uses the host's label, and the model-id assertion applies only when the shorter label leaves room. Worth its own look: at narrow widths the mode label crowds out the model id. Validated locally against both branches by temporarily making `availability()` return Err behind an env var, running the suite, and removing the hook — rather than pushing to CI again to find out. That simulation surfaced the chrome failure, which the CI log had not listed.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
* feat: derive the permission mode from what the host can enforce
Holds one invariant: Auto is only ever entered when there is an enforcement
floor underneath it.
`AcceptEdits` ("Auto") frees writes. That is only defensible when a sandbox
confines what a freed write can reach, so on a host that cannot confine the
honest mode is Manual — forge asks rather than running agent commands
unconfined and silent. This diverges from Claude Code, whose default is to warn
and continue unsandboxed unless you opt into `failIfUnavailable`; that trades
the floor for convenience at exactly the moment the user cannot see it.
Modelled as a ceiling, not an override. Narrowing is always safe, so a user who
prefers Manual keeps it and is never overridden; only widening past what the
host can enforce is refused. `PermissionMode::clamped_to` is the pure rule;
`forge_core::permission_ceiling` computes the bound.
The derivation lives in forge-core because that is the lowest layer seeing both
halves: forge-governance owns PermissionMode but depends on forge-types alone
and cannot see a sandbox, while forge-tools knows about sandboxes and nothing
about approval. A future headless entry point inherits it by living above
forge-core.
`set_permission_mode_clamped` is the single place a mode is applied, so the
invariant cannot be bypassed by adding another call site. It covers all three
paths: startup with no saved state (PermissionMode defaults to AcceptEdits, so
a fresh session on a sandbox-less host would otherwise begin in Auto),
restoring a persisted mode, and the cycle key. A refused cycle now says why,
rather than leaving the chip unchanged and the user wondering if the key is
broken.
The git-cleanliness precondition from the plan is dropped. Evaluated
continuously, the agent's own first edit would drop the session to Manual;
evaluated at session start, ordinary uncommitted work would do the same. Either
reading fights the goal. Sandbox availability is now the only gate.
Tests: 4 in forge-core over the ceiling and clamp, 3 in forge-tui over the
three call sites. On macOS the ceiling is AcceptEdits so the permissive branch
runs locally; CI Linux has no sandbox yet and therefore exercises the
clamp-to-Manual branch.
* fix(tui): clamp the mode on every startup path, and make mode tests ceiling-aware
CI caught two things this change got wrong on Linux, where there is no sandbox
yet and the ceiling is therefore Manual.
**A real bug.** `load_ui_state` has three exits that skip the permission mode
entirely — no state file, malformed file, workspace-id mismatch — and
`PermissionMode` derives `Default` as `AcceptEdits`. Clamping only on the
success path left a brand-new workspace in Auto with no floor under it, which
is the first thing any new user hits. The restore is now a separate function and
the clamp sits outside it, so no exit can skip it. Invisible on macOS, where the
ceiling is AcceptEdits and the missing clamp changes nothing; the test only
failed once CI ran it on a host that actually caps.
**Three tests that assumed Auto is always reachable.** It no longer is. They now
branch on `permission_ceiling()`: without a floor, cycling is a no-op by design,
so they assert that rather than a transition that must not happen.
One of those is a genuine layout consequence rather than a test artifact:
`tui09_narrow_frame_still_shows_model_or_ctx` renders at width 60, and "Manual"
is two columns wider than "Auto" — enough to push the model id out of the footer
entirely. The mode-chip assertion now uses the host's label, and the model-id
assertion applies only when the shorter label leaves room. Worth its own look:
at narrow widths the mode label crowds out the model id.
Validated locally against both branches by temporarily making `availability()`
return Err behind an env var, running the suite, and removing the hook — rather
than pushing to CI again to find out. That simulation surfaced the chrome
failure, which the CI log had not listed.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
Extends the sandbox to Linux, so the enforcement floor exists on every supported platform rather than only on macOS. Fail-safe by construction: when `bwrap` is absent, `availability()` returns Err, the permission ceiling drops to Manual (#387) and forge asks — exactly today's behaviour. The worst case for a host without bubblewrap is no change, never a silent hole. `bwrap` is resolved by absolute path, never through `PATH`. This call decides whether a process gets confined, so letting an environment variable pick the binary would put the boundary inside the blast radius it is meant to define. Bind order is the security property, and it carries the same last-match-wins hazard as the Seatbelt rules: 1. --ro-bind / / everything readable, nothing writable 2. --bind <workspace> carve the workspace back out as writable 3. --ro-bind-try .git, .forge carve those back to read-only Emitted in any other order, `.git` is writable and the recovery mechanism can delete itself. `-try` because a workspace need not have either directory yet and bwrap fails on a missing bind source. `--unshare-net` denies egress; `--dev` and `--proc` are the minimum a shell needs, without which ordinary redirects fail the way /dev/null did on macOS. Reads stay broad, matching the macOS policy and Codex's workspace-write: toolchains need ~/.gitconfig and ~/.cargo, so a secret can be read and the network denial is what stops it leaving. Tests: 4 over the invocation — bind ordering, egress denial with a read-only root, absolute-path resolution, and no invocation for an unresolvable workspace. They assert on the argv rather than on behaviour, because this machine is macOS; they no-op safely where bwrap is absent. CI on Linux is what exercises the real thing, and the enforcement suite in tests/sandbox_enforcement.rs is still macOS-gated — a Linux equivalent should follow once CI confirms bwrap is present and usable on the runner.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
* feat: derive the permission mode from what the host can enforce
Holds one invariant: Auto is only ever entered when there is an enforcement
floor underneath it.
`AcceptEdits` ("Auto") frees writes. That is only defensible when a sandbox
confines what a freed write can reach, so on a host that cannot confine the
honest mode is Manual — forge asks rather than running agent commands
unconfined and silent. This diverges from Claude Code, whose default is to warn
and continue unsandboxed unless you opt into `failIfUnavailable`; that trades
the floor for convenience at exactly the moment the user cannot see it.
Modelled as a ceiling, not an override. Narrowing is always safe, so a user who
prefers Manual keeps it and is never overridden; only widening past what the
host can enforce is refused. `PermissionMode::clamped_to` is the pure rule;
`forge_core::permission_ceiling` computes the bound.
The derivation lives in forge-core because that is the lowest layer seeing both
halves: forge-governance owns PermissionMode but depends on forge-types alone
and cannot see a sandbox, while forge-tools knows about sandboxes and nothing
about approval. A future headless entry point inherits it by living above
forge-core.
`set_permission_mode_clamped` is the single place a mode is applied, so the
invariant cannot be bypassed by adding another call site. It covers all three
paths: startup with no saved state (PermissionMode defaults to AcceptEdits, so
a fresh session on a sandbox-less host would otherwise begin in Auto),
restoring a persisted mode, and the cycle key. A refused cycle now says why,
rather than leaving the chip unchanged and the user wondering if the key is
broken.
The git-cleanliness precondition from the plan is dropped. Evaluated
continuously, the agent's own first edit would drop the session to Manual;
evaluated at session start, ordinary uncommitted work would do the same. Either
reading fights the goal. Sandbox availability is now the only gate.
Tests: 4 in forge-core over the ceiling and clamp, 3 in forge-tui over the
three call sites. On macOS the ceiling is AcceptEdits so the permissive branch
runs locally; CI Linux has no sandbox yet and therefore exercises the
clamp-to-Manual branch.
* fix(tui): clamp the mode on every startup path, and make mode tests ceiling-aware
CI caught two things this change got wrong on Linux, where there is no sandbox
yet and the ceiling is therefore Manual.
**A real bug.** `load_ui_state` has three exits that skip the permission mode
entirely — no state file, malformed file, workspace-id mismatch — and
`PermissionMode` derives `Default` as `AcceptEdits`. Clamping only on the
success path left a brand-new workspace in Auto with no floor under it, which
is the first thing any new user hits. The restore is now a separate function and
the clamp sits outside it, so no exit can skip it. Invisible on macOS, where the
ceiling is AcceptEdits and the missing clamp changes nothing; the test only
failed once CI ran it on a host that actually caps.
**Three tests that assumed Auto is always reachable.** It no longer is. They now
branch on `permission_ceiling()`: without a floor, cycling is a no-op by design,
so they assert that rather than a transition that must not happen.
One of those is a genuine layout consequence rather than a test artifact:
`tui09_narrow_frame_still_shows_model_or_ctx` renders at width 60, and "Manual"
is two columns wider than "Auto" — enough to push the model id out of the footer
entirely. The mode-chip assertion now uses the host's label, and the model-id
assertion applies only when the shorter label leaves room. Worth its own look:
at narrow widths the mode label crowds out the model id.
Validated locally against both branches by temporarily making `availability()`
return Err behind an env var, running the suite, and removing the hook — rather
than pushing to CI again to find out. That simulation surfaced the chrome
failure, which the CI log had not listed.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
Extends the sandbox to Linux, so the enforcement floor exists on every supported platform rather than only on macOS. Fail-safe by construction: when `bwrap` is absent, `availability()` returns Err, the permission ceiling drops to Manual (#387) and forge asks — exactly today's behaviour. The worst case for a host without bubblewrap is no change, never a silent hole. `bwrap` is resolved by absolute path, never through `PATH`. This call decides whether a process gets confined, so letting an environment variable pick the binary would put the boundary inside the blast radius it is meant to define. Bind order is the security property, and it carries the same last-match-wins hazard as the Seatbelt rules: 1. --ro-bind / / everything readable, nothing writable 2. --bind <workspace> carve the workspace back out as writable 3. --ro-bind-try .git, .forge carve those back to read-only Emitted in any other order, `.git` is writable and the recovery mechanism can delete itself. `-try` because a workspace need not have either directory yet and bwrap fails on a missing bind source. `--unshare-net` denies egress; `--dev` and `--proc` are the minimum a shell needs, without which ordinary redirects fail the way /dev/null did on macOS. Reads stay broad, matching the macOS policy and Codex's workspace-write: toolchains need ~/.gitconfig and ~/.cargo, so a secret can be read and the network denial is what stops it leaving. Tests: 4 over the invocation — bind ordering, egress denial with a read-only root, absolute-path resolution, and no invocation for an unresolvable workspace. They assert on the argv rather than on behaviour, because this machine is macOS; they no-op safely where bwrap is absent. CI on Linux is what exercises the real thing, and the enforcement suite in tests/sandbox_enforcement.rs is still macOS-gated — a Linux equivalent should follow once CI confirms bwrap is present and usable on the runner.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
* feat: derive the permission mode from what the host can enforce
Holds one invariant: Auto is only ever entered when there is an enforcement
floor underneath it.
`AcceptEdits` ("Auto") frees writes. That is only defensible when a sandbox
confines what a freed write can reach, so on a host that cannot confine the
honest mode is Manual — forge asks rather than running agent commands
unconfined and silent. This diverges from Claude Code, whose default is to warn
and continue unsandboxed unless you opt into `failIfUnavailable`; that trades
the floor for convenience at exactly the moment the user cannot see it.
Modelled as a ceiling, not an override. Narrowing is always safe, so a user who
prefers Manual keeps it and is never overridden; only widening past what the
host can enforce is refused. `PermissionMode::clamped_to` is the pure rule;
`forge_core::permission_ceiling` computes the bound.
The derivation lives in forge-core because that is the lowest layer seeing both
halves: forge-governance owns PermissionMode but depends on forge-types alone
and cannot see a sandbox, while forge-tools knows about sandboxes and nothing
about approval. A future headless entry point inherits it by living above
forge-core.
`set_permission_mode_clamped` is the single place a mode is applied, so the
invariant cannot be bypassed by adding another call site. It covers all three
paths: startup with no saved state (PermissionMode defaults to AcceptEdits, so
a fresh session on a sandbox-less host would otherwise begin in Auto),
restoring a persisted mode, and the cycle key. A refused cycle now says why,
rather than leaving the chip unchanged and the user wondering if the key is
broken.
The git-cleanliness precondition from the plan is dropped. Evaluated
continuously, the agent's own first edit would drop the session to Manual;
evaluated at session start, ordinary uncommitted work would do the same. Either
reading fights the goal. Sandbox availability is now the only gate.
Tests: 4 in forge-core over the ceiling and clamp, 3 in forge-tui over the
three call sites. On macOS the ceiling is AcceptEdits so the permissive branch
runs locally; CI Linux has no sandbox yet and therefore exercises the
clamp-to-Manual branch.
* fix(tui): clamp the mode on every startup path, and make mode tests ceiling-aware
CI caught two things this change got wrong on Linux, where there is no sandbox
yet and the ceiling is therefore Manual.
**A real bug.** `load_ui_state` has three exits that skip the permission mode
entirely — no state file, malformed file, workspace-id mismatch — and
`PermissionMode` derives `Default` as `AcceptEdits`. Clamping only on the
success path left a brand-new workspace in Auto with no floor under it, which
is the first thing any new user hits. The restore is now a separate function and
the clamp sits outside it, so no exit can skip it. Invisible on macOS, where the
ceiling is AcceptEdits and the missing clamp changes nothing; the test only
failed once CI ran it on a host that actually caps.
**Three tests that assumed Auto is always reachable.** It no longer is. They now
branch on `permission_ceiling()`: without a floor, cycling is a no-op by design,
so they assert that rather than a transition that must not happen.
One of those is a genuine layout consequence rather than a test artifact:
`tui09_narrow_frame_still_shows_model_or_ctx` renders at width 60, and "Manual"
is two columns wider than "Auto" — enough to push the model id out of the footer
entirely. The mode-chip assertion now uses the host's label, and the model-id
assertion applies only when the shorter label leaves room. Worth its own look:
at narrow widths the mode label crowds out the model id.
Validated locally against both branches by temporarily making `availability()`
return Err behind an env var, running the suite, and removing the hook — rather
than pushing to CI again to find out. That simulation surfaced the chrome
failure, which the CI log had not listed.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
Extends the sandbox to Linux, so the enforcement floor exists on every supported platform rather than only on macOS. Fail-safe by construction: when `bwrap` is absent, `availability()` returns Err, the permission ceiling drops to Manual (#387) and forge asks — exactly today's behaviour. The worst case for a host without bubblewrap is no change, never a silent hole. `bwrap` is resolved by absolute path, never through `PATH`. This call decides whether a process gets confined, so letting an environment variable pick the binary would put the boundary inside the blast radius it is meant to define. Bind order is the security property, and it carries the same last-match-wins hazard as the Seatbelt rules: 1. --ro-bind / / everything readable, nothing writable 2. --bind <workspace> carve the workspace back out as writable 3. --ro-bind-try .git, .forge carve those back to read-only Emitted in any other order, `.git` is writable and the recovery mechanism can delete itself. `-try` because a workspace need not have either directory yet and bwrap fails on a missing bind source. `--unshare-net` denies egress; `--dev` and `--proc` are the minimum a shell needs, without which ordinary redirects fail the way /dev/null did on macOS. Reads stay broad, matching the macOS policy and Codex's workspace-write: toolchains need ~/.gitconfig and ~/.cargo, so a secret can be read and the network denial is what stops it leaving. Tests: 4 over the invocation — bind ordering, egress denial with a read-only root, absolute-path resolution, and no invocation for an unresolvable workspace. They assert on the argv rather than on behaviour, because this machine is macOS; they no-op safely where bwrap is absent. CI on Linux is what exercises the real thing, and the enforcement suite in tests/sandbox_enforcement.rs is still macOS-gated — a Linux equivalent should follow once CI confirms bwrap is present and usable on the runner.
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.
Second step of the permission-model overhaul (
docs/permission-model-overhaul.md), after #386 built the enforcement floor.The invariant
AcceptEdits("Auto") frees writes. That is only defensible when a sandbox confines what a freed write can reach. On a host that cannot confine, the honest mode is Manual — forge asks, rather than running agent commands unconfined and silent.This is a deliberate divergence from Claude Code, whose default is warn-and-continue unsandboxed, hardened only by opting into
sandbox.failIfUnavailable. That trades the floor for convenience at exactly the moment the user cannot see it.Ceiling, not override
Narrowing is always safe, so a user who prefers Manual keeps it and is never overridden. Only widening past what the host can enforce is refused.
PermissionMode::clamped_to— the pure rule, in forge-governanceforge_core::permission_ceiling()— computes the bound fromsandbox::availability()The derivation lives in forge-core because it is the lowest layer that sees both halves:
forge-governanceownsPermissionModebut depends onforge-typesalone and cannot see a sandbox;forge-toolsknows about sandboxes and nothing about approval. A future headless entry point inherits it for free.One call site
set_permission_mode_clampedis the only place a mode is applied, so the invariant cannot be bypassed by adding another caller. It covers all three paths:PermissionModederivesDefaultasAcceptEdits, so a fresh session on a sandbox-less host would otherwise begin in Auto with nothing underneath it.Dropping the git precondition
The plan called for a clean git tree as a precondition for Auto. Implementing it showed it does not survive contact:
Either reading fights the goal that motivated the overhaul. Sandbox availability is now the only gate. (Codex keys its defaults off whether the folder is version-controlled, not whether it is clean — same conclusion reached from the other direction.)
Tests
Coverage note worth knowing: on macOS the ceiling is
AcceptEdits, so local runs exercise the permissive branch. CI Linux has no sandbox yet, so CI exercises the clamp-to-Manual branch — between them both sides are covered, and that flips once bubblewrap lands.Pre-existing failure
approving_a_hitl_gated_tool_resumes_the_turn_instead_of_stalling_foreverfails on my machine at every commit including7fdb7a0, and passes in CI. Bisected; unrelated to this change. It is the only failure in the workspace.