Repository navigation
fix: stop queries from mutating the in-memory alias index - #349
Open
Kevin Turcios (KRRT7) wants to merge 4 commits into
Open
Kevin Turcios (KRRT7) wants to merge 4 commits into
Kevin Turcios (KRRT7) wants to merge 4 commits into
Conversation
TermToRelatedTermsMap returned and stored its own Term objects. Search preparation lowercases and reweights related terms in place, and dedupe_related_terms raises shared related terms to their maximum weight, so running a query permanently changed stored alias weights and text. Copy terms on lookup and on add, matching the SQLite alias index. Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
Bernhard Merkle (bmerkle)
approved these changes
Oct 18, 2026
Bernhard Merkle (bmerkle)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — verified locally.
- Confirmed the root cause:
lookup_termreturned the storedTermobjects, and search preparation lowercases text (search.py:552), resets weights (search.py:541), anddedupe_related_termsraises shared terms to their max weight (collections.py:599), all in place, so queries permanently rewrote the alias map. - Copy-on-add plus copy-on-lookup closes both aliasing directions and brings the memory backend in line with SQLite, which already builds fresh
Terms. - The 3 new memory-backend tests fail against
main'srelated_terms_index.pyand pass with the fix; fullmake(format, pyright, 817 tests, build) is green onaec1bd5.
Optional nit: if Term ever gains fields, both Term(term.text, term.weight) copies would silently drop them; dataclasses.replace(term) would be future-proof. Not blocking.
Contributor
Author
|
Thanks! Took the nit: both copies now use |
This branch has not been deployed
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
TermToRelatedTermsMap(in-memory alias index) returned and stored its ownTermobjects. Search preparation lowercases and reweights related terms in place, anddedupe_related_termsraises a related term shared by several search terms to its maximum weight, so running a query permanently changed stored alias weights and text.car → auto (0.5)andvehicle → auto (0.9); after an OR query forcarandvehicle,lookup_term("car")returnedauto (0.9).lookup_termandadd_related_term, matching the SQLite alias index, which already builds freshTermobjects.Validation
add_related_term, and runningresolve_related_termstwice must leave the aliases unchanged. The memory cases fail without the fix.