Repository navigation
fix(headers): merge tracking headers regardless of casing - #7471
Draft
BlueRaddish wants to merge 1 commit into
Draft
BlueRaddish wants to merge 1 commit into
BlueRaddish wants to merge 1 commit into
Conversation
Merge every case variant of the two tracking fields without losing custom tokens. Let MCP use the shared merge instead of collapsing aliases first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Problem:
merge_tracking_headerslooks up tracking header names using lowercase dictionary keys. A caller supplyingUser-AgentorX-Goog-Api-Clienttherefore gets its custom field plus a second lowercase field containing the ADK tokens. A realhttpx.Requestcarries two values for each affected HTTP field.Reproduction on base
7d8c9502f924ed5e7a1ab00dc1f5a603e858abc3: merge{"User-Agent": "custom-client/1", "X-Goog-Api-Client": "custom-sdk/1"}, then create anhttpx.Requestwith those headers.request.headers.get_list("user-agent")returns the custom value and a separate ADK tracking value. Expected: one merged field preserving both sets of tokens.Solution: Merge custom tokens from every casing variant of the two tracking fields into one canonical field, avoiding duplicate tokens. Keep unrelated header spelling and leave the input dictionary unchanged. Remove the MCP caller's redundant casing normalization, which otherwise discards an earlier variant before the shared helper can preserve it.
Testing Plan
Unit Tests:
sh pytest tests/unittests/utils/test_google_client_headers.py tests/unittests/utils/test_client_labels_utils.py tests/unittests/tools/mcp_tool/test_mcp_session_manager.py -qManual End-to-End (E2E) Tests: The regression tests construct real
httpx.Requestobjects with the merged headers and check that each tracking field reaches the transport once, with the custom tokens retained. Real Google GenAI types are used; no model, network request, or service mock is involved.A separate focused header-flow check executes the exact AST-extracted production MCP
_merge_headersmethod with the real shared helper and HTTPX. The base method loses the earlier custom tokens; the revised method preserves both variants and unrelated-header override behavior. This check uses plain connection-parameter values and does not establish complete MCP integration coverage.Checklist
Additional context
No signatures, dependencies, authentication behavior, or unrelated headers change. Normal repository pre-commit hooks pass in the existing native Linux environment, including Ruff, isort, Pyink, compliance, license, private-module, documentation, and spelling checks. The hook formatter only adds one blank line before an adjacent top-level MCP function. git diff --check passes. Current main still has all affected source/test blobs unchanged; complete matching PR diffs were checked and none supersede this fix.
Full repository, service-backed MCP integration, and multi-version tox suites were not run; the contribution guide calls for full multi-version tox before review. Focused tests use actual production modules and supported MCP dependencies, with existing MCP test mocks. The real HTTPX transport representation is checked without a remote service or model call.
Prepared with assistance from OpenAI Codex.