Skip to content

test(bedrock): make agentcore invocation tests hermetic after AWS MMDSv2 enforcement - #33280

Closed
mateo-berri wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_fix_agentcore_ci_tests
Closed

mateo-berri wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_fix_agentcore_ci_tests

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Before, captured at ce3bf2d839 (PR #33274): job 2089381 fails llm_translation_testing on the three test_bedrock_agentcore live tests, all raising

litellm.exceptions.BadRequestError: litellm.BadRequestError: BedrockException - b'{"fieldList":null,"message":"This runtime is not MMDSv2-enabled and can no longer be invoked. Enable MMDSv2 by calling UpdateAgentRuntime with requireMMDSV2=True in metadataConfiguration.","reason":null}'

This reproduces on every pipeline since 2026-07-14 17:44 UTC regardless of branch content (last green job 2087374 started 17:39 UTC, first red job 2087496 started 17:44 UTC; pipelines 87598 through 87638 all show the identical three failures). AWS now rejects invocations of AgentCore runtimes that do not have MMDSv2 enabled (AWS docs) and both hosted agent runtimes these tests invoke predate that requirement, so they are disabled server-side and no live invocation of them can succeed from any commit until they are updated in AWS

The after proof, captured at 87de8fd5cc, is therefore the llm_translation_testing check on this PR going green (job 2089721, success) while the same check is red on every other pipeline since 17:44 UTC. Full RCA with the first-red/last-green bisect and the runtime re-enable runbook: RCA - AWS MMDSv2 enforcement bricked the AgentCore CI runtimes

Type

✅ Test

Changes

AWS began enforcing MMDSv2 on Bedrock AgentCore runtimes, which turned the three tests in tests/llm_translation/test_bedrock_agentcore.py that live-invoke two hand-provisioned runtimes in the CI account into deterministic failures on every pipeline, blocking all PRs on a required check

This PR rewrites those three tests as mocked invocations that pin the same contract the live calls exercised: the request payload shape ({"prompt": ...}), SigV4 signing of the request, JSON and SSE response parsing on the sync completion path (including usage extraction from SSE metadata versus the token-counter fallback for JSON bodies), and SSE chunk assembly plus stop signaling on the async streaming path

It also makes test_bedrock_agentcore_without_api_key_uses_sigv4 deterministic. It previously took the Bearer path whenever AWS_BEARER_TOKEN_BEDROCK was set in the runner environment and its Authorization assertions sat inside an if, so it silently asserted nothing; it now clears that env var, passes static test credentials, and asserts the SigV4 signature unconditionally

Update: MMDSv2 has since been enabled on both runtimes via aws bedrock-agentcore-control update-agent-runtime and real litellm invocations of each (non-streaming and streaming) verified working again, so live coverage can be restored in a follow-up, ideally as a nightly/e2e job rather than a PR-gating check so provider-side lifecycle events cannot block merges again; details in the RCA linked above

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR converts three live Bedrock AgentCore invocation tests into hermetic mocked tests after AWS began enforcing MMDSv2 on the CI runtimes, making those tests fail deterministically on every pipeline.

  • test_bedrock_agentcore_basic is rewritten to parametrize over JSON and SSE response shapes, now asserting the request payload, SigV4 signature, response content, finish_reason, and token usage — substantially stronger than the original length-only check.
  • test_bedrock_agentcore_with_streaming gains concrete assertions on assembled chunk content, finish_reason, and that stream=True was passed; previously it only printed chunks.
  • test_bedrock_agentcore_without_api_key_uses_sigv4 fixes a silent no-op where SigV4 assertions were gated inside a conditional that could evaluate to false; monkeypatch.delenv and FAKE_AWS_CREDS make them unconditional.

Confidence Score: 4/5

Test-only change that strengthens coverage and removes live network dependencies — safe to merge.

The rewritten tests are meaningfully more rigorous than the originals: they now assert request shape, auth header format, response content, finish_reason, and token usage. The silent no-op in the SigV4 test is correctly fixed. Two small gaps remain: the AGENTCORE_SSE_BODY fixture omits the final double newline that SSE parsers need to dispatch the last event, and the async streaming path skips the SigV4 header assertion that the sync path includes. Neither gap masks a current regression.

tests/llm_translation/test_bedrock_agentcore.py — the SSE fixture terminator and the missing auth assertion in the async streaming test are worth a second look.

Important Files Changed

Filename Overview
tests/llm_translation/test_bedrock_agentcore.py Converts three live-invocation tests to hermetic mocked tests, adds SigV4 header assertions, and fixes a conditional-assertion bug; minor SSE fixture formatting gap and missing SigV4 check in the async streaming path.

Reviews (1): Last reviewed commit: "test(bedrock): make agentcore invocation..." | Re-trigger Greptile

Comment on lines +33 to +34
'data: {"message":{"role":"assistant","content":[{"text":"Machine learning is pattern matching at scale."}]}}\n'
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The last SSE event in AGENTCORE_SSE_BODY ends with a single instead of the required double `

. SSE parsers delimit events with a blank line (

), so this final {"message":...}event may never be dispatched andfinal_messageremainsNone`. The sync-path tests still pass because content is identically assembled from deltas, but the fixture silently diverges from what AWS actually emits.

Suggested change
'data: {"message":{"role":"assistant","content":[{"text":"Machine learning is pattern matching at scale."}]}}\n'
)
'data: {"message":{"role":"assistant","content":[{"text":"Machine learning is pattern matching at scale."}]}}\n\n'
)

Comment on lines +130 to +138
mock_post.assert_called_once()
assert mock_post.call_args.kwargs["stream"] is True
streamed_content = "".join(
chunk.choices[0].delta.content or "" for chunk in chunks if chunk.choices
)
assert streamed_content == AGENTCORE_ANSWER
assert any(
chunk.choices[0].finish_reason == "stop" for chunk in chunks if chunk.choices
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 test_bedrock_agentcore_with_streaming doesn't assert the Authorization header in the async streaming path. test_bedrock_agentcore_basic (sync path) checks "AWS4-HMAC-SHA256" in headers["Authorization"], but the async streaming path goes through a different code branch (AsyncHTTPHandler) and could regress to Bearer auth without this test catching it.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fix_agentcore_ci_tests (87de8fd) with litellm_internal_staging (477ef3a)

Open in CodSpeed

@mateo-berri

Copy link
Copy Markdown
Contributor Author

Closing without merge. The root cause was AWS-side (MMDSv2 disabled on the two CI runtimes) and both runtimes have since been updated with requireMMDSV2=true and verified with live invocations, so the existing tests pass again on their next VCR re-record and CI keeps its live coverage. Full RCA is linked in the PR description

@mateo-berri
mateo-berri deleted the litellm_fix_agentcore_ci_tests branch July 14, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant