A first stalled summary stream keeps today's behaviour: the transcript is left alone, the stall-class cooldown (floored at the idle window) is armed and the LLM route retries after it lapses. When the route stalls AGAIN while a stall-class failure is still on the ladder, the stall retry ladder now ends with a deterministic rung: the worker is re-run with the summary LLM skipped (DETERMINISTIC_SUMMARY_ROUTE pin, consumed in _summarize_window) and compress() commits its static fallback summary through the ordinary lease/fence/watermark pipeline — the same degrade a failed summary call gets (abort_on_summary_failure still aborts). WHY: after "made no progress … continuing without compression" the context stays oversized, so the next turn after the cooldown re-enters the same silent stream and burns another full idle window; the reporter saw this every ~2 min for hours (#112420). A route that has proven unhealthy twice must degrade once instead of looping. The prune-on-stall hunk from #112504 was declined because it committed outside the lease/fence; this rung reuses the same-turn fallback worker (bypass_cooldown) and the commit path the fallback_chain retry already uses, so no new commit surface is introduced. Also: a pinned fallback_chain route whose summary call FAILS still commits the static fallback summary (default abort_on_summary_failure=false); the host log said "recovered on fallback_chain[0]" for that. It now logs "committed a deterministic fallback summary on …" at WARNING (#112387 review caveat), keyed on the post-commit fallback_compression_streak bump. Docs: developer-guide failure-cooldown section + agent/AGENTS.md.
61 lines
2.9 KiB
Python
61 lines
2.9 KiB
Python
"""Summary-hook dispatch and cancellation rollback for context compression."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import inspect
|
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
|
|
|
from agent.auxiliary_client import AuxiliaryExplicitCancellation
|
|
|
|
if TYPE_CHECKING:
|
|
from agent.context_compressor import _HandoffScan
|
|
|
|
|
|
def _accepts_keyword_argument(callable_obj: Any, name: str) -> bool:
|
|
"""Return whether an inspectable callable accepts ``name`` as a keyword."""
|
|
try:
|
|
parameters = inspect.signature(callable_obj).parameters
|
|
except (TypeError, ValueError):
|
|
return False
|
|
if any(parameter.kind is inspect.Parameter.VAR_KEYWORD for parameter in parameters.values()):
|
|
return True
|
|
parameter = parameters.get(name)
|
|
return parameter is not None and parameter.kind in (
|
|
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
inspect.Parameter.KEYWORD_ONLY,
|
|
)
|
|
|
|
|
|
class SummaryDispatchMixin:
|
|
def _summarize_window(
|
|
self, messages: List[Dict[str, Any]], turns_to_summarize: List[Dict[str, Any]], scan: "_HandoffScan",
|
|
focus_topic: Optional[str], memory_context: str, bypass_cooldown: bool,
|
|
) -> Optional[str]:
|
|
"""Run the summary LLM; a cancellation rolls back the handoff scan's self-heal mutation first.
|
|
A deterministic pin (repeated stall, #112420) skips the LLM: ``None`` lets Phase 3 insert the static
|
|
fallback summary, or abort under ``abort_on_summary_failure`` exactly like a failed summary call."""
|
|
from agent.context_compressor import take_deterministic_summary_pin
|
|
if take_deterministic_summary_pin():
|
|
# Surfaces through the fallback summary's reason line and the host's one-shot user warning.
|
|
self._last_summary_error = (
|
|
"summary model stalled again after a stall backoff; deterministic fallback summary inserted"
|
|
)
|
|
telemetry = getattr(self, "_active_compression_telemetry", None)
|
|
if isinstance(telemetry, dict):
|
|
telemetry["failure_class"] = "stall_deterministic_fallback"
|
|
return None
|
|
# Focus-topic derivation scans user turns; only pay when a summary is generated.
|
|
summary_kwargs: Dict[str, Any] = {
|
|
"focus_topic": focus_topic or self._derive_auto_focus_topic(messages),
|
|
"memory_context": memory_context,
|
|
}
|
|
if _accepts_keyword_argument(self._generate_summary, "bypass_cooldown"):
|
|
summary_kwargs["bypass_cooldown"] = bypass_cooldown
|
|
try:
|
|
return self._generate_summary(turns_to_summarize, **summary_kwargs)
|
|
except AuxiliaryExplicitCancellation:
|
|
# Cancellation is a true no-op: restore the scan's mutation before the exception escapes.
|
|
self._previous_summary = scan.previous_summary_before
|
|
self._summary_has_user_turn = scan.has_user_turn_before
|
|
raise
|