Skip to content

docs: document set_working_directory relative path contract in runner AGENTS.md#22399

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
claude/update-agents-md-6da5a09
Open

docs: document set_working_directory relative path contract in runner AGENTS.md#22399
github-actions[bot] wants to merge 1 commit into
mainfrom
claude/update-agents-md-6da5a09

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Automated AGENTS.md update triggered by commit 6da5a09.

This PR was generated by Claude Code analyzing the diff from the latest push to main and updating any stale AGENTS.md files.

Why this belongs in AGENTS.md
Path: src/prefect/runner/AGENTS.md
Proposed text: Add a **`set_working_directory` relative path contract** bullet under "Workspace Resolver Subprocess" describing: the resolver seeds `_PULL_STEP_SOURCE_CWD` (from `deployments/steps/core.py`) with the original process CWD before running pull steps; `set_working_directory` resolves relative paths against this context var; the var is cleared after each step so only the *first* `set_working_directory` sees the original CWD; subsequent calls resolve against the CWD left by preceding steps.
Non-obvious evidence: The context var is defined in `deployments/steps/core.py`, set in `runner/_workspace_resolver.py`, and consumed in `deployments/steps/pull.py`. No single file captures the full contract. The per-step clearing behavior (in the step completion callback) is particularly subtle — it changes which CWD `set_working_directory` resolves against depending on step ordering, which is invisible to anyone reading `pull.py` alone.
Cross-cutting scope: Applies to all deployments using `set_working_directory` with relative paths via the runner/workspace resolver path. Covers the "baked-image container" deployment pattern (set_working_directory: ".") as well as chained pull steps (git_clone → set_working_directory with a relative subdir).
Why not code comment/docstring: The inline comment in `_workspace_resolver.py` documents only the clearing behavior and lives in one file. The contract has two sides in two different AGENTS.md territories. A developer modifying `set_working_directory` in `deployments/steps/pull.py` would not see the runner's inline comment; a developer modifying the workspace resolver might not check `pull.py`. AGENTS.md is the only place that spans both.
Durability: The baked-image container deployment pattern is a first-class use case and will remain relevant indefinitely. The context-var mechanism is the chosen solution and unlikely to change structurally.
Counter-evidence checked: Inline comment in `_workspace_resolver.py` (lines 350-355 post-patch) documents the per-step clearing rationale; `_PULL_STEP_SOURCE_CWD` name is descriptive; existing "Local path in-place execution" bullet covers the no-pull-steps baked-image case; tests in `TestRelativePathSetWorkingDirectory` document the scenarios. None of these expose the cross-module contract at the AGENTS.md-reading level.

Changed files in triggering push
src/prefect/deployments/steps/core.py
src/prefect/deployments/steps/pull.py
src/prefect/runner/_workspace_resolver.py
tests/runner/test__workspace_resolver.py

@desertaxle desertaxle marked this pull request as ready for review June 30, 2026 02:03

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

Copy link
Copy Markdown

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: 51fe448183

ℹ️ 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".


**Pull-step directory fallback:** When pull steps run but none produces a `directory` output or changes CWD, `_ensure_entrypoint_in_workspace` copies storage into the workspace root as a fallback. This handles setup-only pull steps (e.g., `run_shell_script` for environment prep) that do not control the working directory themselves.

**`set_working_directory` relative path contract:** Before running pull steps, the resolver sets `_PULL_STEP_SOURCE_CWD` (from `deployments/steps/core.py`) to the original process CWD. `set_working_directory` resolves relative paths against this context var when set. The var is cleared after each step (in the step completion callback), so only the *first* `set_working_directory` call in a sequence sees the original CWD — subsequent calls resolve against the CWD left by preceding steps (e.g., the workspace root after a `git_clone`). This enables `set_working_directory: "."` in a baked-image deployment to point to the container WORKDIR rather than the temporary workspace root.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Put this contract in an AGENTS scope that covers it

This new note documents a contract shared with src/prefect/deployments/steps/core.py and pull.py, but src/prefect/runner/AGENTS.md only applies to files under src/prefect/runner/. That means future changes to set_working_directory or _PULL_STEP_SOURCE_CWD in deployments/steps will not see the instruction, which defeats the stated purpose of preserving this cross-module behavior. Please move or duplicate the contract into an AGENTS.md whose scope includes the deployments step files, such as the common src/prefect/AGENTS.md or a new scoped file under src/prefect/deployments/steps/.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

0 participants