fix(parsers): key query cache by Language object to prevent id reuse collisions#645
Merged
Conversation
Contributor
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Contributor
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Owner
Author
|
@greptile review |
|
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
The JS/TS assignment-function ingestion tests (
test_assignment_arrow_functions_are_ingested,test_object_literal_methods_are_ingested,test_export_const_function_expression, ...) flake in CI, almost exclusively on py3.13 jobs, across all three OSes. This is what failedUnit Tests (ubuntu-latest, py3.13)on #643 and several other recent PR runs.Root cause
get_cached_querykeyed its module-level cache on(id(language_obj), query_text)without retaining theLanguagewrapper.Querydoes not hold a Python reference to itsLanguageeither (refcount stays at baseline after construction). So once a test's wrapper is garbage collected, a laterLanguageallocation (possibly for a different grammar) can land at the same address, and the cache serves aQuerycompiled for the wrong grammar. Captures silently come back empty (the code path swallows the error into a debug log), and the assignment-arrow tests assert False.Whether an address gets reused depends on allocator and GC timing, which is why the failures are nondeterministic and skew toward py3.13.
Fix
Key the cache on the
Languageobject itself.Language.__hash__/__eq__follow the underlying grammar pointer, so distinct wrappers of the same grammar share one cache entry, the dict pins the key alive, and an address can never be reused into a stale hit.RED:
test_query_cache.py::test_cache_keyed_by_grammar_not_wrapper_addressfails on main (two wrappers of the same grammar get separate cache entries). GREEN with the one-line key change.Full non-integration suite: 4399 passed, 5 skipped.