fix: sync __version__ to 0.7.1 and guard None git ref in incremental update#1
fix: sync __version__ to 0.7.1 and guard None git ref in incremental update#1andyx5-26 wants to merge 1 commit intoMibayy:mainfrom
Conversation
- __init__.py: bump __version__ from 0.4.2 to 0.7.1 to match pyproject.toml - server.py: add guard in _maybe_incremental_update() for when last_indexed_git_ref is None (empty repo / first index without git ref). Previously relied on get_changed_files() returning empty changeset for None ref, which worked but silently skipped re-indexing forever. Now triggers a full rebuild so a git ref gets recorded for future checks.
Mibayy
left a comment
There was a problem hiding this comment.
Thanks for the report — the problem you identified in _maybe_incremental_update is real, but I can't merge either change as-is.
__init__.py — version is now stale
The repo has since been bumped to v0.9.0 (commits 4b5f622 and b30bfe1). Merging 0.7.1 here would be a regression.
server.py — fix introduces an infinite rebuild loop
The problem you spotted is genuine: if last_indexed_git_ref is None, the incremental path silently stays a no-op forever. However, the proposed fix (_build_slot on every hit) has a new bug:
On a git repo with no commits yet (git init but nothing committed), is_git_repo() returns True but get_head_commit() returns None. So:
_maybe_incremental_update→last_indexed_git_ref is None→ calls_build_slot_build_slot→ full index →get_head_commit()stillNone→ ref staysNone- 30 seconds later → same thing → full rebuild loop forever
The correct fix is minimal — just stamp HEAD onto the index without rebuilding:
if idx.last_indexed_git_ref is None:
head = get_head_commit(slot.root)
if head is not None:
idx.last_indexed_git_ref = head
_save_cache(idx)
returnThis correctly handles all cases:
- Normal git repo with commits → ref gets recorded, future incremental updates work
- Empty repo (no commits) →
headis None → we return without looping - Non-git → already blocked by
if not slot.is_gitat the top of the function
If the initial index ran before the first commit (or the cache was written by an older version), last_indexed_git_ref is None and the incremental update path silently stays a no-op forever. Fix: when last_indexed_git_ref is None, fetch HEAD and persist it as the new baseline so future incremental checks work correctly. If HEAD is also None (empty repo, no commits yet), do nothing and return — avoids the full-rebuild loop that the naive _build_slot fix would cause (firing every 30 s indefinitely). Refs: PR #1 (proposed full rebuild — rejected due to infinite loop risk) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Applied the correct fix directly in 3c756f1 — stamps HEAD onto the index without triggering a rebuild, with a None-guard for empty repos. Thanks for spotting the issue. |
Changes
__init__.py__version__was hardcoded as0.4.2, out of sync withpyproject.tomlwhich declares0.7.1. This causestoken_savior.__version__to return wrong value at runtime.server.py—_maybe_incremental_update()The function called
get_changed_files(slot.root, idx.last_indexed_git_ref)without checking iflast_indexed_git_refisNonefirst.get_changed_files()already handlesNoneby returning an empty changeset (safe), but this meant the incremental update path would silently skip forever on repos where the initial index didn't record a git ref (empty repo, non-standard git setup). Now triggers a full rebuild in that case so a ref gets recorded.Spotted while evaluating the project.