Cache comment checker tree-sitter queries - #5
Merged
Merged
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
There was a problem hiding this comment.
2 issues found across 2 files
Confidence score: 3/5
- There is a concrete resource-management risk in
pkg/core/detector.go: cached*sitter.Queryobjects are not closed, so C-backed query memory can leak for the detector lifetime in long-running use. - The test in
pkg/core/detector_test.gocurrently validates cache size only, which may miss a regression where queries are recompiled each call under the same key; this leaves cache-reuse behavior under-verified. - Given the moderate severities and fairly strong confidence, this looks mergeable with caution, but fixing the query cleanup and strengthening reuse assertions would reduce regression risk.
- Pay close attention to
pkg/core/detector.goandpkg/core/detector_test.go- query lifecycle cleanup and true cache-reuse validation need tightening.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="pkg/core/detector.go">
<violation number="1" location="pkg/core/detector.go:171">
P2: Cached `*sitter.Query` instances are never closed, so query C-resources can leak for the lifetime of each detector.</violation>
</file>
<file name="pkg/core/detector_test.go">
<violation number="1" location="pkg/core/detector_test.go:120">
P2: This only checks cache size, so it won’t fail if the query is recompiled on every call and stored under the same key. Verify reuse by comparing the cached query pointer across calls (or by counting compilations) instead.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Re-trigger cubic
| return nil | ||
| } | ||
|
|
||
| cache[langName] = compiledQuery |
There was a problem hiding this comment.
P2: Cached *sitter.Query instances are never closed, so query C-resources can leak for the lifetime of each detector.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/core/detector.go, line 171:
<comment>Cached `*sitter.Query` instances are never closed, so query C-resources can leak for the lifetime of each detector.</comment>
<file context>
@@ -137,6 +131,47 @@ func (d *CommentDetector) detectDocstrings(sourceCode []byte, filePath string, l
+ return nil
+ }
+
+ cache[langName] = compiledQuery
+ return compiledQuery
+}
</file context>
| // then | ||
| detector.queryMu.Lock() | ||
| defer detector.queryMu.Unlock() | ||
| assert.Len(t, detector.commentQueries, 1) |
There was a problem hiding this comment.
P2: This only checks cache size, so it won’t fail if the query is recompiled on every call and stored under the same key. Verify reuse by comparing the cached query pointer across calls (or by counting compilations) instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/core/detector_test.go, line 120:
<comment>This only checks cache size, so it won’t fail if the query is recompiled on every call and stored under the same key. Verify reuse by comparing the cached query pointer across calls (or by counting compilations) instead.</comment>
<file context>
@@ -98,3 +98,25 @@ func main() {}`
+ // then
+ detector.queryMu.Lock()
+ defer detector.queryMu.Unlock()
+ assert.Len(t, detector.commentQueries, 1)
+ assert.Len(t, detector.docstringQueries, 1)
+}
</file context>
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
Improvement table
BenchmarkCommentDetectorDetectPythonNoDocstrings-18714618 ns/op,1056 B/op,22 allocs/op11275 ns/op,1024 B/op,19 allocs/opBenchmarkCommentDetectorDetectPythonWithDocstrings-183617623 ns/op,2096 B/op,43 allocs/op14156 ns/op,1800 B/op,34 allocs/op12.71 ns/op,0 B/op,0 allocs/opVerification
Review