From 601b61a83ffe2148031422ad9fd15823c3fab3fa Mon Sep 17 00:00:00 2001 From: jif Date: Fri, 10 Jul 2026 15:35:43 +0000 Subject: [PATCH] Rebind memory consolidation workspace roots (#32197) ## Why The memory consolidation agent changes its working directory to the memory root, but applying its sandbox policy directly to the permissions object can leave workspace roots inherited from the parent configuration. ## What changed Apply the consolidation sandbox policy through `Config` so its workspace roots are synchronized with the memory root. Add a test covering the working directory, workspace roots, and effective legacy sandbox policy. GitOrigin-RevId: dc6e75aef1ffa84a2f66fec6ed3a6fedcf9aa672 --- codex-rs/memories/write/src/phase2.rs | 7 +++- .../write/src/phase2_workspace_roots_tests.rs | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 codex-rs/memories/write/src/phase2_workspace_roots_tests.rs diff --git a/codex-rs/memories/write/src/phase2.rs b/codex-rs/memories/write/src/phase2.rs index 1c7f35b5ae..a4464d29dc 100644 --- a/codex-rs/memories/write/src/phase2.rs +++ b/codex-rs/memories/write/src/phase2.rs @@ -332,8 +332,7 @@ mod agent { exclude_slash_tmp: true, }; agent_config - .permissions - .set_legacy_sandbox_policy(consolidation_sandbox_policy, agent_config.cwd.as_path()) + .set_legacy_sandbox_policy(consolidation_sandbox_policy) .ok()?; agent_config.model = Some( @@ -534,6 +533,10 @@ mod agent { } } +#[cfg(test)] +#[path = "phase2_workspace_roots_tests.rs"] +mod workspace_roots_tests; + pub(super) fn get_watermark( claimed_watermark: i64, latest_memories: &[codex_state::Stage1Output], diff --git a/codex-rs/memories/write/src/phase2_workspace_roots_tests.rs b/codex-rs/memories/write/src/phase2_workspace_roots_tests.rs new file mode 100644 index 0000000000..ffaca77767 --- /dev/null +++ b/codex-rs/memories/write/src/phase2_workspace_roots_tests.rs @@ -0,0 +1,42 @@ +use super::agent; +use crate::memory_root; +use codex_model_provider::create_model_provider; +use codex_protocol::protocol::SandboxPolicy; +use core_test_support::responses::start_mock_server; +use core_test_support::test_codex::test_codex; +use pretty_assertions::assert_eq; +use std::sync::Arc; +use tempfile::TempDir; + +#[tokio::test] +async fn consolidation_rebinds_workspace_roots_to_memory_root() -> anyhow::Result<()> { + let server = start_mock_server().await; + let home = Arc::new(TempDir::new()?); + let test = test_codex() + .with_home(home) + .build_with_auto_env(&server) + .await?; + let provider = create_model_provider( + test.config.model_provider.clone(), + Some(test.thread_manager.auth_manager()), + ); + + let agent_config = + agent::get_config(&test.config, provider.as_ref()).expect("agent config should be created"); + let root = memory_root(&test.config.codex_home); + + assert_eq!(agent_config.cwd, root); + assert_eq!(agent_config.workspace_roots, vec![root]); + assert_eq!( + agent_config.legacy_sandbox_policy(), + SandboxPolicy::WorkspaceWrite { + writable_roots: Vec::new(), + network_access: false, + exclude_tmpdir_env_var: true, + exclude_slash_tmp: true, + } + ); + + test.codex.shutdown_and_wait().await?; + Ok(()) +}