Skip to content

The agent that grows with you

fix(gateway): deliver Stop to the resident running agent

David Dudok de Wit55821ee26ce8
diff --git a/gateway/session_authority.py b/gateway/session_authority.py
index f937012635c..332dc632f42 100644
--- a/gateway/session_authority.py
+++ b/gateway/session_authority.py
@@ -122,7 +122,8 @@ class SessionAuthority:
return SessionRef(self.profile_id, sid)
def agent(self, ref):
- return self.runner._cached_agent_for(self.sessions[ref.session_id].route)
+ lookup = getattr(self.runner, '_resident_agent_for', None) or self.runner._cached_agent_for
+ return lookup(self.sessions[ref.session_id].route)
def _handle(self, ref):
row = self.db.get_session(ref.session_id)
diff --git a/tests/gateway/test_authority_resident_stop.py b/tests/gateway/test_authority_resident_stop.py
new file mode 100644
index 00000000000..10155421923
--- /dev/null
+++ b/tests/gateway/test_authority_resident_stop.py
@@ -0,0 +1,28 @@
+"""Authority Stop must reach a running agent after its reusable cache entry is evicted."""
+from types import SimpleNamespace
+
+import pytest
+
+from hermes_state_runtime import admit_session_input, claim_session_input
+from tests.gateway.test_reaped_eviction_interrupts_run import _build_gateway, KEY
+from tests.gateway.test_session_authority_cancel_settlement import _authority, ACTOR, REF
+
+
+async def test_stop_reaches_resident_agent_after_real_cache_eviction(tmp_path, monkeypatch):
+ db, authority = _authority(tmp_path, monkeypatch)
+ calls = []
+ agent = SimpleNamespace(interrupt=lambda: calls.append('stop'))
+ runner, state = _build_gateway(agent, [])
+ authority.runner = runner
+ authority.sessions['s'].route = KEY
+ with db:
+ admit_session_input(db, epoch=authority.epoch, principal_id=ACTOR.subject, session_id='s',
+ request_id='running', payload={'text':'work'})
+ row = claim_session_input(db, epoch=authority.epoch, session_id='s')
+ runner._evict_cached_agent(KEY)
+ assert runner._cached_agent_for(KEY) is None
+ assert runner._resident_agent_for(KEY) is agent
+ await authority.interrupt(ACTOR, REF, row['generation'])
+ assert calls == ['stop']
+ assert not authority.pending_stops