Skip to content

fix(cli): preserve dependency cache on agent source changes - #8261

Draft
aashikantkumar wants to merge 2 commits into
google:mainfrom
aashikantkumar:codex/fix-cli-deploy-dependency-cache
Draft

aashikantkumar wants to merge 2 commits into
google:mainfrom
aashikantkumar:codex/fix-cli-deploy-dependency-cache

Conversation

@aashikantkumar

Copy link
Copy Markdown

Link to Issue or Description of Change

Closes: #6923

Related: #7181 (currently open; this proposal includes a conservative fallback
for requirements that may need agent files during installation).

Problem:

Generated deployment Dockerfiles copy the complete agent directory before
installing its requirements. Editing only agent source invalidates the
dependency-installation layer even when requirements are unchanged.

Solution:

Install ordinary named requirements before copying the complete agent source.
Preserve source-first installation for local paths and archives, editable
installs, direct URLs, included requirements/constraints, pip options, continued
lines, unreadable files, and unrecognized syntax. Agents without a requirements
file do not get a requirements COPY or install instruction.

Apply this in the shared renderer used by Docker, Cloud Run, Agent Engine, and
GKE. Existing extra-package installation order and CLI options are retained.

Testing Plan

Unit Tests:

  • Added regression cases for cached and fallback instruction order across
    all four deployment targets, including missing requirements and encoding.
  • Expanded deployment and CLI compatibility suite: 440 passed.
  • New regression cases: 62 passed on each of Python 3.11, 3.12, 3.13,
    and 3.14
    .
  • Deployment suites in the locked Python 3.14 tox environment:
    376 passed.
  • All applicable configured pre-commit checks passed.
  • Built source distribution and wheel with uv build; installed the wheel
    in a clean Python 3.11 environment and verified cache-friendly, local-file
    fallback, and absent-requirements rendering with source imports disabled.
  • Full repository tox matrix is entirely green (existing failures below).

Full matrix (tox -p 4 --parallel-live):

Python Passed Failed Skipped Expected failures Unexpected passes
3.11 25,857 1 99 64 2
3.12 25,848 1 100 64 2
3.13 25,848 1 100 64 2
3.14 25,849 2 98 64 2

The existing
test_render_start_command_wrapper_handles_legacy_signature_without_agent_loader
fails after TestAgentLoader.test_agent_without_root_agent_error leaves a
same-name broken_agent module cached. Reproduced this two-test sequence on an
untouched archive of baseline commit
fb08c784242c9afc3d8645508d8c5c08c9836eb9 on all four Python versions:
1 passed, 1 failed each. The legacy-startup function and AgentLoader are
unchanged by this PR.

Python 3.14 additionally reported the wall-clock-sensitive telemetry test
test_sequential_tools_add_up: measured 1.17 seconds against an expected
approximately 0.2 seconds. Isolated reruns passed on both the original baseline
and this branch. The telemetry implementation and test are unchanged. Neither
failure was suppressed or changed to make the matrix green.

Expanded test command:

python -m pytest -q \
  tests/unittests/cli/utils/test_cli_deploy.py \
  tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py \
  tests/unittests/cli/deployers \
  tests/unittests/cli/test_cli_tools_click_option_mismatch.py \
  tests/unittests/cli/utils/test_cli_deploy_ignore.py \
  tests/unittests/cli/test_cli_feature_options.py

This covers Click-option/signature matching, Dockerfile options, provider and
environment arguments, Python versions, extra packages, ignore rules, and
container startup checks in addition to the new dependency cases.

Manual Docker Tests:

Built the generated Dockerfile with a Python 3.11 base and an agent requiring
the base image's installed pip package. Rebuilt after an agent-only edit,
then after a requirements edit. Used a generated local wheel with an absolute
container path for the compatibility case and rebuilt after replacing its
contents. Disposable containers checked updated source and imported both wheel
versions. Only the unrelated ADK package-installation instruction was omitted
to isolate the changed dependency layers; this was not a cloud deployment.

Actual output from five Docker builds:

Initial generated dependency layers built
PASS: source-only edit reused pip install layer and updated source
PASS: requirements edit reran pip install
PASS: local wheel installed successfully with source-first fallback
PASS: local dependency edit reran installation and installed new content

For reproduction, build twice with the same Docker builder/cache after changing
only agent.py; the requirements COPY and pip-install step should use cache.
Change requirements.txt and rebuild; pip must run again. Repeat using a local
wheel inside the agent directory, referenced by its absolute container path;
the full-source COPY must precede pip, and replacing the wheel must reinstall
its changed content.

Checklist

  • Read CONTRIBUTING.md.
  • Performed a self-review.
  • Commented the conservative detection and bare-archive edge case.
  • Added tests proving the cache-order fix and compatibility fallback.
  • Targeted new and existing unit tests pass locally.
  • Manually tested the changed Docker dependency layers.
  • Full supported-version unit-test matrix passes (failures and baseline
    checks documented above).
  • No downstream dependency or public API changes are required.

Additional context

This intentionally optimizes only requirements that can be confidently
classified as source-independent. More complex pip syntax continues to work
with the existing source-first order. No new CLI flag is introduced.

Install source-independent agent requirements before copying agent source.
Preserve source-first installation for local dependencies and requirements
that cannot be safely classified, so existing deployments keep working.

Fixes google#6923
@google-cla

google-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

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.

@aashikantkumar
aashikantkumar marked this pull request as draft November 19, 2026 17:02
@aashikantkumar

Copy link
Copy Markdown
Author

Hi, I noticed #7181 is already open for this issue. I opened #8261 to address the local-dependency compatibility concern discussed above, preserving source-first installation when requirements may need agent files.

Would you prefer incorporating this fallback and its regression tests into #7181, or reviewing #8261 as an alternative? I’m happy to coordinate with the existing author and close my PR if that is the preferred direction

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.

Dockerfile should first copy requirements.txt and install dependencies before copying agent code

2 participants