Skip to content

python: better cache in PET resolveEnv()#13168

Open
austin3dickey wants to merge 2 commits intomainfrom
aus/cachee
Open

python: better cache in PET resolveEnv()#13168
austin3dickey wants to merge 2 commits intomainfrom
aus/cachee

Conversation

@austin3dickey
Copy link
Copy Markdown
Contributor

Addresses part of #12500. Related to #12327, where some Python interpreters weren't getting resolved correctly after we bumped PET. Possibly will help with #12253 too, where some Python interpreters weren't being discovered in the first pass of discovery after we bumped PET.

resolveEnv() was decorated with @cache(30_000, true). But if PET hadn't discovered the env yet, undefined is pinned in the cache for 30 seconds, even after PET finished discovery. Any caller in that window got the stale undefined back. This PR replaces the decorator with an explicit cache on NativePythonEnvironments that:

  1. Only caches successful PythonEnvInfo resolutions.
  2. Never caches undefined or thrown errors.
  3. Is invalidated in addEnv/removeEnv, so a late-arriving PET discovery automatically supersedes any prior cached state.

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

@:interpreter

Reusing the #13064 QA trick to simulate a slow PET: add

await new Promise((r) => setTimeout(r, 30000));

inside finder.refresh's loop in nativeAPI.ts.

Before this PR: picking an interpreter via the picker in the first 30s after a cold start would sometimes log Tried to switch to a language runtime that has not been registered and fail to start.

After this PR: selection should succeed as soon as PET has seen that env without a 30s penalty.

Unit tests covering the regression are included.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:interpreter

readme  valid tags

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