Skip to content

Commit 8d98b91

Browse files
authored
fix(codex): create CODEX_HOME before pinning it in the app-server env (#39)
1 parent edb49cb commit 8d98b91

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎src/coder_eval/agents/codex_agent.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,13 @@ def _build_codex_env(self) -> dict[str, str] | None:
10891089
# shell), which ignores HOME for dotfile selection when it is set.
10901090
env["HOME"] = str(self._login_shell_home)
10911091
env["ZDOTDIR"] = str(self._login_shell_home)
1092-
env["CODEX_HOME"] = str(self._codex_home())
1092+
# The binary hard-errors on an explicitly set CODEX_HOME that does
1093+
# not exist (unset, it materializes the ~/.codex default itself) —
1094+
# hosts that auth via CODEX_API_KEY never ran `codex login`, so
1095+
# the dir may not exist yet. Create it before pinning.
1096+
codex_home = self._codex_home()
1097+
codex_home.mkdir(parents=True, exist_ok=True)
1098+
env["CODEX_HOME"] = str(codex_home)
10931099
return env if env else None
10941100

10951101
@staticmethod

‎tests/test_codex_agent.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,20 @@ def test_build_codex_env_sets_home_and_pins_codex_home(self, monkeypatch, tmp_pa
17551755
# harness reads the same _codex_home() for sub-agent rollout recovery.
17561756
assert env["CODEX_HOME"] == str(agent._codex_home())
17571757

1758+
def test_build_codex_env_creates_missing_codex_home(self, monkeypatch, tmp_path):
1759+
"""The codex binary hard-errors on an explicitly set CODEX_HOME that
1760+
does not exist (unset, it materializes the ~/.codex default itself).
1761+
Runners that auth via CODEX_API_KEY never ran ``codex login``, so the
1762+
dir may not exist — pinning it must create it first."""
1763+
monkeypatch.delenv("CODEX_API_KEY", raising=False)
1764+
monkeypatch.setenv("CODEX_HOME", str(tmp_path / "state" / ".codex"))
1765+
agent = self._agent_with_prepend(["/sandbox/mocks"])
1766+
agent._login_shell_home = tmp_path / "login-home"
1767+
1768+
env = agent._build_codex_env()
1769+
assert env is not None
1770+
assert Path(env["CODEX_HOME"]).is_dir()
1771+
17581772
def test_build_codex_env_without_login_home_leaves_home_alone(self, monkeypatch):
17591773
monkeypatch.setenv("CODEX_API_KEY", "k")
17601774
agent = CodexAgent(parse_agent_config(type=AgentKind.CODEX))

0 commit comments

Comments
 (0)