Skip to content

The agent that grows with you

fix(gateway): a removed workspace refuses the turn, not every read of the chat

Teknium4ff909491b68
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index 08c3d23a301..eb31fd2f683 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -582,7 +582,6 @@ def restore_policy(data):
if ((not is_forward_policy(policy) and
(policy.source not in surfaces or policy.platform != surfaces[policy.source]))
or not isinstance(policy.cwd, str) or not Path(policy.cwd).is_absolute()
- or not Path(policy.cwd).is_dir()
or not isinstance(policy.model, str) or not policy.model.strip()
or not isinstance(policy.toolsets, (list, tuple))
or any(not isinstance(name, str) for name in policy.toolsets)
@@ -622,6 +621,10 @@ def policy_scope(policy, *, authority=None):
if policy is None:
yield
return
+ # Readiness, not structure: a removed workspace keeps the chat readable and movable, but no
+ # turn runs in a missing directory.
+ if not Path(policy.cwd).is_dir():
+ raise RuntimeStoreError('workspace_unavailable')
from agent.runtime_cwd import set_session_cwd
from tools.terminal_scope import set_terminal_scope, reset_terminal_scope
terminal = json.loads(policy.terminal_json)
diff --git a/tests/gateway/test_session_policy_workspace_readiness.py b/tests/gateway/test_session_policy_workspace_readiness.py
new file mode 100644
index 00000000000..2b407b16abe
--- /dev/null
+++ b/tests/gateway/test_session_policy_workspace_readiness.py
@@ -0,0 +1,27 @@
+"""A removed workspace keeps a local chat readable and movable; only a turn refuses (N87)."""
+import pytest
+
+
+async def test_removed_workspace_reads_and_moves_but_refuses_a_turn(tmp_path, monkeypatch):
+ from gateway.session_policy import policy_for_source, policy_scope
+ from hermes_state_runtime import RuntimeStoreError
+ from tests.gateway.test_session_policy_verbs import _mutation, _owner
+
+ store, db, authority, owner, ref = _owner(tmp_path, monkeypatch, None)
+ target = tmp_path / 'project-b'
+ target.mkdir()
+ try:
+ (tmp_path / 'project-a').rmdir() # git worktree remove / deleted scratch folder
+ resumed = await owner.dispatch({'id': 1, 'method': 'session.resume',
+ 'params': {'session_id': ref.session_id}})
+ assert 'result' in resumed, resumed
+ policy = policy_for_source(authority.runner, authority.sessions[ref.session_id].source)
+ with pytest.raises(RuntimeStoreError, match='workspace_unavailable'):
+ with policy_scope(policy, authority=authority):
+ pass
+ moved = await owner.dispatch(_mutation(db, ref, 'mv', 'workspace', {'cwd': str(target)}))
+ assert moved['result']['cwd'] == str(target), moved
+ finally:
+ await owner.close()
+ store.close_all_db_handles()