fix(context): skip compaction when the window can't fit a summary request

When instructions, the reserved summary output, and any prior checkpoint
already consume the model's context window, the summary-input budget is
zero. Previously a doomed summary request was still submitted (and
rejected). Skip summarization in that case and log, rather than issue a
request guaranteed to overflow.
This commit is contained in:
Ahmed Allam
2026-07-25 23:46:27 +00:00
committed by Devin AI
parent 739e969914
commit dd35af6181
2 changed files with 41 additions and 11 deletions
+11 -5
View File
@@ -297,13 +297,19 @@ async def maybe_compact(
split = _select_split(model, items, context.keep_tokens)
head, recent = items[:split], items[split:]
if not head:
previous = _previous_summary(head)
input_budget = _summary_input_budget(model, previous)
if not head or input_budget <= 0:
# Nothing to summarise, or the window can't even fit the summary
# instructions plus the reserved output allowance — any request would
# be rejected, so skip rather than submit a doomed call.
if head:
logger.warning(
"skipping compaction for %s: no room to summarise within its context window", model
)
return False
previous = _previous_summary(head)
serialized_head = _fit_to_tokens(
model, _serialize_items(head), _summary_input_budget(model, previous)
)
serialized_head = _fit_to_tokens(model, _serialize_items(head), input_budget)
summary = await _summarize(
model,
_build_summary_prompt(serialized_head, previous),