Skip to content

fix(install): skip remote-versions refresh in prefer-offline mode#9627

Merged
jdx merged 2 commits intomainfrom
fix/install-refresh-prefer-offline
May 5, 2026
Merged

fix(install): skip remote-versions refresh in prefer-offline mode#9627
jdx merged 2 commits intomainfrom
fix/install-refresh-prefer-offline

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented May 5, 2026

Summary

Why

In prefer_offline mode (set by shims, hook-env, activate, etc.) the versions host is disabled (versions_host.rs:71). The post-#9545 install path was forcing a cache refresh whenever no installed version matched a prefix request, which:

  1. Bypassed the on-disk version cache populated by an earlier non-prefer-offline command (e.g. mise install terraform).
  2. Hit the versions host → returned None because of prefer_offline.
  3. Fell through to the backend's own listing — for many backends this is the GitHub releases API, which only returns the most recent ~30 versions.
  4. Older but valid prefix queries (e.g. terraform = \"prefix:1.10\") failed with no versions found for terraform.

prefer_offline() already returns true whenever offline() is true, so the guard's existing offline behavior is preserved; this just additionally suppresses the cache-busting refresh on the fast paths where it would always make things worse. The original #9545 motivation (mise use <tool> getting a stale cached latest) is unaffected — mise use doesn't run with PREFER_OFFLINE set.

Reported on commit aafe53f: aafe53f#commitcomment-184356367

Test plan

  • mise install terraform (latest), then in a project with terraform = \"prefix:1.10\" invoke a terraform shim — the older prefix should resolve from cache and auto-install rather than erroring.
  • mise use terraform@latest in a fresh shell still refreshes upstream when the cached latest is stale (no regression on fix(install): refresh latest before installing missing tools #9545's fix).
  • CI green.

🤖 Generated with Claude Code


Note

Medium Risk
Changes install-time version resolution behavior for prefix/latest selectors under prefer_offline, which could affect when remote caches are refreshed and which versions get selected. Scope is small and covered by a new e2e regression test, but it touches core install resolution logic.

Overview
Prevents install-time resolution from forcing a remote-versions cache refresh when running in prefer_offline mode, so prefix-based requests can resolve from the existing on-disk cache instead of falling back to limited backend listings.

Adds an e2e regression test (test_install_prefer_offline_no_refresh) that pre-warms the remote versions cache, pins a prefix: tool version, forces MISE_PREFER_OFFLINE=1, and asserts the install succeeds without re-running list-all.

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

In prefer_offline mode (shims, hook-env, activate, etc.) the versions
host is disabled. Refreshing the cache there bypasses the on-disk list
populated by an earlier non-prefer-offline command and falls through to
a backend listing that often has far fewer versions (e.g. GitHub
releases only returns the ~30 most recent), turning a previously-
resolvable prefix query into "no versions found for <tool>".

Reported on commit aafe53f — terraform = "prefix:1.12" auto-install
via shim broke after pre-warming with `mise install terraform`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Greptile Summary

Adds a prefer_offline guard to should_refresh_remote_versions to fix a regression introduced in #9545 where shim/hook-env invocations would force a remote-versions cache refresh even though the versions host is disabled in prefer-offline mode, causing prefix: requests to fall through to truncated backend listings and fail with "no versions found".

  • src/toolset/toolset_install.rs: replaces Settings::get().offline() with Settings::get().prefer_offline() in the early-bail check; prefer_offline() already delegates to offline() internally so the strictly-offline behavior is unchanged.
  • e2e/cli/test_install_prefer_offline_no_refresh: new regression test that pre-warms the cache, then installs under MISE_PREFER_OFFLINE=1 with list-all broken (RTX_FAILURE=1), and asserts the prefix resolves from cache.

Confidence Score: 5/5

Safe to merge — the change is a one-line guard swap with a confirmed subsumption relationship between the old and new predicate, backed by a new regression test.

The fix is minimal: a single predicate replacement in one function. prefer_offline() calls offline() internally, so every previously-guarded code path is still guarded. The new e2e test directly exercises the regression scenario. No other callers or paths are affected.

No files require special attention.

Reviews (2): Last reviewed commit: "test(install): cover prefer-offline cach..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the should_refresh_remote_versions function in src/toolset/toolset_install.rs to check for prefer_offline() instead of offline(). This change, accompanied by new documentation, ensures that the on-disk cache is utilized when the versions host is disabled, preventing issues where limited backend listings fail to resolve version prefixes. I have no feedback to provide as there were no review comments.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.0 x -- echo 30.9 ± 11.9 20.8 77.3 1.00
mise x -- echo 34.8 ± 14.0 20.6 86.0 1.12 ± 0.62
⚠️ Warning: Performance variance for x -- echo is 12%

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.0 env 39.8 ± 15.7 20.9 87.2 1.00
mise env 47.2 ± 15.2 20.5 95.9 1.19 ± 0.60
⚠️ Warning: Performance variance for env is 19%

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.0 hook-env 49.7 ± 16.0 21.4 84.6 1.19 ± 0.63
mise hook-env 41.8 ± 17.7 20.4 93.8 1.00
✅ Performance improvement for hook-env is 19%

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.0 ls 42.8 ± 17.0 19.9 85.4 1.00
mise ls 44.0 ± 12.7 17.8 76.7 1.03 ± 0.51

xtasks/test/perf

Command mise-2026.5.0 mise Variance
install (cached) 180ms ⚠️ 205ms -12%
ls (cached) 109ms ✅ 95ms +14%
bin-paths (cached) 131ms ✅ 104ms +25%
task-ls (cached) 626ms 620ms +0%

⚠️ Warning: install cached performance variance is -12%
✅ Performance improvement: ls cached is 14%
✅ Performance improvement: bin-paths cached is 25%

Pre-warms the dummy plugin's remote_versions cache, then makes list-all
fail and runs `mise install` for a `prefix:` request with no installed
match under MISE_PREFER_OFFLINE=1. The buggy code path re-runs list-all
via refresh_async and aborts; the fix reuses the on-disk cache.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@jdx jdx enabled auto-merge (squash) May 5, 2026 20:17
@jdx jdx merged commit 1fb75c0 into main May 5, 2026
35 of 36 checks passed
@jdx jdx deleted the fix/install-refresh-prefer-offline branch May 5, 2026 21:09
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