Skip to content

Commit f9e6f7f

Browse files
authored
Merge branch 'main' into add-github-action-for-nix
2 parents dd94a4c + 0a0a10d commit f9e6f7f

File tree

5 files changed

+608
-57
lines changed

5 files changed

+608
-57
lines changed

codex-rs/core/src/executor/backends.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use async_trait::async_trait;
66
use crate::CODEX_APPLY_PATCH_ARG1;
77
use crate::apply_patch::ApplyPatchExec;
88
use crate::exec::ExecParams;
9+
use crate::executor::ExecutorConfig;
910
use crate::function_tool::FunctionCallError;
1011

1112
pub(crate) enum ExecutionMode {
@@ -22,6 +23,7 @@ pub(crate) trait ExecutionBackend: Send + Sync {
2223
params: ExecParams,
2324
// Required for downcasting the apply_patch.
2425
mode: &ExecutionMode,
26+
config: &ExecutorConfig,
2527
) -> Result<ExecParams, FunctionCallError>;
2628

2729
fn stream_stdout(&self, _mode: &ExecutionMode) -> bool {
@@ -47,6 +49,7 @@ impl ExecutionBackend for ShellBackend {
4749
&self,
4850
params: ExecParams,
4951
mode: &ExecutionMode,
52+
_config: &ExecutorConfig,
5053
) -> Result<ExecParams, FunctionCallError> {
5154
match mode {
5255
ExecutionMode::Shell => Ok(params),
@@ -65,17 +68,22 @@ impl ExecutionBackend for ApplyPatchBackend {
6568
&self,
6669
params: ExecParams,
6770
mode: &ExecutionMode,
71+
config: &ExecutorConfig,
6872
) -> Result<ExecParams, FunctionCallError> {
6973
match mode {
7074
ExecutionMode::ApplyPatch(exec) => {
71-
let path_to_codex = env::current_exe()
72-
.ok()
73-
.map(|p| p.to_string_lossy().to_string())
74-
.ok_or_else(|| {
75-
FunctionCallError::RespondToModel(
76-
"failed to determine path to codex executable".to_string(),
77-
)
78-
})?;
75+
let path_to_codex = if let Some(exe_path) = &config.codex_exe {
76+
exe_path.to_string_lossy().to_string()
77+
} else {
78+
env::current_exe()
79+
.ok()
80+
.map(|p| p.to_string_lossy().to_string())
81+
.ok_or_else(|| {
82+
FunctionCallError::RespondToModel(
83+
"failed to determine path to codex executable".to_string(),
84+
)
85+
})?
86+
};
7987

8088
let patch = exec.action.patch.clone();
8189
Ok(ExecParams {

codex-rs/core/src/executor/runner.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ use codex_otel::otel_event_manager::ToolDecisionSource;
3030
pub(crate) struct ExecutorConfig {
3131
pub(crate) sandbox_policy: SandboxPolicy,
3232
pub(crate) sandbox_cwd: PathBuf,
33-
codex_linux_sandbox_exe: Option<PathBuf>,
33+
pub(crate) codex_exe: Option<PathBuf>,
3434
}
3535

3636
impl ExecutorConfig {
3737
pub(crate) fn new(
3838
sandbox_policy: SandboxPolicy,
3939
sandbox_cwd: PathBuf,
40-
codex_linux_sandbox_exe: Option<PathBuf>,
40+
codex_exe: Option<PathBuf>,
4141
) -> Self {
4242
Self {
4343
sandbox_policy,
4444
sandbox_cwd,
45-
codex_linux_sandbox_exe,
45+
codex_exe,
4646
}
4747
}
4848
}
@@ -86,24 +86,24 @@ impl Executor {
8686
maybe_translate_shell_command(request.params, session, request.use_shell_profile);
8787
}
8888

89-
// Step 1: Normalise parameters via the selected backend.
89+
// Step 1: Snapshot sandbox configuration so it stays stable for this run.
90+
let config = self
91+
.config
92+
.read()
93+
.map_err(|_| ExecError::rejection("executor config poisoned"))?
94+
.clone();
95+
96+
// Step 2: Normalise parameters via the selected backend.
9097
let backend = backend_for_mode(&request.mode);
9198
let stdout_stream = if backend.stream_stdout(&request.mode) {
9299
request.stdout_stream.clone()
93100
} else {
94101
None
95102
};
96103
request.params = backend
97-
.prepare(request.params, &request.mode)
104+
.prepare(request.params, &request.mode, &config)
98105
.map_err(ExecError::from)?;
99106

100-
// Step 2: Snapshot sandbox configuration so it stays stable for this run.
101-
let config = self
102-
.config
103-
.read()
104-
.map_err(|_| ExecError::rejection("executor config poisoned"))?
105-
.clone();
106-
107107
// Step 3: Decide sandbox placement, prompting for approval when needed.
108108
let sandbox_decision = select_sandbox(
109109
&request,
@@ -227,7 +227,7 @@ impl Executor {
227227
sandbox,
228228
&config.sandbox_policy,
229229
&config.sandbox_cwd,
230-
&config.codex_linux_sandbox_exe,
230+
&config.codex_exe,
231231
stdout_stream,
232232
)
233233
.await

codex-rs/core/tests/common/test_codex.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::mem::swap;
2+
use std::path::PathBuf;
23
use std::sync::Arc;
34

45
use codex_core::CodexAuth;
@@ -39,6 +40,12 @@ impl TestCodexBuilder {
3940
let mut config = load_default_config_for_test(&home);
4041
config.cwd = cwd.path().to_path_buf();
4142
config.model_provider = model_provider;
43+
config.codex_linux_sandbox_exe = Some(PathBuf::from(
44+
assert_cmd::Command::cargo_bin("codex")?
45+
.get_program()
46+
.to_os_string(),
47+
));
48+
4249
let mut mutators = vec![];
4350
swap(&mut self.config_mutators, &mut mutators);
4451

0 commit comments

Comments
 (0)