From 58391436f76a9f1003dd6df819f0852323e632c0 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 20 Jul 2026 03:55:29 -0700 Subject: [PATCH] fix: reconcile probe cache with stale-entry invalidation + stale test fixtures - The #44861 stale-cache guard invalidated any cached value that differed from the static table, which would have discarded legitimate probe-derived windows larger than the table. Treat the table as a FLOOR: only drop under-reporting cache entries. - Update probe test fixtures that predated the 4.6+ 1M table flip (opus-4-6 fallback expectations 200K -> 1M). --- agent/model_metadata.py | 8 ++++++-- tests/agent/test_bedrock_adapter.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/agent/model_metadata.py b/agent/model_metadata.py index bd3505c251d32..50e78a8868fd5 100644 --- a/agent/model_metadata.py +++ b/agent/model_metadata.py @@ -2250,12 +2250,16 @@ def get_model_context_length( ) # Fall through; step 5b reconciles and overwrites if portal responds. # Invalidate stale Bedrock entries seeded before the Claude 4.6+ - # long-context table was corrected to 1M. + # long-context table was corrected to 1M. The static table is a + # FLOOR, not an override: probe-derived cache entries (step 1b) + # may legitimately exceed the table (real window read from + # Bedrock's length-validation error), so only under-reporting + # entries are dropped — never a cached value above the table. elif is_bedrock_context: try: from agent.bedrock_adapter import get_bedrock_context_length bedrock_ctx = get_bedrock_context_length(model) - if cached != bedrock_ctx: + if cached < bedrock_ctx: logger.info( "Dropping stale Bedrock cache entry %s@%s -> %s; " "using static Bedrock table value %s", diff --git a/tests/agent/test_bedrock_adapter.py b/tests/agent/test_bedrock_adapter.py index 56b99838d0bed..97c6d43689e9e 100644 --- a/tests/agent/test_bedrock_adapter.py +++ b/tests/agent/test_bedrock_adapter.py @@ -1244,7 +1244,7 @@ class TestBedrockContextLength: # still invoke get_bedrock_context_length(model_id) with one arg. from agent.bedrock_adapter import get_bedrock_context_length with patch("agent.bedrock_adapter.probe_bedrock_context_length") as mock_probe: - assert get_bedrock_context_length("anthropic.claude-opus-4-6") == 200_000 + assert get_bedrock_context_length("anthropic.claude-opus-4-6") == 1_000_000 mock_probe.assert_not_called() @@ -1299,9 +1299,9 @@ class TestBedrockContextProbe: err = "AccessDeniedException: nope" with patch("agent.bedrock_adapter._get_bedrock_runtime_client", return_value=self._client_raising(err)): - # opus-4-6 is in the table at 200K; probe fails → table wins. + # opus-4-6 is in the table at 1M; probe fails → table wins. assert get_bedrock_context_length( - "anthropic.claude-opus-4-6", region="eu-central-1") == 200_000 + "anthropic.claude-opus-4-6", region="eu-central-1") == 1_000_000 # ---------------------------------------------------------------------------