Skip to content

[Windows] adk deploy fails with [WinError 5] during cleanup of .git repositories #4635

@GuglielmoCerri

Description

@GuglielmoCerri

🔴 Required Information

Description of the Bug:

When running adk deploy agent_engine on Windows inside a directory that is a Git repository, the command fails at the very end during the "Cleaning up" phase.
The tool creates a temporary directory and copies the project files into it. On Windows, files inside the .git/objects folder are marked as read-only by default.
The current implementation uses shutil.rmtree(agent_src_path) in the finally block of the deployment function. On Windows, shutil.rmtree raises a PermissionError: [WinError 5] Access denied when encountering read-only files, causing the CLI to crash even if the cloud deployment was successful.

This happens even if a .gcloudignore file explicitly excludes .git/. It seems the ADK tool copies the files locally before filtering them or the local cleanup ignores the read-only attribute.

Steps to Reproduce

  1. On a Windows machine, create a new folder and initialize a git repository (git init).
  2. Create a basic agent structure.
  3. Commit some files so .git/objects are created.
  4. Run the deploy command:
    adk deploy agent_engine --project=MY_PROJECT --region=us-central1 --display_name=TestAgent .
  5. Wait for the "Deploying to agent engine..." step to finish.
  6. Observe the crash during the "Cleaning up" phase.

Expected Behavior:

The CLI should successfully deploy the agent and clean up the temporary folder without crashing, handling read-only files gracefully on Windows.

Observed Behavior

The deployment to Vertex AI succeeds, but the process exits with an error during cleanup:
Deploy failed: [WinError 5] Access denied: '...\\.git\\objects\\...'

Environment Details

  • ADK Library Version: 1.25.1
  • Desktop OS: Windows 11
  • Python Version: 3.13

Model Information

  • Are you using LiteLLM: N/A (CLI Issue)
  • Which model is being used: N/A

🟡 Optional Information

Regression:

Unknown.

Logs:

Starting deployment of 'Agent_Ops' to [PROJECT_ID] in us-central1...
...
Deploying to agent engine...
Cleaning up the temp folder: Agent_Ops_tmp20260226_162842
Deploy failed: [WinError 5] Access denied:: 'C:\\Projects\\GCP\\Agent_Ops_tmp20260226_162842\\.git\\objects\\02\\c597e11e4a12162f1000288349cd65a176c6c5'

Additional Context:

The issue is located in cli_deploy.py within the to_agent_engine function (and potentially to_cloud_run and to_gke as well).

The finally block (approx. line 688) calls:

finally:
    click.echo(f'Cleaning up the temp folder: {temp_folder}')
    shutil.rmtree(agent_src_path)

Proposed Fix:

To support Windows, an error handler should be passed to shutil.rmtree to toggle the read-only flag before deletion:

import os
import stat
import shutil

def _handle_readonly(func, path, exc_info):
    """Clear the readonly bit and re-run the removal."""
    os.chmod(path, stat.S_IWRITE)
    func(path)

# Then use:
shutil.rmtree(agent_src_path, onerror=_handle_readonly)

Minimal Reproduction Code:

The issue can be reproduced with this snippet on Windows:

import shutil
import os
# Assume 'temp_dir' contains a .git folder with read-only objects
shutil.rmtree('path_to_tmp_agent_dir') # This will raise WinError 5

How often has this issue occurred?:

  • Always (100% on Windows with a Git-initialized project)

Metadata

Metadata

Assignees

Labels

agent engine[Component] This issue is related to Vertex AI Agent Enginecore[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions