Skip to content

The agent that grows with you

fix(compression): fallback/restore re-probe only refreshes an existing feasibility verdict

teknium1c97c7dbdb9ee
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index 69a919d6ae0..ac9a95bb42b 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -1173,8 +1173,10 @@ def restore_primary_runtime(agent) -> bool:
base_url=rt["compressor_base_url"], api_key=rt["compressor_api_key"],
provider=rt["compressor_provider"], api_mode=rt.get("compressor_api_mode", ""),
)
- from agent.conversation_compression import revalidate_compression_feasibility
- revalidate_compression_feasibility(agent)
+ # Same rule as fallback activation: refresh an existing verdict only; never-probed sessions stay lazy.
+ if getattr(agent, "_compression_feasibility_checked", False) is True:
+ from agent.conversation_compression import revalidate_compression_feasibility
+ revalidate_compression_feasibility(agent)
_rebind_primary_credential_pool(
agent, primary_provider, primary_model, _matches_primary, _load_primary_pool, prefetched_pool, prefetched
)
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index 1ca0fdeab0b..81a225f993a 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -1851,8 +1851,12 @@ def _update_fallback_context_compressor(agent) -> None:
model=agent.model, context_length=fb_context_length, base_url=agent.base_url,
api_key=getattr(agent, "api_key", ""), provider=agent.provider, api_mode=agent.api_mode,
)
- from agent.conversation_compression import revalidate_compression_feasibility
- revalidate_compression_feasibility(agent)
+ # Fallback activation is an error path: refresh an EXISTING verdict eagerly (the ceiling was voided by
+ # update_model()), but a session that never probed keeps its lazy compaction-time probe rather than
+ # resolving an auxiliary client while the primary route is failing (#114707).
+ if getattr(agent, "_compression_feasibility_checked", False) is True:
+ from agent.conversation_compression import revalidate_compression_feasibility
+ revalidate_compression_feasibility(agent)
def _reresolve_fallback_reasoning_config(agent) -> None:
diff --git a/tests/agent/test_compression_feasibility.py b/tests/agent/test_compression_feasibility.py
index e046a02b553..f79b333cb3a 100644
--- a/tests/agent/test_compression_feasibility.py
+++ b/tests/agent/test_compression_feasibility.py
@@ -107,6 +107,24 @@ def test_aux_sync_legacy_tail_follows_lowered_threshold():
assert compressor.tail_token_budget == int(compressor.threshold_tokens * compressor.summary_target_ratio)
+def test_fallback_activation_on_never_probed_session_stays_lazy():
+ """A session that never ran the feasibility probe does not resolve an auxiliary client while a
+ fallback is being activated; the compaction-time probe still owns the first verdict (#114707)."""
+ from agent.chat_completion_helpers import _update_fallback_context_compressor
+
+ agent = _make_agent(main_context=200_000)
+ agent.context_compressor = ContextCompressor(
+ "test-main-model", config_context_length=200_000, threshold_percent=0.50, quiet_mode=True,
+ )
+ agent._config_context_length = None
+ agent.model = "fallback-model"
+ with patch("agent.auxiliary_client.get_text_auxiliary_client") as aux_client, \
+ patch("agent.model_metadata.get_model_context_length", return_value=1_000_000):
+ _update_fallback_context_compressor(agent)
+ aux_client.assert_not_called()
+ assert getattr(agent, "_compression_feasibility_checked", False) is False
+
+
def test_fallback_activation_reprobes_aux_ceiling_and_keeps_it_durable():
"""Every main-runtime change re-probes the summariser and the clamp survives later window
corrections; a failed probe leaves the latch unset for the lazy compaction-time probe (#114707)."""