fix(tui): tolerate agents without session_cwd in _register_session_cwd; adapt stubs to the cwd kwarg

Workspace moves stamp agent.session_cwd so a lazily started Codex thread
starts in the moved-to directory. Agents that never had the attribute
(test doubles, slotted objects) must keep working, so stamp only when the
attribute exists. Test stubs of _set_session_context mirror the new cwd
kwarg, and the Codex gateway test asserts the contract (no pinned session
cwd) instead of the attribute's absence.
This commit is contained in:
teknium1
2026-09-15 22:04:13 -07:00
committed by Teknium
parent 3317b8c1e1
commit c2e5c94cd7
3 changed files with 4 additions and 4 deletions
@@ -346,7 +346,7 @@ class TestRunConversationCodexPath:
assert not client_mock.chat.completions.create.called
def test_gateway_terminal_cwd_seeds_codex_thread_cwd(self, monkeypatch, tmp_path):
"""Gateway sessions set TERMINAL_CWD without stamping agent.session_cwd.
"""Gateway sessions set TERMINAL_CWD without pinning agent.session_cwd.
Codex app-server must still start in that configured workspace instead
of falling back to the Hermes daemon process cwd."""
from agent.transports.codex_app_server_session import (
@@ -372,7 +372,7 @@ class TestRunConversationCodexPath:
monkeypatch.setattr(CodexAppServerSession, "run_turn", fake_run_turn)
agent = _make_codex_agent()
assert not hasattr(agent, "session_cwd")
assert agent.session_cwd is None
with patch.object(agent, "_spawn_background_review", return_value=None):
agent.run_conversation("hi")
@@ -274,7 +274,7 @@ def build_env(monkeypatch, tmp_path):
monkeypatch.setattr("hermes_state_registry.acquire", _factory)
for name, value in [
("_set_session_context", lambda _key: []),
("_set_session_context", lambda _key, cwd=None: []),
("_clear_session_context", lambda _tokens: None),
("_wire_callbacks", lambda _sid: None),
("_config_model_target", lambda: None),
+1 -1
View File
@@ -197,7 +197,7 @@ def _register_session_cwd(session: dict | None) -> None:
return
# Workspace moves must reach lazy/restarted runtimes, not just terminal tools.
# Do not reinitialize memory providers or invalidate the cached system prompt.
if (agent := session.get("agent")) is not None:
if hasattr(agent := session.get("agent"), "session_cwd"):
agent.session_cwd = session.get("cwd") or None
with contextlib.suppress(Exception):
from tools.terminal_tool import register_task_env_overrides