Skip to content

Studio: never offer an older llama.cpp prebuilt as an update - #6215

Closed
danielhanchen wants to merge 3 commits into
mainfrom
studio/fix-llama-update-downgrade
Closed

danielhanchen wants to merge 3 commits into
mainfrom
studio/fix-llama-update-downgrade

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The in-app "New llama.cpp version" banner could offer an OLDER build than the one installed, and it reappeared even after clicking Update. Reported cases: b9585 -> b9518 and b9596 -> b9594, where the offered tag is lower than the installed one (which is also GitHub's latest).

Root causes:

  • get_update_status gated update_available on installed_tag != latest_tag, a plain inequality that fires whenever latest differs from installed, including when latest is older. The source-build path additionally treated an unknown installed version as "behind" without checking that the candidate parsed to a newer build.
  • latest can legitimately resolve to an older tag. The 24h release cache can still hold the previous GitHub latest while the marker on disk is freshly newer, and the per-host resolver can walk back to an older partial release for the preferred CUDA runtime line (several recent releases ship only the cuda13 Linux line).
  • After a successful apply, reset_caches cleared only the in-memory caches, leaving the on-disk release cache and the markerless resolver memo intact, so the next poll re-derived the same stale "latest" and the banner reappeared.

Fix

  • Gate update_available on a strict build-number comparison (latest_build > installed_build) in both the marker and source-build paths, via a shared _tag_build_number helper. An older or stale "latest" can no longer be presented as an update, regardless of which path produced it.
  • After a successful in-app update, also clear the on-disk release cache (reset_caches(drop_disk=True)) and the resolver memo so the banner cannot reappear off stale data.

Test plan

  • Added regression tests in test_llama_cpp_update.py and test_llama_cpp_freshness.py: stale-cache downgrade suppressed (marker path), older-resolver-tag downgrade suppressed (source-build path), unknown installed version still offered only when the candidate parses, apply clears the resolver memo, and drop_disk removes the on-disk cache.
  • Confirmed the new regression tests fail on the pre-fix code and pass after.
  • Full backend and installer suites pass on Linux, macOS, and Windows.

The in-app update banner offered an OLDER build than installed (e.g.
b9585 -> b9518) and reappeared even after clicking Update. Two causes:

- get_update_status gated update_available on installed_tag != latest_tag,
  which fires when latest is older than installed (a stale 24h release
  cache, or the host resolver walking back to an older partial release).
- After a successful apply, reset_caches left the on-disk release cache and
  the markerless resolver memo intact, so the next poll re-derived the same
  stale older latest and re-showed the banner.

Gate update_available on a strict build-number compare (latest must be
strictly newer than installed) in both the marker and source-build paths,
and after a successful apply drop the disk release cache and resolver memo.

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

Copy link
Copy Markdown
Contributor

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 improves the update status logic for llama.cpp to prevent downgrades when dealing with stale caches or older partial releases. It introduces a helper function _tag_build_number to parse build numbers from release tags, updates update-checking logic to strictly require a newer build number, and clears on-disk caches and resolver memos upon a successful update. Additionally, comprehensive tests have been added to verify these behaviors. Feedback suggests refining the regular expression in _tag_build_number to specifically match tags starting with 'b' (e.g., b(\d+)) to avoid false positives on other numeric sequences.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +187 to +188
m = re.search(r"(\d+)", tag)
return int(m.group(1)) if m else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using r"b(\d+)" ensures we only extract the build number from tags starting with b (e.g., b9585), matching the docstring's description. This prevents false positives on other digits that might appear in non-standard tags, such as version numbers (e.g., v1.0 matching 1) or CUDA runtime suffixes (e.g., cuda13 matching 13).

Suggested change
m = re.search(r"(\d+)", tag)
return int(m.group(1)) if m else None
m = re.search(r"b(\d+)", tag)
return int(m.group(1)) if m else None

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98984c761b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +299 to +307
installed_build = _tag_build_number(installed)
latest_build = _tag_build_number(latest)
# Offer only a STRICTLY newer build. A stale release cache (latest behind the
# freshly installed marker) or an older partial release must never downgrade.
update_available = bool(
freshness.get("has_marker") and installed and latest and installed != latest
freshness.get("has_marker")
and installed_build is not None
and latest_build is not None
and latest_build > installed_build

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Compare marker installs against upstream build tags

For installs from the default unslothai/llama.cpp published repo, the marker's tag is the upstream llama.cpp build such as b9457, but the GitHub release returned here can be the fork wrapper tag such as v1.0 (the source-build path explicitly handles this by using llama_tag). In that scenario, a newer fork release like v1.1 carrying upstream b9585 is parsed as build 1, so latest_build > installed_build is false and the in-app update is suppressed for users who are actually behind.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Checked this against the published repo. On the marker path latest_tag comes from the GitHub releases API tag_name, and for unslothai/llama.cpp that tag is the upstream build itself (the /releases/latest endpoint returns b9585 today, and every recent release is bNNNN). There is no separate wrapper release carrying a hidden build number on this path, so _tag_build_number parses it correctly.

The source-build path is the one that can see a fork wrapper tag, and it already resolves against llama_tag (the bNNNN that --version reports), not release_tag, so a v1.x wrapper never reaches the comparison there either.

The only non-bNNNN tags the fork has ever published are the old llama-prebuilt-master-* date tags, which parse to None and fail open (offer nothing). That is the intended direction for this fix: never present something we cannot prove is strictly newer, which is exactly how b9585 -> b9518 slipped through before. So I am keeping the strict gate as is.

Match b(\d+) instead of the first digit run so wrapper/date tags and
master-style asset names (e.g. llama-prebuilt-master-ac76808) fail open
to no-update rather than comparing a stray number.
@danielhanchen

Copy link
Copy Markdown
Member Author

Good call. Anchored the parser on the b prefix (b(\d+)) in 2534372 so wrapper, date, and master-style asset names fail open to no-update instead of matching a stray digit run. Tests still green.

@danielhanchen

Copy link
Copy Markdown
Member Author

Closing in favor of #6219, which supersedes this.

After the mix-tag releases went live (/releases/latest is now b9596-mix-e6f2453), the more complete fix is to resolve "latest" by publish time rather than the lagging /releases/latest pointer, and to guard the apply path as well. #6219 does both. The strict build-number gate here reaches the same result on the two reported cases (b9596 -> b9594 downgrade and the mix-sticky banner), but #6219 is the more robust version to carry forward. The one item left here, gating the source-build detection path, I have folded into the #6219 review.

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