Skip to content

The agent that grows with you

fix(compression): contain drifted fast controls

Mike DeMott7568dd551b59
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 40245874dd0..03b6e9a7fe0 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -2377,7 +2377,7 @@ class _BedrockCompletionsAdapter:
"stream); caller downgrades to non-streaming.",
model,
)
- return call_converse(
+ response = call_converse(
region=self._region,
model=model,
messages=messages,
@@ -2395,6 +2395,11 @@ class _BedrockCompletionsAdapter:
top_p=kwargs.get("top_p"),
stop_sequences=stop,
)
+ # Converse is a complete-response API in this shim. Mark provider
+ # progress only after the response returns so TTFP reflects real
+ # Bedrock latency rather than dispatch/setup activity.
+ _notify_aux_provider_response()
+ return response
class _BedrockChatShim:
@@ -9803,6 +9808,18 @@ def _call_llm_impl(
if fast_compression_lane is not None and max_tokens is None
else None
)
+ if (
+ task == "compression"
+ and fast_compression_lane is not None
+ and not fast_compression_lane.certified_non_reasoning
+ and _compression_config_claims_fast_lane(
+ _get_auxiliary_task_config("compression")
+ )
+ ):
+ # A concrete fast-only route was requested but Hermes resolved a
+ # different provider/model. Its non-reasoning control is no safer to
+ # inherit than its cap. Auto/inherited config never enters this branch.
+ effective_extra_body.pop("reasoning", None)
_set_relay_auxiliary_route(
request_provider,
final_model,
diff --git a/tests/agent/test_fast_compression_lane.py b/tests/agent/test_fast_compression_lane.py
index 6f2840b16b7..689b6986380 100644
--- a/tests/agent/test_fast_compression_lane.py
+++ b/tests/agent/test_fast_compression_lane.py
@@ -216,6 +216,50 @@ def test_uncertified_effective_primary_route_does_not_receive_fast_cap():
request = client.chat.completions.create.call_args.kwargs
assert "max_tokens" not in request
assert "max_completion_tokens" not in request
+ assert "reasoning" not in request.get("extra_body", {})
+
+
+def test_bedrock_converse_ttfp_waits_for_the_nonstreaming_response():
+ from agent.auxiliary_client import BedrockAuxiliaryClient, call_llm
+
+ config = {
+ "provider": "auto",
+ "model": "",
+ "max_output_tokens": 0,
+ }
+ client = BedrockAuxiliaryClient("us-east-1", "amazon.nova-lite-v1:0")
+ response = SimpleNamespace(
+ choices=[
+ SimpleNamespace(
+ message=SimpleNamespace(content="summary"),
+ finish_reason="stop",
+ )
+ ],
+ usage=None,
+ )
+ timings = {}
+
+ def _delayed_converse(**_kwargs):
+ time.sleep(0.02)
+ return response
+
+ with (
+ patch("agent.auxiliary_client._get_auxiliary_task_config", return_value=config),
+ patch(
+ "agent.auxiliary_client._get_cached_client",
+ return_value=(client, "amazon.nova-lite-v1:0"),
+ ),
+ patch("agent.bedrock_adapter.call_converse", side_effect=_delayed_converse),
+ ):
+ assert call_llm(
+ task="compression",
+ messages=[{"role": "user", "content": "summary request"}],
+ latency_info=timings,
+ ) is response
+
+ assert timings["provider_dispatch_ms"] >= 0
+ assert timings["time_to_first_progress_ms"] >= 15
+ assert timings["time_to_first_progress_ms"] >= timings["provider_dispatch_ms"]
def test_summary_model_override_cap_uses_the_actual_primary_request():