Skip to content

The agent that grows with you

refactor(agent): share one _is_refusal_response predicate across both summarizers

kshitijk4poorbc2373110c37
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index dac6082edc0..7f5f0199f1c 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -202,6 +202,15 @@ def _response_refusal_text(response: Any) -> str:
return refusal.strip() if isinstance(refusal, str) else ""
+def _is_refusal_response(response: Any, content: str) -> bool:
+ """Single refusal predicate for both summarizer paths.
+
+ An explicit provider ``message.refusal`` wins even when ``content`` looks like a
+ summary; otherwise fall back to the prose detector on the extracted content.
+ """
+ return bool(_response_refusal_text(response)) or _is_summary_refusal(content)
+
+
def _is_summary_access_or_quota_error(exc: Exception) -> bool:
"""Return True for non-retryable summary auth, permission, or quota errors."""
@@ -3633,7 +3642,7 @@ Summary generation was unavailable, so this is a best-effort deterministic fallb
# error, rather than replacing real context with an empty summary.
if not content.strip():
raise RuntimeError(f"Context compression LLM returned empty content {where}")
- if _response_refusal_text(response) or _is_summary_refusal(content):
+ if _is_refusal_response(response, content):
# Treat a refusal as unusable content. This deliberately reuses the
# established fallback/cooldown/abort path for an empty body, so it
# can never be committed as `_previous_summary`.
diff --git a/agent/micro_compaction.py b/agent/micro_compaction.py
index 0ae07ed361f..47456f9ee76 100644
--- a/agent/micro_compaction.py
+++ b/agent/micro_compaction.py
@@ -154,7 +154,7 @@ class MicroCompactionMixin:
if not content:
logger.info("micro-summarization returned empty content")
return None
- if _cc()._response_refusal_text(response) or _cc()._is_summary_refusal(content):
+ if _cc()._is_refusal_response(response, content):
logger.warning("micro-summarization returned refusal content — discarding unusable summary")
return None
return content