fix(compression): provider-proven overflow gets one real compaction attempt while the failure cooldown is armed

After one failed/stalled summary attempt arms the 60/300/900s compression-
failure cooldown, a provider context_length_exceeded rejection entered the
reactive overflow branch in conversation_loop, which called _compress_context
without force. Since #97488 the cooldown gate returns the soft "temporarily
paused, retry in a moment" deferral instead of exhaustion, so every turn
deferred until the cooldown lapsed, and the next failure extended the ladder:
long-running sessions wedged with no automatic recovery (#100661, four sessions
lost).

Thread a narrow `bypass_cooldown` kwarg from the three provider-proven overflow
call sites (generic overflow, 413, output-cap recovery) through
AIAgent._compress_context -> compress_context -> ContextCompressor.compress ->
_generate_summary. It skips ONLY the summary-failure cooldown check at each gate.
Unlike force=True it does not clear the cooldown, does not skip the feasibility /
anti-thrash breakers, and a failed attempt records its cooldown normally. The
attempt is bounded by the existing compression_attempts/max_compression_attempts
budget, so there is no retry loop. The preflight threshold gate is unchanged:
ordinary over-threshold pressure still honors the cooldown (#11529).

Engines whose _automatic_compression_blocked()/compress() predate the kwarg
(plugins, test doubles) are called with the legacy signature.

Tests: cooldown armed + bypass_cooldown -> summarizer invoked and transcript
compacted; ordinary pass still deferred. Docs note the cooldown/overflow
contract in the developer guide.

Fixes #100661
Closes #97766 (overflow-force idea; the bundled continuation changes were not taken)

Co-authored-by: sgtworkman <178342791+sgtworkman@users.noreply.github.com>
This commit is contained in:
Teknium
2026-09-02 04:51:44 -07:00
parent c7e2e0b779
commit d1efa0d78d
6 changed files with 163 additions and 10 deletions
+5 -1
View File
@@ -8546,6 +8546,7 @@ class AIAgent:
task_id: str = "default",
focus_topic: str = None,
force: bool = False,
bypass_cooldown: bool = False,
defer_context_engine_notification: bool = False,
commit_fence=None,
) -> tuple:
@@ -8554,7 +8555,9 @@ class AIAgent:
``force=True`` is passed by the manual ``/compress`` slash command
so users can bypass the summary-failure cooldown after an
auto-compress abort. Auto-compress callers use the default
``force=False``.
``force=False``. ``bypass_cooldown=True`` is passed by the
provider-proven overflow recovery path so one real attempt runs while
the cooldown is armed (#100661) — without clearing it.
"""
# Per-attempt signal consumed by turn-start preflight (#98424) and the
# in-loop pre-API/overflow consumers. A stalled compression must not
@@ -8635,6 +8638,7 @@ class AIAgent:
approx_tokens=approx_tokens, task_id=task_id,
focus_topic=focus_topic,
force=force,
bypass_cooldown=bypass_cooldown,
defer_context_engine_notification=(
defer_context_engine_notification
),