Skip to content

Resolve executable symlinks when warming venv interpreter caches - #2548

Draft
astral-automations-bot[bot] wants to merge 5 commits into
zb/restore-interpreter-cache-warmingfrom
automations/fix-bug/22383
Draft

astral-automations-bot[bot] wants to merge 5 commits into
zb/restore-interpreter-cache-warmingfrom
automations/fix-bug/22383

Conversation

@astral-automations-bot

@astral-automations-bot astral-automations-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Venv cache warming retained executable symlinks, causing cached and freshly queried base paths to differ. Match CPython’s executable-symlink resolution while preserving parent-directory links, and strengthen the regression to require matching metadata and downstream venv targets. Fixes astral-sh#22383

Stacked on astral-sh#22524.

@astral-automations-bot astral-automations-bot Bot added the bug Something isn't working label Oct 9, 2026
Comment on lines +1196 to +1199
if links >= 40 {
return Err(
io::Error::other("Too many symbolic links in Python executable").into(),
);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[P2] Preserve successful venv creation at the symlink limit

An installation-local chain of 39 executable symlinks becomes 40 after adding the venv’s bin/python link. I verified that Linux canonicalization and CPython 3.12.14 both accept this environment; CPython falls back when deriving _base_executable. This new error instead propagates through cache_virtualenv to uv venv, making creation of a working environment fail. Match CPython’s fallback at this boundary, or skip cache warming when resolution reaches the limit.

@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 54 untouched benchmarks
⏩ 35 skipped benchmarks1


Comparing automations/fix-bug/22383 (217b459) with main (06bf2e8)2

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on zb/restore-interpreter-cache-warming (e83627b) during the generation of this report, so main (06bf2e8) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@woodruffw

Copy link
Copy Markdown
Member

NB #2549 is an attempt at a simpler fix here.

@astral-automations-bot
astral-automations-bot Bot force-pushed the automations/reproduce-bug/22383 branch from 93729c7 to e3272ea Compare October 13, 2026 18:55
@zaniebot
zaniebot changed the base branch from automations/reproduce-bug/22383 to zb/restore-interpreter-cache-warming October 13, 2026 19:00
@zaniebot
zaniebot force-pushed the automations/fix-bug/22383 branch from de0b2a2 to 2d06bfe Compare October 13, 2026 19:01
@zaniebot
zaniebot deployed to automations October 13, 2026 19:02 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 13, 2026 19:08 — with GitHub Actions Active
Comment on lines +1189 to +1190
executable.pop();
executable = uv_fs::normalize_absolute_path(&executable.join(target))?;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[P2] Preserve absolute symlink targets during cache inference

CPython’s getpath_realpath preserves absolute symlink targets verbatim and normalizes only relative targets. For example, with /tmp/alias -> /usr/lib, an absolute target /tmp/alias/../bin/python3.12 reaches /usr/bin/python3.12, but this loop changes it to /tmp/bin/python3.12. I reproduced this difference with CPython 3.12.3 and the extracted resolution loop. Cache writing still succeeds because it canonicalizes the original venv executable, leaving a nonexistent base executable in the warmed metadata. Creating another venv from that cached environment then fails, while querying Python gives a working target. Assign absolute targets directly and only join and normalize relative targets.

@zaniebot
zaniebot deployed to automations October 13, 2026 19:23 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 13, 2026 19:28 — with GitHub Actions Active
Comment on lines +1194 to +1195
executable.pop();
uv_fs::normalize_absolute_path(&executable.join(target))?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[P2] Skip cache inference when normalization walks above root

A valid relative executable symlink can contain more .. components than its directory depth: POSIX and CPython clamp these at /, but normalize_absolute_path returns InvalidInput. I verified that CPython 3.12 runs such a venv and canonicalization succeeds, while the extracted inference loop errors. For a system interpreter, the earlier home-directory check does not skip this branch, so the error propagates through cache_virtualenv, making uv venv fail after creating a working environment. Return Ok(None) on this normalization failure to use the existing cache-clearing fallback, or match CPython’s root-clamping semantics.

@zaniebot
zaniebot deployed to automations October 13, 2026 19:34 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
automations — 217b459d Deployed Oct 13, 2026 by zaniebot via review-code-quality / code quality review #9803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants