Skip to content

fix(backend): use remote version cache offline#9304

Merged
jdx merged 1 commit intojdx:mainfrom
risu729:codex/offline-remote-version-cache
Apr 22, 2026
Merged

fix(backend): use remote version cache offline#9304
jdx merged 1 commit intojdx:mainfrom
risu729:codex/offline-remote-version-cache

Conversation

@risu729
Copy link
Copy Markdown
Contributor

@risu729 risu729 commented Apr 22, 2026

Summary

  • read the existing remote-versions cache in true offline mode without fetching or writing
  • route offline latest resolution through the shared list/cache path instead of backend-specific fast paths
  • fall back from a latest_stable_version() miss to the generic latest matcher centrally in Backend::latest_version

Root Cause

Backend::list_remote_versions_with_info() returned an empty list before consulting remote_versions.msgpack.z whenever offline was enabled. Plain latest resolution also called backend-specific fast paths first, which can return None or attempt backend-specific network work before the cached list path gets a chance to resolve a version.

Validation

  • cargo fmt --check
  • cargo test backend::latest_version_tests -- --nocapture
  • cargo test cache::tests -- --nocapture
  • git diff --check

This PR was generated by an AI coding assistant.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

This PR fixes offline mode for remote version resolution by (1) making list_remote_versions_with_info read the on-disk remote_versions.msgpack.z cache instead of returning an empty list when offline, and (2) centralising the latest_stable_version → list fallback in Backend::latest_version so every backend benefits without duplicating the fallback logic.

The previously-flagged issues (in-memory OnceCell check, default latest_stable_version returning Ok(None), and the redundant double-call) are all addressed in the current head commit.

Confidence Score: 5/5

Safe to merge — all previously flagged concerns are addressed and the new tests validate the offline cache path end-to-end.

All remaining findings are P2 or below. The core logic is correct, the centralised fallback removes duplication, and get_cached() correctly prefers in-memory state before hitting disk. The four new unit tests directly exercise the fixed code paths.

No files require special attention.

Important Files Changed

Filename Overview
src/backend/mod.rs Core fix: offline branch now calls get_cached() before returning empty list; latest_version centralises fallback from latest_stable_version → None to latest_version_for_query; default latest_stable_version returns Ok(None); four new focused unit tests added.
src/cache.rs New get_cached() method checks in-memory cache_asynccache → disk, enabling stale-but-valid reads in offline mode without triggering a fetch.
src/backend/github.rs GitLab fast path and GitHub 'no release found' case now return Ok(None) instead of calling latest_version_for_query directly, delegating fallback to the central latest_version.
src/backend/asdf.rs When no latest-stable plugin script exists, now returns Ok(None) instead of calling latest_version_for_query; _config parameter unused and renamed with leading underscore.
src/backend/npm.rs Non-string dist-tag latest field now returns Ok(None) instead of falling back to latest_version_for_query inline.
src/backend/pipx.rs Unrecognised pip version format now returns Ok(None) instead of calling latest_version_for_query inline; _config parameter renamed.

Sequence Diagram

sequenceDiagram
    participant CLI
    participant Backend
    participant Cache as CacheManager

    Note over CLI,Cache: Offline latest resolution (after this PR)

    CLI->>Backend: latest_version(None, None)
    Backend->>Backend: latest_stable_version()
    alt fast path returns Some(version)
        Backend-->>CLI: Ok(Some(version))
    else fast path returns Ok(None)
        Backend->>Backend: latest_version_for_query("latest", None)
        Backend->>Backend: list_remote_versions_with_info()
        Backend->>Cache: get_cached()
        alt in-memory hit (cache_async / cache)
            Cache-->>Backend: Ok(versions)
        else disk read
            Cache->>Cache: parse() → read msgpack.z
            Cache-->>Backend: Ok(versions) or Err
        end
        alt versions found
            Backend-->>CLI: Ok(Some(latest))
        else no cache
            Backend-->>CLI: Ok(vec![]) → Ok(None)
        end
    end
Loading

Reviews (2): Last reviewed commit: "fix(backend): use remote version cache o..." | Re-trigger Greptile

Comment thread src/cache.rs Outdated
Comment thread src/backend/mod.rs
Comment thread src/backend/mod.rs
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 enhances offline capabilities and improves the robustness of version resolution. Key changes include updating list_remote_versions_with_info to retrieve cached versions when in offline mode and implementing a fallback in latest_version to use the version list if the fast-path latest_stable_version returns no result. Comprehensive tests were added to cover these offline and fallback scenarios. The review feedback suggests further improving resilience by extending the fallback logic to handle errors from the fast-path call, ensuring the system can still resolve versions using cached data during transient network failures.

Comment thread src/backend/mod.rs
@risu729 risu729 force-pushed the codex/offline-remote-version-cache branch from ea83ed4 to de5765d Compare April 22, 2026 18:47
@risu729 risu729 marked this pull request as ready for review April 22, 2026 18:50
@jdx jdx merged commit 3c04b2a into jdx:main Apr 22, 2026
34 checks passed
@risu729 risu729 deleted the codex/offline-remote-version-cache branch April 22, 2026 22:22
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.

2 participants