fix(banner): invalidate update-check cache when local git HEAD moves - #40985
Closed
luyao618 wants to merge 1 commit into
Closed
fix(banner): invalidate update-check cache when local git HEAD moves#40985luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
For git-source installs, the version banner reported a stale
"N commits behind" count for up to 6 hours after the user manually
ran `git pull --ff-only` to update — the documented update path
for source installs.
Root cause: `check_for_updates()` cached the result at
`~/.hermes/.update_check` and invalidated only on TTL expiry, change
of `HERMES_REVISION` (nix-only, None for git installs), or change of
`VERSION`. When a git pull brought in upstream commits that didn't
bump `__version__` (common: backports, security patches, non-versioned
batches), the predicate stayed satisfied and the stale count survived
the full 6h TTL.
Fix: track the local git HEAD SHA in the cache and add a fourth
condition to the validity predicate. Once HEAD moves, the cache is
invalidated immediately and the next banner check shows the correct
count.
- Add `_local_head_sha()` helper around the existing
`_check_via_local_git()` (reuses the same subprocess pattern,
5s timeout, broad exception handling).
- Compute `local_head` once via `_resolve_repo_dir()` (the helper
already used by other banner code paths) before the cache read,
reuse the same `repo_dir` in the git-path branch.
- Add `"head": local_head` to both the predicate and the cache
write.
Backward compatibility:
- Legacy cache files (no "head" key): `cached.get("head")` is None.
- On pip/docker installs `local_head` is also None — predicate matches,
no spurious refresh.
- On git installs `local_head` is non-None — predicate mismatches,
fresh check runs (intended).
Per-call cost: one extra local `git rev-parse HEAD` (no network),
identical to the cost profile already paid by `_check_via_local_git`.
Tests:
- New: `test_check_for_updates_invalidates_on_head_change` —
HEAD-moved cache is invalidated and rewritten.
- New: `test_check_for_updates_cache_hit_includes_head` —
matching HEAD is honored without a git fetch.
- New: `test_check_for_updates_legacy_cache_without_head_invalidates_on_git_install`
— old cache shape on a git install triggers a refresh.
- Updated: two existing tests for the new HEAD probe + cache field.
Fixes NousResearch#40944
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For git-source installs, the version banner reported a stale
N commits behindcount for up to 6 hours after the user manually rangit pull --ff-onlyto update — the documented update path for source installs.Root cause:
check_for_updates()inhermes_cli/banner.pycached its result at~/.hermes/.update_checkand invalidated only on TTL expiry, change ofHERMES_REVISION(nix-only;Nonefor git installs), or change ofVERSION. When agit pullbrought in upstream commits that did not bump__version__(common: backports, security patches, non-versioned batches), the predicate stayed satisfied and the stale count survived the full 6h TTL.Fix: track the local git
HEADSHA in the cache and add a fourth condition to the cache-validity predicate. OnceHEADmoves the cache is invalidated immediately and the next banner check shows the correct count.This implements Option A from the issue body, which the reporter explicitly preferred. The cost is a single local
git rev-parse HEADper banner check (no network) — the same cost profile already paid by_check_via_local_git.Test plan
New tests in
tests/hermes_cli/test_update_check.py:test_check_for_updates_invalidates_on_head_change— primary regression: a cache stamped at the oldHEADis invalidated whengit rev-parse HEADreturns a new SHA, the fresh check runs, and the cache is rewritten with the new SHA +behind=0.test_check_for_updates_cache_hit_includes_head— a cache stamped with the currentHEADis honored without agit fetch(a non-rev-parsesubprocess call would fail the test).test_check_for_updates_legacy_cache_without_head_invalidates_on_git_install— old cache files (no"head"key) on git installs trigger a refresh, and the new file includes"head".Updated tests in the same file account for the new
headfield and the extragit rev-parse HEADsubprocess call.Backward compatibility verified:
"head"key):cached.get("head")isNone.local_headis alsoNone— predicate matches, no spurious refresh.local_headis non-None— predicate mismatches, fresh check runs (intended).Manual repro (matches issue body)
Risks / out of scope
check_for_updates) plus one tiny new helper (_local_head_sha); no other call sites changed._invalidate_update_cache()from the CLI update command, the docker short-circuit, the version guard from check_for_updates() cache not invalidated after pip upgrade, showing stale "1 commit behind" #34491) remain untouched.Fixes #40944.