fix: invalidate update check cache when HEAD moves (e.g. git pull) - #9670
Closed
kshitijk4poor wants to merge 1 commit into
Closed
kshitijk4poor wants to merge 1 commit into
kshitijk4poor wants to merge 1 commit into
Conversation
The update check cached the 'commits behind' count with a 6-hour TTL based purely on timestamp. When a user ran git pull manually, HEAD moved forward but the banner still showed the stale count until the cache expired. hermes update worked because it explicitly deleted the cache file. Fix: store the local HEAD hash in the .update_check cache. On each check, compare current HEAD against the cached value. If they differ (git pull, checkout, rebase, etc.), treat the cache as stale and re-fetch. The rev-parse call is ~5ms so the fast path (cache hit) remains fast. Backward compat: old cache files without the head key get a one-time invalidation and rewrite with the HEAD hash.
This was referenced Apr 25, 2026
This was referenced May 1, 2026
This was referenced May 8, 2026
This was referenced May 25, 2026
3 tasks
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.
Problem
check_for_updates()cached the "commits behind" count in~/.hermes/.update_checkwith a 6-hour TTL based purely on timestamp. When a user rangit pullmanually, HEAD moved forward but the banner still showed the stale "X updates available" count until the 6-hour cache expired.hermes updateworked correctly because it explicitly deletes the cache file via_invalidate_update_cache(). But any manual git operation that moved HEAD (pull, checkout, rebase) left the stale cache in place.Fix
Store the local HEAD commit hash in the
.update_checkcache file alongside the existing timestamp and behind count. On each call tocheck_for_updates():git rev-parse HEAD(~5ms, cheap) to get current HEADCache logic after fix:
Backward compatibility:
Old cache files without the
headkey get a one-time invalidation and rewrite with the HEAD hash on first launch after this update.Changes
hermes_cli/banner.py— HEAD-aware cache invalidation incheck_for_updates()tests/hermes_cli/test_update_check.py— Updated existing tests + addedtest_check_for_updates_head_changed_invalidates_cacheTest plan
python -m pytest tests/hermes_cli/test_update_check.py -v— 10 tests pass