From 761a0b124eedac716c9875347b8f36117a76251f Mon Sep 17 00:00:00 2001 From: Enzo Adami Date: Wed, 1 Jul 2026 11:05:35 -0400 Subject: [PATCH] fix: ground compression task snapshot --- agent/context_compressor.py | 71 ++++++++++++++++++++++---- tests/agent/test_context_compressor.py | 40 +++++++++++++++ 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index f94285663b26..98947b6c110d 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -299,6 +299,7 @@ _FALLBACK_TURN_MAX_CHARS = 700 _AUTO_FOCUS_MAX_TURNS = 3 _AUTO_FOCUS_TURN_MAX_CHARS = 260 _AUTO_FOCUS_MAX_CHARS = 700 +_ACTIVE_TASK_MAX_CHARS = 1400 # Keep a short run of recent messages verbatim even when the token budget is # already exhausted. The public ``protect_last_n`` default is intentionally # high for small/light tails, but using all 20 as a hard floor here would bring @@ -322,6 +323,9 @@ _PATH_MENTION_RE = re.compile(r"(?:/|~/?|[A-Za-z]:\\)[^\s`'\")\]}<>]+") # the summary, the downstream model may re-emit it as an active directive on # the next turn, triggering bogus attachment sends (#14665). _MEDIA_DIRECTIVE_RE = re.compile(r"MEDIA:\S+") +_HISTORICAL_TASK_SECTION_RE = re.compile( + rf"(?ms)^{re.escape(HISTORICAL_TASK_HEADING)}\s*\n.*?(?=^## |\Z)" +) def _dedupe_append(items: list[str], value: str, *, limit: int) -> None: @@ -2146,9 +2150,9 @@ Summary generation was unavailable, so this is a best-effort deterministic fallb _template_sections = f"""{HISTORICAL_TASK_HEADING} [THE SINGLE MOST IMPORTANT FIELD. Capture the user's most recent unfulfilled input verbatim — the exact words they used. This includes: -- Explicit task assignments ("refactor the auth module") -- Questions awaiting an answer ("waarom staat X op Y?", "wat zijn de volgende stappen?") -- Decisions awaiting input ("optie A of B?") +- Explicit task assignments ("") +- Questions awaiting an answer ("") +- Decisions awaiting input ("