Skip to content

fix(runtime): never replace a published uv script - #2777

Open
faresobeid wants to merge 2 commits into
mainfrom
fix/uv-script-link-if-absent
Open

faresobeid wants to merge 2 commits into
mainfrom
fix/uv-script-link-if-absent

Conversation

@faresobeid

@faresobeid faresobeid commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Runtime.prepare_uv_script published a content-addressed script with mv -f <tmp> <path>, even when the file already existed. On a shared filesystem (the subprocess runtime keeps scripts in ~/.cache/verifiers/runtimes/scripts, shared across nodes) that rename swaps the file under workers that are running it, and they fail with ENOENT.

What

  • Publish with ln <tmp> <path>. link(2) is atomic and fails if the path exists, so a published script is never replaced. The path is content-addressed, so an existing file has the same bytes.
  • The temp file is always removed; test -f <path> checks a copy is in place before uv sync.

Validation

  • uv run pytest tests/unit: 217 passed, 19 skipped (Docker/Prime/harbor). ruff check/format clean.
  • 6 concurrent processes ran SubprocessRuntime.run_uv_script on the same script on the shared FS: all exited 0, one file left, no temp files.

Note

Medium Risk
Changes shared-filesystem publication semantics for all prepare_uv_script callers; if the destination exists but is not a regular file, bootstrap may be skipped while execution still proceeds from cache.

Overview
Fixes a race when multiple workers publish the same content-addressed UV script on a shared filesystem.

prepare_uv_script no longer uses mv -f to install the script. It writes a unique temp file, tries ln into the stable path (fails silently if another worker already published), removes the temp, then runs test -f before uv sync / interpreter resolution. That way an in-use script is never replaced and concurrent execs avoid ENOENT from rename.

The run_uv_script docstring is updated to describe hard-link publication instead of temp + atomic move.

Reviewed by Cursor Bugbot for commit 9c98de9. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix Runtime.prepare_uv_script to never replace a published uv script

Changes script publication from an atomic move (forced replace) to a hard-link from a unique temp file, so concurrent workers preparing the same content-addressed script do not clobber each other. The temp file is removed after the link attempt, and dependency/bootstrap setup only proceeds when the destination is a regular file. Also updates the docstring of Runtime.run_uv_script to match. Risk: if the destination exists but is not a regular file (e.g. a dangling symlink on a shared filesystem), setup in base.py is skipped — check callers that assume setup always runs.

Macroscope summarized 9c98de9.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Oct 13, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 5751883

Macroscope's review found this PR approvable — This is a focused one-file fix to publish content-addressed uv scripts without replacing an existing file, preserving stable execution for concurrent workers while leaving dependency setup unchanged. The behavior change is limited to correcting the publication race and does not introduce a new capability or schema/infrastructure change.

No code changes detected at 7920275. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

This branch has not been deployed

No deployments
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