Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7226 fix(daemon): decline Codex reuse when home preparation fails (#8236)
mrlonely6194a8b3a7a1
diff --git a/server/internal/daemon/execenv/codex_home.go b/server/internal/daemon/execenv/codex_home.goindex a5ed3948f4..ed6f9934f2 100644--- a/server/internal/daemon/execenv/codex_home.go+++ b/server/internal/daemon/execenv/codex_home.go@@ -293,8 +293,9 @@ func prepareCodexHomeWithOpts(codexHome string, opts CodexHomeOptions, logger *s// so the fail-closed policy just computed above would only exist in// memory while the effective config silently stays loose. Abort rather// than launch Codex with an unenforced sandbox: on fresh Prepare this- // fails the task; on Reuse the caller leaves env.CodexHome unset, which- // configureCodexTaskShellEnvironment then refuses to start (MUL-4957).+ // fails the task; on Reuse the caller declines the reuse and falls back+ // to Prepare, which re-runs this check against a fresh home and fails+ // the task if the managed block still cannot be written (MUL-4957).return fmt.Errorf("ensure codex sandbox config: %w", err)}diff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.goindex d6fcb99df0..335f0deea6 100644--- a/server/internal/daemon/execenv/execenv.go+++ b/server/internal/daemon/execenv/execenv.go@@ -804,7 +804,8 @@ type ReuseParams struct {}// Reuse wraps an existing workdir into an Environment and refreshes context files.-// Returns nil if the workdir does not exist (caller should fall back to Prepare).+// Returns nil if the workdir does not exist or required provider setup fails+// (caller should fall back to Prepare).func Reuse(params ReuseParams, logger *slog.Logger) *Environment {if _, err := os.Stat(params.WorkDir); err != nil {return nil@@ -914,7 +915,15 @@ func Reuse(params ReuseParams, logger *slog.Logger) *Environment {if params.Provider == "codex" {codexHome := filepath.Join(env.RootDir, codexHomeDirName)if err := prepareCodexHomeWithOpts(codexHome, CodexHomeOptions{CodexVersion: params.CodexVersion, ResumeSessionID: params.ResumeSessionID, IsLocalDirectory: params.LocalDirectory, SessionStoreKey: codexSessionStoreKey(params.Profile, params.Task), CodexCustomArgs: params.CodexCustomArgs}, logger); err != nil {- logger.Warn("execenv: refresh codex-home failed", "error", err)+ // Leaving env.CodexHome empty does not launch Codex against an+ // ambient home: configureCodexTaskShellEnvironment rejects the empty+ // value ("task CODEX_HOME is missing") and the run fails before+ // launch. Decline the reuse instead, so the caller falls back to+ // Prepare and the task still gets a usable task-local home. The+ // prior session is not carried over, and a fresh Prepare that fails+ // the same way still stops the task.+ logger.Warn("execenv: refresh codex-home failed; forcing fresh prepare", "error", err)+ return nil} else {env.CodexHome = codexHomeif err := hydrateCodexSkills(codexHome, params.Task.AgentSkills, params.Task.DisabledRuntimeSkills, logger); err != nil {diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.goindex 4672ba7c17..d97885e189 100644--- a/server/internal/daemon/execenv/execenv_test.go+++ b/server/internal/daemon/execenv/execenv_test.go@@ -4239,8 +4239,8 @@ func TestResolveWindowsSandboxStateFailsClosed(t *testing.T) {// warned and returned success, so the task launched with the stale// danger-full-access — the decision failed closed while the effective config// failed open. prepareCodexHomeWithOpts must now return an error, which blocks-// startup on both paths (fresh Prepare fails the task; Reuse leaves-// env.CodexHome unset, which configureCodexTaskShellEnvironment refuses).+// startup on both paths (fresh Prepare fails the task; Reuse declines the+// reuse and falls back to Prepare, which re-runs this check on a fresh home).func TestPrepareCodexHomeFailsClosedWhenSandboxWriteFails(t *testing.T) {if os.Geteuid() == 0 {t.Skip("running as root bypasses the read-only permissions this test relies on")@@ -6925,6 +6925,27 @@ func TestClaimEnvRootRecoversOwnerTempLeftBeforeRename(t *testing.T) {}}+// TestReuseCodexRejectsUnusableHome pins the reuse contract for a task-local+// Codex home that cannot be prepared: Reuse must decline (return nil) so the+// caller falls back to Prepare, instead of handing back an environment with an+// empty CodexHome that only fails later at launch.+func TestReuseCodexRejectsUnusableHome(t *testing.T) {+ t.Setenv("CODEX_HOME", t.TempDir())+ root := t.TempDir()+ workDir := filepath.Join(root, "workdir")+ if err := os.MkdirAll(workDir, 0o755); err != nil {+ t.Fatal(err)+ }+ // A regular file blocks home preparation deterministically without relying+ // on permission checks or accessing a real Codex installation or account.+ if err := os.WriteFile(filepath.Join(root, codexHomeDirName), []byte("blocked"), 0o600); err != nil {+ t.Fatal(err)+ }+ if env := Reuse(ReuseParams{WorkDir: workDir, Provider: "codex"}, testLogger()); env != nil {+ t.Fatalf("unusable Codex home must decline reuse, got environment with CodexHome=%q", env.CodexHome)+ }+}+// TestReleaseLockFreesEnvRootForALaterDispatch pins the lifetime rule that// Windows CI surfaced: the lock belongs to the task EXECUTION, and nothing in// production calls Environment.Cleanup — the GC reclaims env roots on its own