mirror of
https://github.com/openai/codex.git
synced 2026-11-14 21:40:39 +00:00
Resolve session storage URL async with timeout
This commit is contained in:
@@ -79,6 +79,7 @@ use std::io::ErrorKind;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
#[cfg(test)]
|
||||
use tempfile::tempdir;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@@ -110,6 +111,7 @@ pub use codex_git::GhostSnapshotConfig;
|
||||
/// the context window.
|
||||
pub(crate) const PROJECT_DOC_MAX_BYTES: usize = 32 * 1024; // 32 KiB
|
||||
pub(crate) const DEFAULT_AGENT_MAX_THREADS: Option<usize> = Some(6);
|
||||
const SESSION_OBJECT_STORAGE_URL_CMD_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
pub const CONFIG_TOML_FILE: &str = "config.toml";
|
||||
|
||||
@@ -1904,15 +1906,35 @@ impl Config {
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub fn resolve_session_object_storage_url(&self) -> std::io::Result<Option<String>> {
|
||||
pub async fn resolve_session_object_storage_url(&self) -> std::io::Result<Option<String>> {
|
||||
if let Some(url) = self.session_object_storage_url.as_ref() {
|
||||
return Ok(Some(url.clone()));
|
||||
}
|
||||
|
||||
Self::try_run_command_for_value(
|
||||
self.session_object_storage_url_cmd.as_deref(),
|
||||
"session_object_storage_url_cmd",
|
||||
)
|
||||
let Some(command) = self.session_object_storage_url_cmd.clone() else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut handle = tokio::task::spawn_blocking(move || {
|
||||
Self::try_run_command_for_value(Some(&command), "session_object_storage_url_cmd")
|
||||
});
|
||||
let resolved =
|
||||
match tokio::time::timeout(SESSION_OBJECT_STORAGE_URL_CMD_TIMEOUT, &mut handle).await {
|
||||
Ok(result) => result.map_err(|err| {
|
||||
std::io::Error::other(format!("session_object_storage_url_cmd panicked: {err}"))
|
||||
})?,
|
||||
Err(_) => {
|
||||
handle.abort();
|
||||
return Err(std::io::Error::new(
|
||||
ErrorKind::TimedOut,
|
||||
format!(
|
||||
"session_object_storage_url_cmd timed out after {}s",
|
||||
SESSION_OBJECT_STORAGE_URL_CMD_TIMEOUT.as_secs()
|
||||
),
|
||||
));
|
||||
}
|
||||
};
|
||||
Ok(resolved?)
|
||||
}
|
||||
|
||||
fn load_instructions(codex_dir: Option<&Path>) -> Option<String> {
|
||||
|
||||
Reference in New Issue
Block a user