mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Scope resume --approve-for-me to the initial conversation (#63589)
## Why An already-loaded conversation can ignore permission overrides sent with a resume request. Applying the preset to the TUI's launch configuration can also carry it into later conversations. ## What changed Resolve the preset using the selected conversation's workspace and managed requirements. Apply it only to the initial resume, so `/new` and later resumes use the regular launch configuration. If an already-loaded conversation needs a settings update, read back its approval and sandbox settings before submitting the initial prompt. Stop the resume when the server cannot confirm the requested settings or when workspace or managed restrictions cannot be verified. ## Testing Regression tests cover CLI flag precedence, updating an already-loaded conversation, rejecting unverifiable restrictions, and keeping the preset out of new and subsequently resumed conversations. GitOrigin-RevId: 6a09097dfc64fdeb890c03cd3e56bb404e5199c8
This commit is contained in:
+48
-20
@@ -1119,9 +1119,11 @@ async fn dispatch_cli(
|
||||
interactive.no_daemon |= options.no_daemon;
|
||||
}
|
||||
let root_strict_config = interactive.strict_config;
|
||||
interactive
|
||||
.shared
|
||||
.take_auto_review_config_overrides(&mut root_config_overrides);
|
||||
if !matches!(subcommand, Some(Subcommand::Resume(_))) {
|
||||
interactive
|
||||
.shared
|
||||
.take_auto_review_config_overrides(&mut root_config_overrides);
|
||||
}
|
||||
reject_root_strict_config_for_subcommand(root_strict_config, &subcommand)?;
|
||||
if let Some(subcommand) = subcommand.as_ref() {
|
||||
profile_v2_for_subcommand(&interactive, subcommand)?;
|
||||
@@ -2689,6 +2691,26 @@ fn finalize_resume_interactive(
|
||||
interactive.resume_show_all = show_all;
|
||||
interactive.resume_include_non_interactive = include_non_interactive;
|
||||
|
||||
// Extract the preset before merging launch flags so it cannot erase root permissions
|
||||
// or force an embedded server. Keep its position relative to explicit -c overrides.
|
||||
if interactive.auto_review || resume_cli.auto_review {
|
||||
let overrides_root_permissions = resume_cli.auto_review;
|
||||
let mut config = root_config_overrides.clone();
|
||||
interactive
|
||||
.shared
|
||||
.take_auto_review_config_overrides(&mut config);
|
||||
config
|
||||
.raw_overrides
|
||||
.extend(resume_cli.config_overrides.raw_overrides.iter().cloned());
|
||||
resume_cli
|
||||
.shared
|
||||
.take_auto_review_config_overrides(&mut config);
|
||||
interactive.resume_approval_preset = Some(codex_tui::ResumeApprovalPreset {
|
||||
config,
|
||||
overrides_root_permissions,
|
||||
});
|
||||
}
|
||||
|
||||
// Merge resume-scoped flags and overrides with highest precedence.
|
||||
merge_interactive_cli_flags(&mut interactive, resume_cli);
|
||||
|
||||
@@ -2952,16 +2974,12 @@ enabled = true
|
||||
fn finalize_resume_from_args(args: &[&str]) -> TuiCli {
|
||||
let cli = MultitoolCli::try_parse_from(args).expect("parse");
|
||||
let MultitoolCli {
|
||||
mut interactive,
|
||||
config_overrides: mut root_overrides,
|
||||
interactive,
|
||||
config_overrides: root_overrides,
|
||||
subcommand,
|
||||
feature_toggles: _,
|
||||
remote: _,
|
||||
} = cli;
|
||||
interactive
|
||||
.shared
|
||||
.take_auto_review_config_overrides(&mut root_overrides);
|
||||
|
||||
let Subcommand::Resume(ResumeCommand {
|
||||
session_id,
|
||||
last,
|
||||
@@ -3370,8 +3388,11 @@ enabled = true
|
||||
interactive.approval_policy,
|
||||
Some(codex_utils_cli::ApprovalModeCliArg::Never)
|
||||
);
|
||||
assert!(interactive.config_overrides.raw_overrides.is_empty());
|
||||
let preset = interactive.resume_approval_preset.unwrap();
|
||||
assert!(!preset.overrides_root_permissions);
|
||||
assert_eq!(
|
||||
interactive.config_overrides.raw_overrides,
|
||||
preset.config.raw_overrides,
|
||||
vec![
|
||||
r#"approvals_reviewer="auto_review""#.to_string(),
|
||||
r#"approval_policy="on-request""#.to_string(),
|
||||
@@ -3381,23 +3402,30 @@ enabled = true
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn later_approve_for_me_overrides_root_tui_approval_policy() {
|
||||
fn resume_preset_preserves_root_permissions_for_later_sessions() {
|
||||
let interactive = finalize_resume_from_args(&[
|
||||
"codex",
|
||||
"--ask-for-approval",
|
||||
"never",
|
||||
"--sandbox",
|
||||
"read-only",
|
||||
"resume",
|
||||
"--approve-for-me",
|
||||
]);
|
||||
|
||||
assert!(interactive.approval_policy.is_none());
|
||||
assert_eq!(
|
||||
interactive.config_overrides.raw_overrides,
|
||||
vec![
|
||||
r#"approvals_reviewer="auto_review""#.to_string(),
|
||||
r#"approval_policy="on-request""#.to_string(),
|
||||
r#"sandbox_mode="workspace-write""#.to_string(),
|
||||
]
|
||||
assert_matches!(
|
||||
interactive.approval_policy,
|
||||
Some(codex_utils_cli::ApprovalModeCliArg::Never)
|
||||
);
|
||||
assert_matches!(
|
||||
interactive.sandbox_mode,
|
||||
Some(codex_utils_cli::SandboxModeCliArg::ReadOnly)
|
||||
);
|
||||
assert!(interactive.config_overrides.raw_overrides.is_empty());
|
||||
assert!(
|
||||
interactive
|
||||
.resume_approval_preset
|
||||
.unwrap()
|
||||
.overrides_root_permissions
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user