From 8b58f9f68f01a96f101366b6b9a98dbd341db301 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 15 Aug 2026 12:43:49 +0530 Subject: [PATCH] test(bedrock): pin stream-path cap omission; document truthiness edge Self-review follow-up: cover call_converse_stream's max_tokens=None path (same builder, previously unpinned) and document why the shim reads the caller cap with truthiness rather than 'is None' (parity with the Anthropic shim's reading). --- agent/auxiliary_client.py | 3 +++ tests/agent/test_bedrock_adapter.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 0f163f38ef..d49a797ed8 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -2218,6 +2218,9 @@ class _BedrockCompletionsAdapter: # allowed output, matching the no-cap-by-default policy every # other aux wire already follows (#10809: vision descriptions # stayed capped at the shim's old hardcoded 4096 on Bedrock). + # Truthiness (not `is None`) is deliberate — it matches the + # sibling Anthropic shim's reading of max_tokens above, so a + # nonsense explicit 0 is treated as "no cap" on both wires. max_tokens=int(max_tokens) if max_tokens else None, temperature=kwargs.get("temperature"), top_p=kwargs.get("top_p"), diff --git a/tests/agent/test_bedrock_adapter.py b/tests/agent/test_bedrock_adapter.py index 8d6acf2ede..e6c2c3c3c4 100644 --- a/tests/agent/test_bedrock_adapter.py +++ b/tests/agent/test_bedrock_adapter.py @@ -423,6 +423,27 @@ class TestBuildConverseKwargs: ) assert "inferenceConfig" not in kwargs + def test_call_converse_stream_omits_cap_for_none(self): + """The streaming entry point funnels through the same builder — pin + that max_tokens=None omits the cap there too.""" + from unittest.mock import MagicMock, patch as mock_patch + from agent.bedrock_adapter import call_converse_stream + boto3_client = MagicMock() + boto3_client.converse_stream.return_value = {"stream": []} + with mock_patch( + "agent.bedrock_adapter._get_bedrock_runtime_client", + return_value=boto3_client, + ): + call_converse_stream( + region="us-east-1", + model="test-model", + messages=[{"role": "user", "content": "Hi"}], + max_tokens=None, + temperature=0.2, + ) + wire_kwargs = boto3_client.converse_stream.call_args.kwargs + assert "maxTokens" not in wire_kwargs.get("inferenceConfig", {}) +