From 8362b79cb478401c2027296f0ca3aed62b884122 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Wed, 25 Feb 2026 15:52:55 +0000 Subject: [PATCH] feat: fix sqlite home (#12787) --- codex-rs/core/config.schema.json | 2 +- codex-rs/core/src/config/mod.rs | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json index c81c4e174..c5e85ad68 100644 --- a/codex-rs/core/config.schema.json +++ b/codex-rs/core/config.schema.json @@ -2052,7 +2052,7 @@ "$ref": "#/definitions/AbsolutePathBuf" } ], - "description": "Directory where Codex stores the SQLite state DB. Defaults to `$CODEX_SQLITE_HOME` when set. Otherwise uses a temp dir under WorkspaceWrite sandboxing and `$CODEX_HOME` for other modes." + "description": "Directory where Codex stores the SQLite state DB. Defaults to `$CODEX_SQLITE_HOME` when set. Otherwise uses `$CODEX_HOME`." }, "suppress_unstable_features_warning": { "description": "Suppress warnings about unstable (under development) features.", diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index 6b0c05fef..37fd5740a 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -120,16 +120,6 @@ pub(crate) const DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS: Option = None; pub const CONFIG_TOML_FILE: &str = "config.toml"; -fn default_sqlite_home(sandbox_policy: &SandboxPolicy, codex_home: &Path) -> PathBuf { - if matches!(sandbox_policy, SandboxPolicy::WorkspaceWrite { .. }) { - let mut path = std::env::temp_dir(); - path.push("codex-sqlite"); - path - } else { - codex_home.to_path_buf() - } -} - fn resolve_sqlite_home_env(resolved_cwd: &Path) -> Option { let raw = std::env::var(codex_state::SQLITE_HOME_ENV).ok()?; let trimmed = raw.trim(); @@ -1146,8 +1136,7 @@ pub struct ConfigToml { pub history: Option, /// Directory where Codex stores the SQLite state DB. - /// Defaults to `$CODEX_SQLITE_HOME` when set. Otherwise uses a temp dir - /// under WorkspaceWrite sandboxing and `$CODEX_HOME` for other modes. + /// Defaults to `$CODEX_SQLITE_HOME` when set. Otherwise uses `$CODEX_HOME`. pub sqlite_home: Option, /// Directory where Codex writes log files, for example `codex-tui.log`. @@ -2007,7 +1996,7 @@ impl Config { .as_ref() .map(AbsolutePathBuf::to_path_buf) .or_else(|| resolve_sqlite_home_env(&resolved_cwd)) - .unwrap_or_else(|| default_sqlite_home(&sandbox_policy, &codex_home)); + .unwrap_or_else(|| codex_home.to_path_buf()); // Ensure that every field of ConfigRequirements is applied to the final // Config. @@ -2957,6 +2946,23 @@ trust_level = "trusted" Ok(()) } + #[test] + fn sqlite_home_defaults_to_codex_home_for_workspace_write() -> std::io::Result<()> { + let codex_home = TempDir::new()?; + let config = Config::load_from_base_config_with_overrides( + ConfigToml::default(), + ConfigOverrides { + sandbox_mode: Some(SandboxMode::WorkspaceWrite), + ..Default::default() + }, + codex_home.path().to_path_buf(), + )?; + + assert_eq!(config.sqlite_home, codex_home.path().to_path_buf()); + + Ok(()) + } + #[test] fn config_defaults_to_file_cli_auth_store_mode() -> std::io::Result<()> { let codex_home = TempDir::new()?;