Skip to content

feat: derive the permission mode from what the host can enforce - #387

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/derive-permission-mode
Aug 17, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/derive-permission-mode

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Second step of the permission-model overhaul (docs/permission-model-overhaul.md), after #386 built the enforcement floor.

The 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. 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-governance
  • forge_core::permission_ceiling() — computes the bound from sandbox::availability()

The derivation lives in forge-core because it is the lowest layer that sees both halves: forge-governance owns PermissionMode but depends on forge-types alone and cannot see a sandbox; forge-tools knows about sandboxes and nothing about approval. A future headless entry point inherits it for free.

One call site

set_permission_mode_clamped is the only place a mode is applied, so the invariant cannot be bypassed by adding another caller. It covers all three paths:

  1. Startup with no saved state — PermissionMode derives Default as AcceptEdits, so a fresh session on a sandbox-less host would otherwise begin in Auto with nothing underneath it.
  2. Restoring a persisted mode.
  3. The cycle key — a refused cycle now explains itself, instead of leaving the chip unchanged and the user wondering whether the binding is broken.

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:

  • evaluated continuously, the agent's own first edit dirties the tree and drops the session to Manual mid-task;
  • evaluated at session start, ordinary uncommitted work puts you in Manual for the whole session.

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

  • forge-core (4) — the ceiling matches host capability; Auto is unreachable without a floor; narrowing is never refused; a permitted mode passes through.
  • forge-tui (3) — requesting Auto is capped; choosing Manual is never overridden; a session never starts above the ceiling.

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_forever fails on my machine at every commit including 7fdb7a0, and passes in CI. Bisected; unrelated to this change. It is the only failure in the workspace.

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.
@github-actions
github-actions Bot enabled auto-merge (squash) August 17, 2026 13:39
…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.
@github-actions
github-actions Bot merged commit 89dbfa2 into main Aug 17, 2026
7 checks passed
@mohitranka
mohitranka deleted the feat/derive-permission-mode branch August 17, 2026 14:17
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.
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.

1 participant