Skip to content

Add isolated workspace resolver for flow run setup#21699

Open
desertaxle wants to merge 5 commits intomainfrom
feat/first-class-uv-support
Open

Add isolated workspace resolver for flow run setup#21699
desertaxle wants to merge 5 commits intomainfrom
feat/first-class-uv-support

Conversation

@desertaxle
Copy link
Copy Markdown
Member

@desertaxle desertaxle commented Apr 24, 2026

refs #19321

this PR adds an internal workspace resolver primitive for safely preparing deployment workspaces before later uv launcher integration.

Details
  • introduces private prefect.runner._workspace_resolver subprocess entrypoint that prepares storage and pull-step workspaces and returns structured metadata as JSON
  • preserves parent cwd by running resolution in a child process, keeping stdout reserved for JSON and redirecting pull-step output to stderr
  • tracks pull-step cwd outputs, local path project roots, environment, and sys.path metadata for later executor wiring
  • adds a narrow optional run_steps completion callback with best-effort cwd probing only when the callback is supplied
  • covers local storage, git clone, remote and block storage, custom cwd behavior, noisy stdout, process state capture, structured failures, and deleted cwd recovery

Reviewer example

For a deployment whose pull steps clone a repo and then enter a nested src directory:

pull:
- prefect.deployments.steps.git_clone:
    id: clone
    repository: https://github.com/acme/data-jobs.git
    clone_directory_name: repo
- prefect.deployments.steps.set_working_directory:
    directory: "{{ clone.directory }}/service/src"

deployments:
- name: daily-report
  entrypoint: flows/report.py:daily_report

the resolver can be invoked before the eventual flow subprocess:

python -m prefect.runner._workspace_resolver "$FLOW_RUN_ID" "/tmp/prefect-workspaces/$FLOW_RUN_ID"

It prepares the pull-step workspace and returns metadata like:

{
  "status": "success",
  "workspace": {
    "workspace_root": "/tmp/prefect-workspaces/abc",
    "working_directory": "/tmp/prefect-workspaces/abc/repo/service/src",
    "project_root": "/tmp/prefect-workspaces/abc/repo/service",
    "runtime_entrypoint": "flows/report.py:daily_report"
  }
}

A uv-aware executor can then run from working_directory while using project_root for project dependency resolution:

cd /tmp/prefect-workspaces/abc/repo/service/src

PREFECT__FLOW_RUN_ID="$FLOW_RUN_ID" \
PREFECT__FLOW_ENTRYPOINT="flows/report.py:daily_report" \
uv run --project /tmp/prefect-workspaces/abc/repo/service \
  python -m prefect.engine

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 24, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing feat/first-class-uv-support (b7a66ac) with main (efb35bf)

Open in CodSpeed

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd9afcea1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/prefect/runner/_workspace_resolver.py Outdated
@desertaxle desertaxle marked this pull request as draft April 24, 2026 15:04
@desertaxle desertaxle marked this pull request as ready for review April 24, 2026 19:29
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.

1 participant