From 7be7aede8b94bb3d104993a3d548dcbfd46928fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Almeida?= Date: Wed, 6 May 2026 21:03:31 +0100 Subject: [PATCH] fix(codex): align with the standard SessionDirTemplate pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex was the only agent that bind-mounted its host home into the container via an explicit `Mounts: [{home}/.codex → /root/.codex]` entry, while every other ACP agent uses `SessionConfig.SessionDirTemplate` + `SessionDirTarget`. Move codex onto the same surface so the host-state isolation work in the next commit covers it uniformly. This change alone does not stop the host-state leak — the bind mount still resolves to the host's ~/.codex for now — but it removes the last agent-specific branch in the runtime config so the docker container manager can apply one rule for all agents. --- .../internal/agent/agents/codex_acp.go | 8 ++++- .../internal/agent/agents/codex_acp_test.go | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 apps/backend/internal/agent/agents/codex_acp_test.go diff --git a/apps/backend/internal/agent/agents/codex_acp.go b/apps/backend/internal/agent/agents/codex_acp.go index c10081c139..a373cf39b4 100644 --- a/apps/backend/internal/agent/agents/codex_acp.go +++ b/apps/backend/internal/agent/agents/codex_acp.go @@ -88,13 +88,19 @@ func (a *CodexACP) Runtime() *RuntimeConfig { Env: map[string]string{}, Mounts: []MountTemplate{ {Source: "{workspace}", Target: "/workspace"}, - {Source: "{home}/.codex", Target: "/root/.codex"}, }, ResourceLimits: ResourceLimits{MemoryMB: 4096, CPUCores: 2.0, Timeout: time.Hour}, Protocol: agent.ProtocolACP, SessionConfig: SessionConfig{ NativeSessionResume: true, CanRecover: &canRecover, + // Use the same SessionDirTemplate pattern every other ACP agent + // uses; the docker container manager wires this into a kandev-owned + // per-container session dir, isolated from the host's ~/.codex + // (which carries host-absolute rollout paths in state.db that + // don't resolve inside the container). + SessionDirTemplate: "{home}/.codex", + SessionDirTarget: "/root/.codex", }, } } diff --git a/apps/backend/internal/agent/agents/codex_acp_test.go b/apps/backend/internal/agent/agents/codex_acp_test.go new file mode 100644 index 0000000000..1ea17754f0 --- /dev/null +++ b/apps/backend/internal/agent/agents/codex_acp_test.go @@ -0,0 +1,29 @@ +package agents + +import ( + "strings" + "testing" +) + +func TestCodexACPRuntimeNoLongerBindMountsHostHome(t *testing.T) { + a := NewCodexACP() + rt := a.Runtime() + + for _, m := range rt.Mounts { + if strings.Contains(m.Source, "{home}") { + t.Fatalf("codex Mounts unexpectedly references {home}: %+v", m) + } + } +} + +func TestCodexACPSessionDirTemplate(t *testing.T) { + a := NewCodexACP() + cfg := a.Runtime().SessionConfig + + if cfg.SessionDirTemplate != "{home}/.codex" { + t.Fatalf("SessionDirTemplate = %q, want %q", cfg.SessionDirTemplate, "{home}/.codex") + } + if cfg.SessionDirTarget != "/root/.codex" { + t.Fatalf("SessionDirTarget = %q, want %q", cfg.SessionDirTarget, "/root/.codex") + } +}