Skip to content

fix(auth): use branch-scoped events for auth responses#5982

Open
gezw wants to merge 1 commit into
google:mainfrom
gezw:codex/gezw-adk-auth-branch-binding
Open

fix(auth): use branch-scoped events for auth responses#5982
gezw wants to merge 1 commit into
google:mainfrom
gezw:codex/gezw-adk-auth-branch-binding

Conversation

@gezw
Copy link
Copy Markdown

@gezw gezw commented Jun 5, 2026

Summary

  • read auth-response events through the current-branch event view
  • ignore auth responses that are hidden by branch filtering
  • add regression coverage for branch-scoped auth response handling

Details

The auth preprocessor already consumes prior session events to decide whether an auth response should be applied to the next LLM request. This change makes that lookup use InvocationContext._get_events(current_branch=True) instead of reading the full session event list directly, so auth handling follows the same branch visibility semantics used by the rest of the invocation context.

Validation

  • uv run --extra test pytest -q tests/unittests/auth/test_auth_preprocessor.py
  • uv run --extra dev pyink --check src/google/adk/auth/auth_preprocessor.py tests/unittests/auth/test_auth_preprocessor.py
  • uv run --extra test python -m py_compile src/google/adk/auth/auth_preprocessor.py tests/unittests/auth/test_auth_preprocessor.py
  • git diff --check

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Jun 5, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Jun 5, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Jun 5, 2026

Response from ADK Triaging Agent

Hello @gezw, thank you for submitting this pull request!

Before we can review and merge your contribution, please make sure to address the following items from our contribution guidelines:

  1. Sign our Contributor License Agreement (CLA): It looks like the CLA check has failed. Please visit https://cla.developers.google.com/ to sign the agreement so that we can proceed with your PR.
  2. Provide Test Logs / Output: To help reviewers better understand the fix, please include a summary of your passed pytest results or the actual logs showing that the tests passed successfully.

Thank you for your help in making ADK better!

@rohityan rohityan self-assigned this Jun 5, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

rohityan commented Jun 5, 2026

Hi @gezw , Thank you for your contribution! It appears you haven't yet signed the Contributor License Agreement (CLA). Please visit https://cla.developers.google.com/ to complete the signing process. Once the CLA is signed, we'll be able to proceed with the review of your PR. Thank you!

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Jun 5, 2026
@gezw
Copy link
Copy Markdown
Author

gezw commented Jun 6, 2026

@googlebot rescan

@gezw gezw force-pushed the codex/gezw-adk-auth-branch-binding branch from 2a7f7f8 to 1559690 Compare June 6, 2026 02:39
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Jun 6, 2026

🔍 ADK Pull Request Analysis: PR #5982

Title: fix(auth): use branch-scoped events for auth responses
Author: @gezw
Status: OPEN (CLA Signed & Check Run Succeeded)
Impact: 37 additions, 5 deletions across 2 files

Executive Summary

  1. Core Objective: Prevent authorization credential leakage and incorrect resolution across conversational branches by retrieving session events via the branch-scoped invocation_context._get_events(current_branch=True) filter rather than pulling the complete, unfiltered session list.
  2. Justification & Value: Valuable Fix - Highly justified, as it preserves strict branch boundaries for authorization responses, ensuring parallel threads or isolated agent flows do not cross-pollinate sensitive token contexts.
  3. Alignment with Principles: Pass - Perfect alignment with ADK's architectural principles; respects internal encapsulation, utilizes standardized APIs under invocation_context.py, and includes rigorous unit tests.
  4. Recommendation: Approve (The Google CLA check is verified and signed as of 2026-06-06T02:39:27Z; ready for merging).
Detailed Findings & Analysis

1. Objectives & Impact ("What does it do?")

  • Context & Background:
    In ADK, workflows can execute sub-agents or create branched/forked execution paths under the conversation session. Each branch has its own list of historical events.
    The auth preprocessor intercepts outgoing LLM requests to determine if previous user credential submissions should be appended.
    Previously, auth_preprocessor.py pointed directly to invocation_context.session.events, querying the absolute complete event history. Under parallel executions or multiple concurrent branches, this causes authorization response leakage or incorrect credential mapping since parent/peer branches' events got processed.
  • Implementation Mechanism:
    The change modifies the target retrieval in _AuthLlmRequestProcessor.run_async:
    -    events = invocation_context.session.events
    +    events = invocation_context._get_events(current_branch=True)
    This scopes the processed events down to the current active branch path using _get_events, which limits elements based on the current branch ID hierarchy.
  • Affected Surface:
    • No public APIs are impacted.
    • Changes are completely internal to the _AuthLlmRequestProcessor preprocessor.

2. Justification & Value ("Is it a valid and useful change?")

  • Workspace Verification:
    • Investigated auth_preprocessor.py in the workspace.
    • Confirmed that before this PR, the session.events read bypassed the branch context.
    • Investigated invocation_context.py and confirmed that _get_events(current_branch=True) correctly filters events by matching branches or general user inputs.
  • Value Assessment:
    This is a critical security and correctness fix. Without it, concurrent multi-agent executions running in isolated branches could bleed context, potentially leading to unauthorized token injections or unexpected validation crashes in parallel flows.
  • Alternative Approaches:
    The implementation is highly elegant. Instead of rewriting branch filter duplication inside auth_preprocessor.py, it appropriately reuses the framework-level _get_events functionality.
  • Scope & Depth:
    Systematic Fix & Root Cause Resolution: Rather than setting up a specialized check or "point fix" for one specific parallel-execution crash, this fix establishes systemic branch scoping for the auth-retrieval pipeline.

3. Principle & Style Alignment Checklist ("Does it follow rules?")

  • Public API & Visibility Boundaries:
    • Status: Pass
    • Analysis: No public APIs or model structures are changed. Internal boundaries are completely respected.
  • Code Quality, Typing & Conventions:
    • Status: Pass
    • Analysis: The code matches Google's styling. It correctly cleans up test mocks, replacing Mock objects with simple object() instances in test_auth_preprocessor.py (lines 168 and 539) to handle hasattr(agent, 'canonical_tools') validation safely and cleanly.
  • Robustness & Edge Cases:
    • Status: Pass
    • Analysis: Handles the empty event subset correctly downstream if no actions are found.
  • Test Integrity & Quality:
    • Status: Pass
    • Analysis:
      • Added test_ignores_auth_responses_outside_current_branch which checks that auth responses hidden on external branches are ignored.
      • Patched the mock context fixture to fall back successfully for outstanding unit tests.
      • Cleaned up mock setup anomalies across existing unit tests, preventing a class of false-positive testing signals.

Summary of Completed Tasks

  • Retrieved & Analyzed PR metadata: Fetched details for PR fix(auth): use branch-scoped events for auth responses #5982.
  • Checked MANDATORY CLA GATE: Confirmed that the cla/google status check completed with status SUCCESS at 2026-06-06T02:39:27Z. The contributor holds a valid Google CLA.
  • Reviewed workspace logic: Inspected auth_preprocessor.py, invocation_context.py, and test_auth_preprocessor.py.
  • Produced Structured Report: Composed a premium, detailed markdown analysis matching all specified guidelines under our read-only analysis profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants