Skip to content

Commit 95caac5

Browse files
committed
Fix Codex resume config replay and simplify permission handling
Replay saved config overrides in the resume/fork scope so launch reasoning settings survive a conflicting Codex default. Preserve user developer instructions and positional prompts when rebuilding the bootstrap. Remove codex_sandbox_mode and let native Codex settings select sandbox and approval policy. Keep native --add-dir and the terminal socket-access default, respecting explicit network overrides. Remove unused home wrappers. Validate with full just ci (10 steps), Codex 0.159.2 lifecycle regression, and live native-policy, network-override, and nested-launch checks. Fixes #147
1 parent f8110bc commit 95caac5

12 files changed

Lines changed: 302 additions & 641 deletions

File tree

‎scripts/mock-tools.pins‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# cache key all read this file.
44
#
55
# After a bump: just ci mock-tools real_tool_codex real_tool_claude test_relay_roundtrip
6-
@openai/codex@0.157.1
6+
@openai/codex@0.159.2
77
# Claude must stay >= 2.1.198: the first release with both `prompt_id` and
88
# backgrounded Agent/Task calls (tool_response.status="async_launched"), which
99
# hcom's hook routing has to handle. Below that, CI never exercises either.

‎src/commands/config.rs‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ pub const CONFIG_KEYS: &[(&str, &str, &str)] = &[
114114
"Default args for copilot on launch",
115115
"string",
116116
),
117-
(
118-
"HCOM_CODEX_SANDBOX_MODE",
119-
"Codex permission profile (workspace | danger-full-access | none)",
120-
"string",
121-
),
122117
(
123118
"HCOM_GEMINI_SYSTEM_PROMPT",
124119
"System prompt for gemini on launch",
@@ -332,20 +327,6 @@ fn config_set_at_path(path: &Path, key: &str, value: &str) -> Result<(), String>
332327
let field_name = key.strip_prefix("HCOM_").unwrap_or(key).to_lowercase();
333328
validate_config_args(&field_name, value)?;
334329

335-
if field_name == "codex_sandbox_mode" && !value.is_empty() {
336-
let normalized = if value == "full-auto" {
337-
"danger-full-access"
338-
} else {
339-
value
340-
};
341-
if !crate::config::VALID_SANDBOX_MODES.contains(&normalized) {
342-
return Err(format!(
343-
"codex_sandbox_mode must be one of: {}. Got '{value}'",
344-
crate::config::VALID_SANDBOX_MODES.join(", ")
345-
));
346-
}
347-
}
348-
349330
if field_name == "title_mode"
350331
&& !value.is_empty()
351332
&& !crate::shared::VALID_TITLE_MODES.contains(&value)
@@ -1436,28 +1417,6 @@ Clear: hcom config codex_args \"\"
14361417
Merged with launch-time cli args (launch args win on conflict).",
14371418
),
14381419

1439-
"HCOM_CODEX_SANDBOX_MODE" => Some(
1440-
"\
1441-
HCOM_CODEX_SANDBOX_MODE - Permission flags hcom injects when launching codex
1442-
1443-
Default: workspace
1444-
1445-
Codex's default sandbox blocks the writes and Unix sockets hcom needs,
1446-
so hcom injects flags on every codex launch to reshape it. This knob
1447-
picks which set.
1448-
1449-
Values:
1450-
workspace Codex auto-runs; asks only when the model judges
1451-
necessary.
1452-
danger-full-access No sandbox, no approvals.
1453-
none Inject nothing. Codex uses your own config; DB
1454-
writes fail unless your config allows ~/.hcom.
1455-
1456-
Usage:
1457-
hcom config codex_sandbox_mode danger-full-access
1458-
hcom config codex_sandbox_mode \"\" # Reset to default",
1459-
),
1460-
14611420
"HCOM_RELAY" => Some(
14621421
"\
14631422
HCOM_RELAY - MQTT broker URL

‎src/commands/help.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,6 @@ const CONFIG_KEYS_HELP: &[HelpEntry] = &[
588588
" gemini_system_prompt / codex_system_prompt",
589589
"Default system prompt",
590590
),
591-
(
592-
" codex_sandbox_mode",
593-
"workspace | danger-full-access | none",
594-
),
595591
(" auto_approve", "Auto-approve safe hcom commands"),
596592
(" auto_subscribe", "Event auto-subscribe presets"),
597593
(

‎src/commands/resume.rs‎

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,19 +1069,20 @@ fn build_resume_args(tool: &str, session_id: &str, fork: bool) -> Vec<String> {
10691069

10701070
/// Merge original launch args with resume-specific args.
10711071
fn merge_resume_args(tool: &str, original: &[String], resume: &[String]) -> Vec<String> {
1072-
// Claude/Gemini/Codex stay grammar-free: preserve the stored user/config
1073-
// vector verbatim and append hcom's resume injection.
1072+
// Preserve user/config args where the tool accepts them. Codex config
1073+
// overrides must reach the resume/fork scope to take effect.
10741074
let tool_lookup = if tool == "claude-pty" { "claude" } else { tool };
10751075
let tool = tool_lookup
10761076
.parse::<crate::tool::Tool>()
10771077
.expect("resume tool must be validated before argument merging");
10781078

10791079
match tool {
1080-
crate::tool::Tool::Claude | crate::tool::Tool::Gemini | crate::tool::Tool::Codex => {
1080+
crate::tool::Tool::Claude | crate::tool::Tool::Gemini => {
10811081
let mut merged = original.to_vec();
10821082
merged.extend_from_slice(resume);
10831083
merged
10841084
}
1085+
crate::tool::Tool::Codex => merge_codex_resume_args(original, resume),
10851086
crate::tool::Tool::OpenCode | crate::tool::Tool::Kilo => {
10861087
merge_opencode_args(original, resume)
10871088
}
@@ -1098,6 +1099,43 @@ fn merge_resume_args(tool: &str, original: &[String], resume: &[String]) -> Vec<
10981099
}
10991100
}
11001101

1102+
/// Keep ordinary flags at the root, but replay config overrides after the
1103+
/// session selector. Extra resume overrides follow saved overrides so Codex
1104+
/// resolves precedence itself. Moving all flags would put saved and new
1105+
/// singular options (such as --model) in one clap scope, where they conflict.
1106+
fn merge_codex_resume_args(original: &[String], resume: &[String]) -> Vec<String> {
1107+
let mut root = Vec::new();
1108+
let mut config = Vec::new();
1109+
let mut i = 0;
1110+
while i < original.len() {
1111+
let token = &original[i];
1112+
if token == "--" {
1113+
root.extend_from_slice(&original[i..]);
1114+
break;
1115+
}
1116+
if matches!(token.as_str(), "-c" | "--config") {
1117+
config.push(token.clone());
1118+
i += 1;
1119+
if let Some(value) = original.get(i) {
1120+
config.push(value.clone());
1121+
i += 1;
1122+
}
1123+
} else {
1124+
if (token.starts_with("-c") && token.len() > 2) || token.starts_with("--config=") {
1125+
config.push(token.clone());
1126+
} else {
1127+
root.push(token.clone());
1128+
}
1129+
i += 1;
1130+
}
1131+
}
1132+
// hcom constructs this pair with build_resume_args.
1133+
root.extend_from_slice(&resume[..2]);
1134+
root.extend(config);
1135+
root.extend_from_slice(&resume[2..]);
1136+
root
1137+
}
1138+
11011139
/// Merge grok original launch args with resume args.
11021140
///
11031141
/// Drop session selectors, one-shot flags, and worktree flags (the session
@@ -2575,6 +2613,49 @@ mod tests {
25752613
assert_eq!(args, s(&["fork", "sess-456"]));
25762614
}
25772615

2616+
#[test]
2617+
fn codex_resume_replays_config_in_session_scope_with_new_overrides_last() {
2618+
let original = s(&[
2619+
"--model",
2620+
"gpt-6-luna",
2621+
"-c",
2622+
"model_reasoning_effort=\"low\"",
2623+
"--yolo",
2624+
"--config=service_tier=\"fast\"",
2625+
"-c=features.foo=true",
2626+
"-cfeatures.bar=false",
2627+
]);
2628+
for fork in [false, true] {
2629+
let mut resume = build_resume_args("codex", "session-id", fork);
2630+
resume.extend(s(&[
2631+
"--model",
2632+
"gpt-6-astra",
2633+
"--config",
2634+
"model_reasoning_effort=\"high\"",
2635+
]));
2636+
let merged = merge_resume_args("codex", &original, &resume);
2637+
assert_eq!(
2638+
merged,
2639+
s(&[
2640+
"--model",
2641+
"gpt-6-luna",
2642+
"--yolo",
2643+
if fork { "fork" } else { "resume" },
2644+
"session-id",
2645+
"-c",
2646+
"model_reasoning_effort=\"low\"",
2647+
"--config=service_tier=\"fast\"",
2648+
"-c=features.foo=true",
2649+
"-cfeatures.bar=false",
2650+
"--model",
2651+
"gpt-6-astra",
2652+
"--config",
2653+
"model_reasoning_effort=\"high\"",
2654+
])
2655+
);
2656+
}
2657+
}
2658+
25782659
#[test]
25792660
fn test_build_resume_args_gemini() {
25802661
let args = build_resume_args("gemini", "sess-789", false);

‎src/config.rs‎

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub(crate) const TOML_KEY_MAP: &[(&str, &str)] = &[
131131
("gemini_args", "launch.gemini.args"),
132132
("gemini_system_prompt", "launch.gemini.system_prompt"),
133133
("codex_args", "launch.codex.args"),
134-
("codex_sandbox_mode", "launch.codex.sandbox_mode"),
135134
("codex_system_prompt", "launch.codex.system_prompt"),
136135
("opencode_args", "launch.opencode.args"),
137136
("kilo_args", "launch.kilo.args"),
@@ -172,7 +171,6 @@ const FIELD_TO_ENV: &[(&str, &str)] = &[
172171
("claude_args", "HCOM_CLAUDE_ARGS"),
173172
("gemini_args", "HCOM_GEMINI_ARGS"),
174173
("codex_args", "HCOM_CODEX_ARGS"),
175-
("codex_sandbox_mode", "HCOM_CODEX_SANDBOX_MODE"),
176174
("gemini_system_prompt", "HCOM_GEMINI_SYSTEM_PROMPT"),
177175
("codex_system_prompt", "HCOM_CODEX_SYSTEM_PROMPT"),
178176
("opencode_args", "HCOM_OPENCODE_ARGS"),
@@ -214,9 +212,6 @@ const TERMINAL_DANGEROUS_CHARS: &[char] = &['`', '$', ';', '|', '&', '\n', '\r']
214212

215213
use crate::shared::terminal_presets::TERMINAL_PRESETS;
216214

217-
/// Valid codex sandbox modes.
218-
pub const VALID_SANDBOX_MODES: &[&str] = &["workspace", "danger-full-access", "none"];
219-
220215
/// TOML file header comment.
221216
const TOML_HEADER: &str = "\
222217
# hcom configuration
@@ -298,7 +293,6 @@ pub struct HcomConfig {
298293
pub kimi_args: String,
299294
pub copilot_args: String,
300295
pub grok_args: String,
301-
pub codex_sandbox_mode: String,
302296
pub gemini_system_prompt: String,
303297
pub codex_system_prompt: String,
304298
pub relay: String,
@@ -337,7 +331,6 @@ impl Default for HcomConfig {
337331
kimi_args: String::new(),
338332
copilot_args: String::new(),
339333
grok_args: String::new(),
340-
codex_sandbox_mode: "workspace".to_string(),
341334
gemini_system_prompt: String::new(),
342335
codex_system_prompt: String::new(),
343336
relay: String::new(),
@@ -469,17 +462,6 @@ impl HcomConfig {
469462
}
470463
}
471464

472-
// Validate codex_sandbox_mode
473-
if !VALID_SANDBOX_MODES.contains(&self.codex_sandbox_mode.as_str()) {
474-
errors.insert(
475-
"codex_sandbox_mode".into(),
476-
format!(
477-
"codex_sandbox_mode must be one of {:?}, got '{}'",
478-
VALID_SANDBOX_MODES, self.codex_sandbox_mode
479-
),
480-
);
481-
}
482-
483465
// Validate auto_subscribe (comma-separated alphanumeric/underscore preset names)
484466
if !self.auto_subscribe.is_empty() {
485467
for preset in self.auto_subscribe.split(',') {
@@ -523,7 +505,6 @@ impl HcomConfig {
523505
"kimi_args" => Some(self.kimi_args.clone()),
524506
"copilot_args" => Some(self.copilot_args.clone()),
525507
"grok_args" => Some(self.grok_args.clone()),
526-
"codex_sandbox_mode" => Some(self.codex_sandbox_mode.clone()),
527508
"gemini_system_prompt" => Some(self.gemini_system_prompt.clone()),
528509
"codex_system_prompt" => Some(self.codex_system_prompt.clone()),
529510
"relay" => Some(self.relay.clone()),
@@ -570,16 +551,6 @@ impl HcomConfig {
570551
"kimi_args" => self.kimi_args = value.to_string(),
571552
"copilot_args" => self.copilot_args = value.to_string(),
572553
"grok_args" => self.grok_args = value.to_string(),
573-
"codex_sandbox_mode" => {
574-
// Retired modes fall back to the default rather than turning an
575-
// existing config into an error. `untrusted` relied on Codex's
576-
// `-a untrusted`, which Codex 0.152 removed.
577-
self.codex_sandbox_mode = if matches!(value, "full-auto" | "untrusted") {
578-
"workspace".to_string()
579-
} else {
580-
value.to_string()
581-
};
582-
}
583554
"gemini_system_prompt" => self.gemini_system_prompt = value.to_string(),
584555
"codex_system_prompt" => self.codex_system_prompt = value.to_string(),
585556
"relay" => self.relay = value.to_string(),
@@ -704,7 +675,6 @@ impl HcomConfig {
704675
"cursor_args",
705676
"copilot_args",
706677
"grok_args",
707-
"codex_sandbox_mode",
708678
"gemini_system_prompt",
709679
"codex_system_prompt",
710680
"auto_subscribe",
@@ -714,9 +684,8 @@ impl HcomConfig {
714684
for str_field in &str_fields {
715685
if let Some(val) = get_var(str_field) {
716686
let s = val.as_string();
717-
// terminal and codex_sandbox_mode: skip empty (use default)
718-
if (*str_field == "terminal" || *str_field == "codex_sandbox_mode") && s.is_empty()
719-
{
687+
// Empty terminal uses the default.
688+
if *str_field == "terminal" && s.is_empty() {
720689
continue;
721690
}
722691
let _ = config.set_field(str_field, &s);
@@ -1864,7 +1833,6 @@ mod tests {
18641833
assert_eq!(config.subagent_timeout, 30);
18651834
assert_eq!(config.terminal, "default");
18661835
assert_eq!(config.tag, "");
1867-
assert_eq!(config.codex_sandbox_mode, "workspace");
18681836
assert!(config.relay_enabled);
18691837
assert!(config.auto_approve);
18701838
assert_eq!(config.auto_subscribe, "collision");
@@ -1904,22 +1872,6 @@ mod tests {
19041872
assert!(!config.collect_errors().contains_key("tag"));
19051873
}
19061874

1907-
#[test]
1908-
fn test_hcom_config_validation_sandbox_mode() {
1909-
let mut config = HcomConfig::default();
1910-
1911-
for mode in VALID_SANDBOX_MODES {
1912-
config.codex_sandbox_mode = mode.to_string();
1913-
assert!(
1914-
!config.collect_errors().contains_key("codex_sandbox_mode"),
1915-
"mode '{mode}' should be valid"
1916-
);
1917-
}
1918-
1919-
config.codex_sandbox_mode = "invalid".to_string();
1920-
assert!(config.collect_errors().contains_key("codex_sandbox_mode"));
1921-
}
1922-
19231875
#[test]
19241876
fn test_hcom_config_validation_shell_args() {
19251877
let mut config = HcomConfig {
@@ -2023,15 +1975,6 @@ mod tests {
20231975
assert!(config.collect_errors().contains_key("terminal"));
20241976
}
20251977

2026-
#[test]
2027-
fn test_set_field_retired_sandbox_modes_normalize_to_workspace() {
2028-
for retired in ["full-auto", "untrusted"] {
2029-
let mut config = HcomConfig::default();
2030-
config.set_field("codex_sandbox_mode", retired).unwrap();
2031-
assert_eq!(config.codex_sandbox_mode, "workspace", "{retired}");
2032-
}
2033-
}
2034-
20351978
#[test]
20361979
fn test_set_field_bool_coercion() {
20371980
let mut config = HcomConfig::default();
@@ -2205,19 +2148,6 @@ mod tests {
22052148
assert!(!config.auto_approve);
22062149
}
22072150

2208-
#[test]
2209-
fn test_load_from_sources_sandbox_mode_empty_uses_default() {
2210-
let mut file_config = HashMap::new();
2211-
file_config.insert(
2212-
"codex_sandbox_mode".to_string(),
2213-
TomlFieldValue::Str("".to_string()),
2214-
);
2215-
2216-
let env = HashMap::new();
2217-
let config = HcomConfig::load_from_sources(&file_config, Some(&env)).unwrap();
2218-
assert_eq!(config.codex_sandbox_mode, "workspace"); // Default, not empty
2219-
}
2220-
22212151
#[test]
22222152
fn test_load_from_sources_terminal_empty_uses_default() {
22232153
let mut file_config = HashMap::new();
@@ -2403,16 +2333,6 @@ auto_approve = false
24032333
);
24042334
}
24052335

2406-
#[test]
2407-
fn test_hcom_config_from_env_dict_with_retired_sandbox_modes() {
2408-
for retired in ["full-auto", "untrusted"] {
2409-
let mut data = HcomConfig::default().to_env_dict();
2410-
data.insert("HCOM_CODEX_SANDBOX_MODE".to_string(), retired.to_string());
2411-
let config = HcomConfig::from_env_dict(&data).unwrap();
2412-
assert_eq!(config.codex_sandbox_mode, "workspace", "{retired}");
2413-
}
2414-
}
2415-
24162336
#[test]
24172337
fn test_hcom_config_validation_error_display() {
24182338
let errors = HashMap::from([

0 commit comments

Comments
 (0)