Skip to content

The agent that grows with you

fix(context): assemble compaction head/tail from the pruned copy (#61932)

kshitijk4poorf6ce8bb23bef
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index c8c2709c5a3..93d26d00ecf 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -5489,18 +5489,18 @@ Write only the summary body. Do not include any preamble or prefix."""
)
# Phase 4: Assemble compressed message list
compressed = self._assemble_compressed(
- messages, compress_start, compress_end, scan, summary, source_messages=canonical_messages,
+ messages, compress_start, compress_end, scan, summary,
)
return self._finalize_compressed(compressed, canonical_messages, n_messages, spare_pending_images)
def _assemble_compressed(
self, messages: List[Dict[str, Any]], compress_start: int, compress_end: int,
- scan: "_HandoffScan", summary: str, *, source_messages: List[Dict[str, Any]] | None = None,
+ scan: "_HandoffScan", summary: str,
) -> List[Dict[str, Any]]:
- """Head + summary + tail; temporary prune copies never become durable rows."""
- source = source_messages if source_messages is not None else messages
- compressed = self._assemble_head(source, compress_start)
- tail_messages = self._assemble_tail(source, compress_end, scan.tail_start, scan.summary_indices)
+ """Head + summary + tail from the pruned copy: its tool-result demotions are what let an oversized
+ head/tail compress at all (#61932); tool-call arguments are never rewritten by pruning."""
+ compressed = self._assemble_head(messages, compress_start)
+ tail_messages = self._assemble_tail(messages, compress_end, scan.tail_start, scan.summary_indices)
summary_role, merge_into_tail, force_user_leading, first_tail_visible_idx = (
self._summary_placement(compressed, tail_messages, compress_start)
)
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 2f16c5cb607..50d7570015d 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -1049,7 +1049,7 @@ The value is the **first rung** of an escalating ladder, not a fixed interval: c
`idle_compact_after_seconds` is an **opt-in, time-based** trigger that complements the size-based `threshold`. Default `0` (disabled). When set above 0, a session that resumes after at least that many seconds of inactivity compacts its accumulated history up front, before the first reply — so a long-lived thread (e.g. a Telegram conversation you come back to hours later) doesn't re-read its full stale context on every subsequent turn. It never fires when the context is already at or below the post-compression target (`threshold × target_ratio`), and it honors the same failure-cooldown, anti-thrash, and per-session lock guards as every automatic compaction. Example: `idle_compact_after_seconds: 1800` compacts after 30 minutes idle.
-`proactive_prune_tokens` enables a deterministic, no-LLM prune of old tool-result payloads that runs independently of `threshold`. On large-window models the `threshold` compaction (≈50% of the window) rarely fires, so bulky tool outputs (terminal dumps, file reads, web extracts) ride along in history and get re-sent on every subsequent turn. When re-sent history exceeds `proactive_prune_tokens` (default `0` = off; try `48000` to enable), the prune dedupes identical results and summarizes older oversized tool results, protecting the most recent `protect_last_n` messages and never calling the model. Tool-call arguments are execution records and are never rewritten by pruning; the summary model has a separate bounded serializer for copies included in its prompt. The pressure pass likewise demotes tool-result bodies only. During full semantic compaction those demotions live only in the summarizer working copy: carried head/tail rows come from canonical history. The opt-in proactive prune still commits eligible tool-result-body demotions, so `proactive_prune_min_reclaim_tokens` (default `4096`) keeps those cache-breaking commits episodic; `proactive_prune_min_result_chars` (default `8000`, clamped to ≥ 200) sets the size below which a tool result is left untouched. This runs only under the built-in `compressor` engine; other context engines inherit a no-op.
+`proactive_prune_tokens` enables a deterministic, no-LLM prune of old tool-result payloads that runs independently of `threshold`. On large-window models the `threshold` compaction (≈50% of the window) rarely fires, so bulky tool outputs (terminal dumps, file reads, web extracts) ride along in history and get re-sent on every subsequent turn. When re-sent history exceeds `proactive_prune_tokens` (default `0` = off; try `48000` to enable), the prune dedupes identical results and summarizes older oversized tool results, protecting the most recent `protect_last_n` messages and never calling the model. Tool-call arguments are execution records and are never rewritten by pruning; the summary model has a separate bounded serializer for copies included in its prompt. The pressure pass likewise demotes tool-result bodies only. During full semantic compaction the carried head/tail rows keep those tool-result demotions (so an oversized tail can still compress), while tool-call arguments stay byte-exact. The opt-in proactive prune still commits eligible tool-result-body demotions, so `proactive_prune_min_reclaim_tokens` (default `4096`) keeps those cache-breaking commits episodic; `proactive_prune_min_result_chars` (default `8000`, clamped to ≥ 200) sets the size below which a tool result is left untouched. This runs only under the built-in `compressor` engine; other context engines inherit a no-op.
:::tip Gateway hot-reload of compression and context length
As of recent releases, editing `model.context_length` or any `compression.*` key in `config.yaml` on a running gateway takes effect on the next message — no gateway restart, no `/reset`, no session rotation required. The cached-agent signature includes these keys, so the gateway transparently rebuilds the agent when it sees a change. API keys and tool/skill config still require the usual reload paths.