Skip to content

semantic_search: warn when the index predates the current commit - #151

Merged
alpibrupa merged 1 commit into
mainfrom
feat/semantic-search-staleness
Sep 8, 2026
Merged

semantic_search: warn when the index predates the current commit#151
alpibrupa merged 1 commit into
mainfrom
feat/semantic-search-staleness

Conversation

@alpibrupa

Copy link
Copy Markdown
Contributor

Summary

  • The index is already incrementally rebuilt (sig_id is the reuse key, not mtime — unchanged functions carry their embedding over), so rebuilding is cheap, but nothing ever told a caller a rebuild might be needed: a stale index answered a query exactly as confidently as a fresh one.
  • Config gains built_at_commit — the git HEAD sha at build time, "" when not built inside a git checkout or written before this field existed (index_build.lex's new git_head(), matching the existing docs_json's proc.run pattern).
  • semantic_search compares it against the CURRENT head at query time and appends a one-line note naming both commits when they differ; matching or either-side-empty stays silent — this is a heuristic ("HEAD moved"), not a guarantee ("a function actually changed"), and reusable() deliberately still ignores it for cache-reuse decisions (only base_url/model/dims matter there).

Test plan

  • lex check / lex fmt --check / lex doc-sync --check — clean
  • lex test tests — 4/4 existing tests still pass
  • examples {} blocks for staleness_note cover match/mismatch/either-side-empty
  • Live driver isolating render()/staleness_note() from the real embedding HTTP call (hand-built index header, real HEAD via git rev-parse): a mismatched commit produces the note naming both shas; a matching one produces byte-for-byte the same output as before this change

🤖 Generated with Claude Code

The index is already incrementally rebuilt (sig_id is the reuse key,
not mtime -- unchanged functions carry their embedding over), so
rebuilding is cheap, but nothing ever told a caller a rebuild might be
needed: a stale index answered a query exactly as confidently as a
fresh one, with no way to tell the difference short of noticing wrong
results after the fact.

Config gains built_at_commit -- the git HEAD sha at build time, ""
when not built inside a git checkout or written before this field
existed (index_build.lex's git_head(), matching the existing
docs_json's proc.run pattern). semantic_search compares it against
the CURRENT head at query time and appends a one-line note naming
both commits when they differ; matching or either-side-empty stays
silent, since this is a heuristic ("HEAD moved") and not a guarantee
("a function actually changed") -- built_at_commit's own comment says
so, and reusable() deliberately still ignores it for cache-reuse
decisions, only base_url/model/dims matter there.

Verified with a driver isolating render()/staleness_note() from the
real embedding HTTP call (a hand-built index header, real HEAD via
git rev-parse): a mismatched commit produces the note naming both
shas, a matching one produces the exact same output as before this
change, byte for byte.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@alpibrupa
alpibrupa merged commit 0fd4d4d into main Sep 8, 2026
1 check passed
@alpibrupa
alpibrupa deleted the feat/semantic-search-staleness branch September 8, 2026 15:31
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