Skip to content

The agent that grows with you

fix(agent): a managed worker's lease refresh accepts the refresher's patience

Teknium315ce9a4124f
diff --git a/agent/runtime_session_store.py b/agent/runtime_session_store.py
index b4053951858..db6e7d4a50f 100644
--- a/agent/runtime_session_store.py
+++ b/agent/runtime_session_store.py
@@ -275,7 +275,7 @@ class RuntimeSessionStore(RuntimeSessionCompressionMixin, RuntimeSessionLifecycl
should_abort=should_abort, acquire_patience_s=acquire_patience_s,
on_contended=on_contended)
- def refresh_session_turn_lease(self, session_id, holder, *, ttl_seconds=300.0):
+ def refresh_session_turn_lease(self, session_id, holder, *, ttl_seconds=300.0, patience_s=None):
self._session(session_id)
return self._apply('turn.renew', {'holder': holder, 'ttl_seconds': ttl_seconds})['value']
diff --git a/tests/agent/test_runtime_session_store_lease_refresh.py b/tests/agent/test_runtime_session_store_lease_refresh.py
new file mode 100644
index 00000000000..4310d07ebcd
--- /dev/null
+++ b/tests/agent/test_runtime_session_store_lease_refresh.py
@@ -0,0 +1,28 @@
+"""A managed worker's turn lease survives its periodic refresh (the store is the agent's session_db)."""
+import time
+from types import SimpleNamespace
+
+from agent.runtime_session_store import RuntimeSessionStore
+from agent.turn_facade_lease import LEASE_TTL_SECONDS, DurableTurnLease
+
+
+def test_managed_worker_turn_survives_lease_refresh_tick(tmp_path):
+ sent = []
+
+ def rpc(method, **params):
+ sent.append((method, params['operation'], params['payload']))
+ return {'value': True}
+
+ store = RuntimeSessionStore(rpc, {'session_id': 's'}, tmp_path / 'private')
+ interrupts = []
+ agent = SimpleNamespace(session_id='s', interrupt=lambda message, **kwargs: interrupts.append(message))
+ lease = DurableTurnLease(agent, store, 's', 'holder', expires_at=time.time() + LEASE_TTL_SECONDS)
+ lease.turn_active = True
+ try:
+ before = lease._authority_deadline
+ assert lease.refresh_tick() is None
+ assert interrupts == [] and lease.interrupt_message is None
+ assert sent == [('worker.persist', 'turn.renew', {'holder': 'holder', 'ttl_seconds': LEASE_TTL_SECONDS})]
+ assert lease._authority_deadline >= before
+ finally:
+ store.close()