Skip to content

The agent that grows with you

fix(compression): release idle-timeout lease promptly

fangliquanflqc0787c8ec1e9
diff --git a/gateway/run.py b/gateway/run.py
index 293010310d5..2a6a54f96cd 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -20865,9 +20865,12 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
# successful compaction as a timeout.
_compressed, _ = await _hyg_future
else:
- # Cleanup follows worker completion;
- # its holder-qualified lease remains
- # live until then to exclude retries.
+ # Release an inactivity-timed-out
+ # worker's holder-qualified lease
+ # promptly. Total-ceiling attempts
+ # retained it above, so this is a
+ # no-op until worker cleanup there.
+ _hyg_commit_fence.release_cancelled_compression_lock()
self._defer_agent_cleanup_until_future_done(
_hyg_future,
_hyg_agent,
diff --git a/tests/gateway/test_session_hygiene.py b/tests/gateway/test_session_hygiene.py
index bac5b3ea26b..f09b1e60c99 100644
--- a/tests/gateway/test_session_hygiene.py
+++ b/tests/gateway/test_session_hygiene.py
@@ -506,6 +506,7 @@ async def test_session_hygiene_timeout_continues_to_agent_and_sets_cooldown(monk
worker_started = threading.Event()
release_worker = threading.Event()
+ lease_released = threading.Event()
cleanup_done = threading.Event()
fake_db = MagicMock()
# The DB-backed cooldown check calls this before compressing; a bare
@@ -531,8 +532,10 @@ async def test_session_hygiene_timeout_continues_to_agent_and_sets_cooldown(monk
def _compress_context(
self, messages, *_args, commit_fence=None, **_kwargs
):
+ if commit_fence is not None:
+ commit_fence.register_cancelled_lock_release(lease_released.set)
worker_started.set()
- assert release_worker.wait(timeout=2)
+ assert release_worker.wait(timeout=10)
if commit_fence is not None and not commit_fence.begin_commit():
return (messages, None)
try:
@@ -630,8 +633,9 @@ async def test_session_hygiene_timeout_continues_to_agent_and_sets_cooldown(monk
timeout_warnings = [s for s in adapter.sent if "Context compression timed out" in s["content"]]
assert len(timeout_warnings) == 1
fake_db.archive_and_compact.assert_not_called()
+ assert lease_released.is_set()
# Event/state assertions prove the host returned before the detached
- # worker's two-second wait completed without a scheduler-sensitive clock
+ # worker's event-gated wait completed without a scheduler-sensitive clock
# bound: cleanup runs only when that worker actually exits.
SlowCompressAgent.last_instance.close.assert_not_called()