The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(relay): clear stale cwd scope data
Alex Fournierd7c657bf3c95
diff --git a/agent/relay_runtime.py b/agent/relay_runtime.pyindex 5434cbe4a53..8981001c1bc 100644--- a/agent/relay_runtime.py+++ b/agent/relay_runtime.py@@ -445,8 +445,8 @@ class RelayRuntime:with session.lock:if session.closing:return None- if isinstance(cwd, str) and cwd.strip():- session.cwd = cwd.strip()+ if cwd is not None:+ session.cwd = _scope_input(cwd).get("cwd", "")if session.handle is None:self._open_session_scope(session, {**(metadata or {}), **runtime_metadata(self.runtime_id)},@@ -950,12 +950,15 @@ class RelaySessionCoordinator:"parent_session_id": parent_session_id, "model": model, "cwd": session_cwd,}session = _warn_on_error("conversation initialization", self._open_conversation_session, host, context)- effective_turn_cwd = (- _scope_input(turn_cwd).get("cwd") or _scope_input(session_cwd).get("cwd") or ""- )- if not effective_turn_cwd and session is not None:+ if turn_cwd is not None:+ effective_turn_cwd = _scope_input(turn_cwd).get("cwd", "")+ elif session_cwd is not None:+ effective_turn_cwd = _scope_input(session_cwd).get("cwd", "")+ elif session is not None:with session.lock:effective_turn_cwd = session.cwd+ else:+ effective_turn_cwd = ""return ConversationLease(profile_key=profile_key, session_id=session_id, platform=platform, host=host,session=session, parent_session_id=parent_session_id, turn_cwd=effective_turn_cwd,diff --git a/agent/turn_facade.py b/agent/turn_facade.pyindex 67a2834d4fa..3c901a41cb9 100644--- a/agent/turn_facade.py+++ b/agent/turn_facade.py@@ -96,7 +96,10 @@ class TurnFacadeMixin:conversation_history = admission.conversation_historyrelay_session_cwd, relay_turn_cwd = resolve_relay_scope_cwds(- self, effective_task_id, session_id, task_context["platform"]+ self,+ effective_task_id,+ task_context["session_id"],+ task_context["platform"],)relay_lease = relay_runtime.SESSION_COORDINATOR.acquire_conversation(profile_key=relay_runtime.current_profile_key(),diff --git a/tests/agent/test_relay_session_segments.py b/tests/agent/test_relay_session_segments.pyindex 9287d6141aa..72feeb06f2b 100644--- a/tests/agent/test_relay_session_segments.py+++ b/tests/agent/test_relay_session_segments.py@@ -297,6 +297,26 @@ class TestCwdProjection:assert fake.scope.pushes[-1]["input"] == {"cwd": "/workspace/next-task"}coordinator.end_turn(turn, outcome="success")+ def test_explicit_unknown_cwd_clears_prior_scope_input(self, coordinator):+ fake = _FakeRelay()+ runtime = _make_runtime(fake)+ lease = _acquire(+ coordinator, runtime,+ session_cwd="/workspace/session", turn_cwd="/workspace/task",+ )+ coordinator.end_turn(+ coordinator.begin_turn(lease, turn_id="t1", task_id="task1"),+ outcome="success",+ )++ lease = _acquire(coordinator, runtime, session_cwd="", turn_cwd="")+ runtime.rotate_session_scope(lease.session, reason="compaction")+ turn = coordinator.begin_turn(lease, turn_id="t2", task_id="task2")++ assert _session_pushes(fake)[-1]["input"] == {}+ assert fake.scope.pushes[-1]["input"] == {}+ coordinator.end_turn(turn, outcome="success")+class TestCompactionRotation:def test_compaction_rotates_at_next_begin_turn_not_immediately(