The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): don't force a wire cap for explicit caller max_tokens
kshitijk4poor1564a9748ffc
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex ba0baa87401..e342c06c3be 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -9890,11 +9890,15 @@ def _call_llm_impl(tools=tools, timeout=effective_timeout, extra_body=effective_extra_body,reasoning_config=reasoning_config,base_url=_base_info or resolved_base_url, task=task)- if fast_compression_cap is not None:+ if fast_compression_cap is not None and max_tokens is None:# Normal auxiliary calls intentionally omit a cap on most# OpenAI-compatible/local providers. This is the narrow exception:# the configured compression route is concrete and certified# non-reasoning, so a bounded summary request is intentional.+ # ``max_tokens is None`` restricts the forced param to caps the+ # certified lane itself produced — an explicit caller max_tokens is+ # passed through untouched and keeps _build_call_kwargs's+ # provider-quirk handling (same guard as the fallback path).kwargs.update(auxiliary_max_tokens_param(fast_compression_cap, model=final_model))if extra_headers:kwargs["extra_headers"] = dict(extra_headers)diff --git a/tests/agent/test_fast_compression_lane.py b/tests/agent/test_fast_compression_lane.pyindex 8326dd66e75..920e248053e 100644--- a/tests/agent/test_fast_compression_lane.py+++ b/tests/agent/test_fast_compression_lane.py@@ -440,3 +440,38 @@ def test_timing_hooks_propagate_to_protected_call_worker_thread():assert result == "ok"assert "dispatch" in seenassert "response" in seen+++def test_explicit_caller_max_tokens_keeps_provider_quirk_handling():+ """An explicit caller cap must NOT be force-injected as a wire param.++ _build_call_kwargs deliberately omits max_tokens for most+ OpenAI-compatible providers (ZAI vision 400s on it; GPT-5/Copilot need+ max_completion_tokens). Only a cap the certified lane itself produced may+ bypass that handling. Before this guard, a caller-passed max_tokens on+ the compression task flowed through _compression_fast_lane_controls as a+ passthrough and was misread as a lane cap — forcing the param onto+ providers where the omission was intentional (pre-fast-lane behavior).+ """+ from agent.auxiliary_client import call_llm++ config = {"provider": "auto", "model": "", "max_output_tokens": 0}+ client = MagicMock()+ client.base_url = "http://127.0.0.1:11434/v1"+ response = object()+ client.chat.completions.create.return_value = response++ with (+ patch("agent.auxiliary_client._get_auxiliary_task_config", return_value=config),+ patch("agent.auxiliary_client._get_cached_client", return_value=(client, "qwen3:8b")),+ patch("agent.auxiliary_client._validate_llm_response", return_value=response),+ ):+ assert call_llm(+ task="compression",+ messages=[{"role": "user", "content": "summary request"}],+ max_tokens=1500,+ ) is response++ request = client.chat.completions.create.call_args.kwargs+ assert "max_tokens" not in request+ assert "max_completion_tokens" not in request