Skip to content

fix(cli): Discover newly staged agents during validation - #6929

Open
yousefalbanna1 wants to merge 1 commit into
google:mainfrom
yousefalbanna1:fix/agent-import-cache-invalidation
Open

fix(cli): Discover newly staged agents during validation#6929
yousefalbanna1 wants to merge 1 commit into
google:mainfrom
yousefalbanna1:fix/agent-import-cache-invalidation

Conversation

@yousefalbanna1

Copy link
Copy Markdown

Problem:

_validate_agent_import() can fail to import a newly created agent package when Python has already cached the contents of the package's parent directory.

In that case, the package and agent.py exist, but importlib.import_module() can still raise ModuleNotFoundError.

Solution:

Invalidate Python's import caches immediately before importing the agent package.

A regression test was added that primes the import cache before creating the package and verifies that validation can still discover the new agent.

Testing Plan

Unit Tests:

  • I have added unit tests for my change.

  • All unit tests pass locally.

  • python -m pytest tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport -q — 12 passed.

  • python -m pytest tests/unittests/cli/utils/test_cli_deploy.py -q — 98 passed.

  • tox:

    • Python 3.10 — passed.
    • Python 3.11 — passed.
    • Python 3.12 — 2 failures in tests/unittests/test_import_loading.py.
    • Python 3.13 — passed.
    • Python 3.14 — passed.
  • The same two Python 3.12 failures reproduce on the unmodified base commit 6eb1d35d.

  • Pre-commit checks for the changed files — passed.

Manual End-to-End (E2E) Tests:

Built the package with uv build, installed the generated wheel in a clean virtual environment, and verified that ADK imports successfully and the updated validation code is present.

A cloud deployment was not performed.

Screenshot 2026-08-28 043012 Screenshot 2026-08-28 043746 Screenshot 2026-08-28 042814

Additional context

The two Python 3.12 tox failures are unrelated to this change and reproduce on the unmodified base commit.

Python's import finder can retain stale directory contents when an agent package is created after the parent directory has already been scanned. Invalidate import caches before validation so newly staged agent packages can be imported reliably.
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