fix(relay): clear stale cwd scope data

Signed-off-by: Alex Fournier <afournier@nvidia.com>
This commit is contained in:
Alex Fournier
2026-09-23 07:46:43 -04:00
parent 00c45c084d
commit d7c657bf3c
3 changed files with 33 additions and 7 deletions

View File

@@ -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,

View File

@@ -96,7 +96,10 @@ class TurnFacadeMixin:
conversation_history = admission.conversation_history
relay_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(),

View File

@@ -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(