From 4f134d4c377cf177530591bbcf43d54063b20be5 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 26 Sep 2026 20:41:11 +0530 Subject: [PATCH] fix(agent): always write the row when resetting the overload budget _reset_consecutive_overload_aborts skipped the DB write unless the in-memory count was armed (or settle=True). The in-memory count is not authoritative when two agents share a session: agent A can bump the row to 2 while agent B still holds 0, so B's summary success or runtime switch left A's streak alive and the next overload escalated early. Drop the settle parameter and always persist; one helper, one contract. --- agent/context_compressor.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index b9fd000545..547d6a9228 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -2371,12 +2371,12 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngin def _persist_consecutive_overload_aborts(self) -> None: self._durable_write("set_compression_overload_streak", "compression overload streak", self._consecutive_overload_aborts) - def _reset_consecutive_overload_aborts(self, *, settle: bool = False) -> None: - """Zero the sustained-overload budget, writing the row only when it was armed. ``settle`` - writes unconditionally: another agent on the session may have bumped the row since.""" - if settle or self._consecutive_overload_aborts: - self._consecutive_overload_aborts = 0 - self._persist_consecutive_overload_aborts() + def _reset_consecutive_overload_aborts(self) -> None: + """Zero the sustained-overload budget and ALWAYS write the row: the in-memory count is not + authoritative when two agents share a session, so skipping the write would let another + agent's streak survive a success or runtime switch.""" + self._consecutive_overload_aborts = 0 + self._persist_consecutive_overload_aborts() def _increment_consecutive_overload_aborts(self) -> None: """Count one overload abort. The bound row is bumped atomically and is authoritative, so two @@ -2462,7 +2462,7 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngin self._fallback_compression_streak = 0 self._persist_fallback_compression_streak() # Any completed boundary (incl. the degraded fallback) settles the overload budget (#123167). - self._reset_consecutive_overload_aborts(settle=True) + self._reset_consecutive_overload_aborts() def get_active_compression_failure_cooldown(self, *, refresh: bool = False) -> Optional[Dict[str, Any]]: """Return the live compression-failure cooldown for the bound session."""