Skip to content

The agent that grows with you

perf(agent,gateway): back cancel-wait polls off from 1ms to 25ms (re-review #5)

Teknium06bdc48c1ff4
diff --git a/agent/conversation_compression.py b/agent/conversation_compression.py
index 206fc663449..35430b1c792 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 e75d11b9404..345a69e100c 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