Skip to content

Fix virtual environment reuse error in multi-deployment jobs#72

Merged
jamiezieziula merged 1 commit intomainfrom
fix-venv-reuse-issue
Feb 6, 2026
Merged

Fix virtual environment reuse error in multi-deployment jobs#72
jamiezieziula merged 1 commit intomainfrom
fix-venv-reuse-issue

Conversation

@jamiezieziula
Copy link
Copy Markdown
Contributor

@jamiezieziula jamiezieziula commented Feb 6, 2026

Problem

When this action runs multiple times in the same GitHub Actions job, subsequent runs fail with:

error: Failed to create virtual environment
  Caused by: A virtual environment already exists at .venv

This causes intermittent failures when deploying multiple Prefect flows in the same workflow job.

Root Cause

The uv venv command (line 55) creates a .venv directory but doesn't clean it up. When called a second time in the same job, it refuses to overwrite the existing directory without the --clear flag.

This became an issue after v4.3.0 re-enabled uv for dependency management (PR #66).

Solution

Add --clear flag to uv venv command:

- name: Set up environment
  run: uv venv --clear  # Forces recreation if exists
  shell: bash

Testing

Tested by running action multiple times in same job - second run now succeeds instead of failing.

Impact

  • ✅ No breaking changes - behavior identical for first-time runs
  • ✅ Fixes intermittent failures in multi-deployment workflows
  • ✅ Eliminates need for cleanup workarounds in consuming repos
  • ✅ Aligns with uv best practices for CI environments

Related

  • Fixes failures in PrefectHQ/flows workflows
  • Allows removal of cleanup workarounds added in PrefectHQ/flows#2407

When this action runs multiple times in the same GitHub Actions job,
subsequent runs fail with:
  error: Failed to create virtual environment
  Caused by: A virtual environment already exists at .venv

This happens because uv venv refuses to overwrite an existing .venv
directory without the --clear flag.

Changes:
- Add --clear flag to 'uv venv' command
- Forces recreation of .venv if it already exists
- Allows action to be called multiple times in same job safely

Impact:
- No breaking changes - action behavior is identical
- Fixes intermittent failures when deploying multiple flows
- Eliminates need for workarounds in consuming workflows

Fixes: workflows failing with "A virtual environment already exists"
@jamiezieziula jamiezieziula requested a review from a team as a code owner February 6, 2026 18:18
@jamiezieziula jamiezieziula merged commit 3805b32 into main Feb 6, 2026
1 check passed
@jamiezieziula jamiezieziula deleted the fix-venv-reuse-issue branch February 6, 2026 18:39
@jamiezieziula jamiezieziula added the enhancement New feature or request label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants