refactor: remove redundant sandbox violation predicate

Co-authored-by: Codex noreply@openai.com
This commit is contained in:
viyatb-oai
2026-07-07 12:44:02 -07:00
co-authored by Codex noreply@openai.com
parent d0cc5676a6
commit 935c9f2b54
4 changed files with 30 additions and 37 deletions
@@ -48,7 +48,6 @@ use codex_sandboxing::SandboxManager;
use codex_sandboxing::SandboxTransformRequest;
use codex_sandboxing::SandboxType;
use codex_sandboxing::SandboxablePreference;
use codex_sandboxing::is_filesystem_sandbox_violation;
use codex_sandboxing::record_filesystem_sandbox_violation;
use codex_shell_command::bash::parse_shell_lc_plain_commands;
use codex_shell_command::bash::parse_shell_lc_single_command_prefix;
@@ -1114,8 +1113,7 @@ fn map_exec_result(
})));
}
if is_filesystem_sandbox_violation(sandbox, &output) {
record_filesystem_sandbox_violation(sandbox, &output);
if record_filesystem_sandbox_violation(sandbox, &output).is_some() {
return Err(ToolError::Codex(CodexErr::Sandbox(SandboxErr::Denied {
output: Box::new(output),
network_policy_decision: None,
-2
View File
@@ -30,8 +30,6 @@ pub use violation::FileSystemSandboxViolation;
pub use violation::FileSystemSandboxViolationReason;
pub use violation::NetworkSandboxViolation;
pub use violation::SandboxViolationEvent;
pub use violation::classify_filesystem_sandbox_violation;
pub use violation::is_filesystem_sandbox_violation;
pub use violation::record_filesystem_sandbox_violation;
pub use violation::record_network_sandbox_violation;
pub use violation::record_sandbox_violation;
+1 -9
View File
@@ -110,7 +110,7 @@ impl NetworkSandboxViolation {
}
/// Classify a sandboxed process result as a filesystem sandbox violation.
pub fn classify_filesystem_sandbox_violation(
fn classify_filesystem_sandbox_violation(
sandbox_type: SandboxType,
exec_output: &ExecToolCallOutput,
) -> Option<FileSystemSandboxViolation> {
@@ -148,14 +148,6 @@ pub fn classify_filesystem_sandbox_violation(
None
}
/// Return whether a sandboxed process result represents a filesystem sandbox violation.
pub fn is_filesystem_sandbox_violation(
sandbox_type: SandboxType,
exec_output: &ExecToolCallOutput,
) -> bool {
classify_filesystem_sandbox_violation(sandbox_type, exec_output).is_some()
}
/// Record a filesystem sandbox violation, returning the classified event when one was found.
pub fn record_filesystem_sandbox_violation(
sandbox_type: SandboxType,
+28 -23
View File
@@ -23,7 +23,7 @@ fn make_exec_output(
}
#[test]
fn preserves_legacy_boolean_denial_keywords() {
fn classifies_legacy_denial_keywords() {
for keyword in [
"operation not permitted",
"permission denied",
@@ -35,16 +35,15 @@ fn preserves_legacy_boolean_denial_keywords() {
] {
let output = make_exec_output(/*exit_code*/ 1, "", keyword, "");
assert_eq!(
is_filesystem_sandbox_violation(SandboxType::LinuxSeccomp, &output),
true,
assert!(
classify_filesystem_sandbox_violation(SandboxType::LinuxSeccomp, &output).is_some(),
"{keyword}"
);
}
}
#[test]
fn preserves_legacy_boolean_denial_ordering() {
fn preserves_legacy_denial_ordering() {
let quick_reject_without_keyword =
make_exec_output(/*exit_code*/ 127, "", "command not found", "");
let quick_reject_with_keyword =
@@ -54,22 +53,28 @@ fn preserves_legacy_boolean_denial_ordering() {
let non_sandbox_with_keyword =
make_exec_output(/*exit_code*/ 1, "", "Operation not permitted", "");
assert!(!is_filesystem_sandbox_violation(
SandboxType::LinuxSeccomp,
&quick_reject_without_keyword
));
assert!(is_filesystem_sandbox_violation(
SandboxType::LinuxSeccomp,
&quick_reject_with_keyword
));
assert!(!is_filesystem_sandbox_violation(
SandboxType::LinuxSeccomp,
&zero_exit_with_keyword
));
assert!(!is_filesystem_sandbox_violation(
SandboxType::None,
&non_sandbox_with_keyword
));
assert!(
classify_filesystem_sandbox_violation(
SandboxType::LinuxSeccomp,
&quick_reject_without_keyword
)
.is_none()
);
assert!(
classify_filesystem_sandbox_violation(
SandboxType::LinuxSeccomp,
&quick_reject_with_keyword
)
.is_some()
);
assert!(
classify_filesystem_sandbox_violation(SandboxType::LinuxSeccomp, &zero_exit_with_keyword)
.is_none()
);
assert!(
classify_filesystem_sandbox_violation(SandboxType::None, &non_sandbox_with_keyword)
.is_none()
);
}
#[test]
@@ -134,10 +139,10 @@ fn classifies_linux_sigsys_exit() {
}
#[test]
fn preserves_boolean_denial_semantics_for_non_sandbox_mode() {
fn does_not_classify_non_sandbox_mode() {
let output = make_exec_output(/*exit_code*/ 1, "", "Operation not permitted", "");
assert!(!is_filesystem_sandbox_violation(SandboxType::None, &output));
assert!(classify_filesystem_sandbox_violation(SandboxType::None, &output).is_none());
}
#[test]