Skip to content

fix(flows): stop Agent import loading authlib, which fails test_import_loading - #7214

Open
vishal-bulbule wants to merge 1 commit into
google:mainfrom
vishal-bulbule:fix/lazy-toolset-auth-import
Open

vishal-bulbule wants to merge 1 commit into
google:mainfrom
vishal-bulbule:fix/lazy-toolset-auth-import

Conversation

@vishal-bulbule

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

  • N/A

2. Or, if no issue exists, describe the change:

Problem:

Since 665ec98 ("refactor: extract tool-resolution steps into tool_request_processors"),
tests/unittests/test_import_loading.py::test_entry_point_loads_only_allowlisted_packages
fails on main, and all five Unit Tests jobs (Python 3.10 to 3.14) fail on every CI run and on open PRs
(latest main run: https://github.com/google/adk-python/actions/runs/35460464450):

FAILED tests/unittests/test_import_loading.py::test_entry_point_loads_only_allowlisted_packages[agent]
AssertionError: 'from google.adk.agents import Agent' now loads authlib, charset_normalizer,
cryptography, joserfc, requests, urllib3, which every ADK process would pay for at startup.

The new flows/llm_flows/tools/_toolset_auth.py imports
TOOLSET_AUTH_CREDENTIAL_ID_PREFIX from auth.auth_preprocessor at module level.
auth_preprocessor imports AuthHandler, which imports the OAuth2 credential exchanger and
authlib. Before the refactor, base_llm_flow.py defined the constant itself, so nothing
extra was loaded.

Solution:

Import the constant inside resolve_toolset_auth, where it is used, as the module already
does for CredentialManager and AuthHandler. One file, one import moved.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change. (N/A: covered by the existing
    test_import_loading.py, which fails on main and passes with this change)
  • All unit tests pass locally.
$ pytest tests/unittests/test_import_loading.py
main (d57c84f1):  1 failed, 14 passed
this change:      15 passed

$ pytest tests/unittests/flows tests/unittests/auth -n auto
1092 passed

$ pytest tests/unittests -n auto
main (d57c84f1):  1 failed, 15291 passed
this change:      15288 passed, 0 failed

Bisected over the commits since f33d492: the import test passes up to 6605031 and fails from
665ec98 onward.

mypy: no issues in flows/llm_flows/tools/_toolset_auth.py. pre-commit passes.

Manual End-to-End (E2E) Tests:

N/A: import-time change with no behavior change. The toolset auth path still resolves the prefix
(covered by the flows and auth tests above).

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas. (N/A, one import moved)
  • I have added tests that prove my fix is effective or that my feature works. (existing test)
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end. (N/A, see above)
  • Any dependent changes have been merged and published in downstream modules. (N/A)

…t_loading

_toolset_auth imported TOOLSET_AUTH_CREDENTIAL_ID_PREFIX from
auth.auth_preprocessor at module level. That module imports AuthHandler
and the OAuth2 credential exchanger, so `from google.adk.agents import
Agent` started loading authlib, cryptography, requests and related
packages at startup, which fails test_import_loading. Import the constant
where it is used, as the module already does for CredentialManager and
AuthHandler.
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.

2 participants