Files
codex/codex-rs/exec/src/approval_warning.rs
T
Benjamin Carlsson 6b776372fd Honor configured and saved approvals in codex exec (#63515)
## Why

`codex exec` could force the approval policy to `never`, overriding
configured approvals on new threads and saved approvals when continuing
a thread.

## What changed

New local and remote threads use their configured approval settings.
Resumed and forked threads inherit the source thread's approval policy
and reviewer independently. An explicit local CLI or profile override
changes the supplied setting and saves it on the resulting thread.

Before an interactive approval can be requested, `codex exec` warns on
stderr when the effective settings call for a human reviewer. Exec
rejects those requests immediately because it runs non-interactively.

## Testing

Regression tests cover approval outcomes, warnings, and saved settings
across local and remote runs. They also cover managed sandbox validation
against an inherited approval policy.

GitOrigin-RevId: 5d3499f7a59ce16b8d909e669e9f74682f6c3b69
2026-11-24 03:13:18 +00:00

30 lines
1.3 KiB
Rust

//! Explain how exec handles approvals when the effective settings call for a human.
use codex_app_server_protocol::ApprovalsReviewer;
use codex_app_server_protocol::AskForApproval;
pub(super) fn warn_if_human_approval(
policy: AskForApproval,
reviewer: ApprovalsReviewer,
flags_supported: bool,
) {
// Even with every granular category disabled, a dangerous command can
// require approval to run within the existing sandbox.
if reviewer != ApprovalsReviewer::User || policy == AskForApproval::Never {
return;
}
eprintln!(
"WARNING: This thread is configured to ask a human for approval. \
`codex exec` runs non-interactively and immediately rejects approval requests it receives.\n\
- To review requests yourself, run this turn from the TUI."
);
// Switching an untrusted project to Never would also allow ordinary
// sandboxed commands that currently require approval.
if flags_supported && policy != AskForApproval::UnlessTrusted {
eprintln!(
"- To change the thread's saved reviewer, pass `--config 'approvals_reviewer=\"auto_review\"'` to `codex exec resume`.\n\
- To disable approval prompts for this and future turns, pass `--config 'approval_policy=\"never\"'` to `codex exec resume`."
);
}
}