From 06bdc48c1ff4f2d9c4cce50dc2804fa6ade9e69e Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 2 Aug 2026 15:33:17 -0700 Subject: [PATCH] perf(agent,gateway): back cancel-wait polls off from 1ms to 25ms (re-review #5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fence-cancel poll loops (sync host wait in conversation_compression, async hygiene wait in gateway/run) spun at 1kHz while the worker held the fence through its lock-setup window — which rides SessionDB write patience and can last seconds. 25ms keeps sub-tick cancel latency without the spin. --- agent/conversation_compression.py | 7 ++++++- gateway/run.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py index 206fc66344..35430b1c79 100644 --- a/agent/conversation_compression.py +++ b/agent/conversation_compression.py @@ -972,7 +972,12 @@ def run_compress_context_with_progress_timeout( break cancelled = fence.try_cancel_before_commit() if cancelled is None: - time.sleep(0.001) + # Round-2 #5: the fence is only held transiently here (lock + # setup / cancel admission — an in-flight commit is caught by + # the commit_in_flight check above), but that window rides + # SessionDB write patience and can last seconds. 25ms keeps + # sub-tick latency without a 1kHz spin. + time.sleep(0.025) if not cancelled: # Pre-commit ceiling already elapsed, but begin_commit() won the # race. Waiting is intentional: SessionDB mutation cannot be diff --git a/gateway/run.py b/gateway/run.py index e75d11b940..345a69e100 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -16747,7 +16747,12 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew _hyg_commit_fence.try_cancel_before_commit() ) if _cancelled is None: - await asyncio.sleep(0.001) + # Round-2 #5: transient + # lock-setup windows ride + # write patience for seconds; + # 25ms keeps sub-tick latency + # without 1kHz spin. + await asyncio.sleep(0.025) if not _cancelled: # The worker crossed the commit boundary just # before the timeout. The fence poll waited for