Skip to content

Commit 231864d

Browse files
author
razvan
committed
fix: address PR #40 review comments
- fix(engine): propagate recreate=true through pendingOverflow queue When a recreate request is queued while indexing, tryStartPendingIndex now correctly passes recreate=true to the follow-up job. - fix(index_status): Windows-safe atomic rename fallback os.Rename fails on Windows when dest exists; now falls back to remove-then-rename. - fix(docs/treesitter): avoid materializing huge strings for massive leaf nodes — slice source bytes directly when nodeLen > 8192. - cleanup(tests): remove empty t.Cleanup block in fallback search test.
1 parent 7e2966e commit 231864d

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

internal/service/engine/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,8 @@ func (e *Engine) popPendingIndex(workspaceID string) (files []string, overflow b
762762
func (e *Engine) tryStartPendingIndex(root, workspaceID string) {
763763
files, overflow := e.popPendingIndex(workspaceID)
764764
if overflow {
765-
logger.Instance.Info("[IDX] ♻️ Pending changes exceeded limit for ws=%s — triggering full scan", filepath.Base(root))
766-
e.StartIndexingAsync(root, workspaceID, nil, false)
765+
logger.Instance.Info("[IDX] ♻️ Pending changes exceeded limit for ws=%s — triggering full re-index", filepath.Base(root))
766+
e.StartIndexingAsync(root, workspaceID, nil, true)
767767
return
768768
}
769769
if len(files) == 0 {

internal/service/engine/engine_fallback_search_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ func ValidateEmail(email string) bool {
9494
eng := NewEngine(idxSvc, searchSvc, "", &config.Config{})
9595
eng.SetResolver(resolver.New(resolver.Dependencies{Detector: &mockDirDetector{root: root}}))
9696

97-
t.Cleanup(func() {
9897

99-
})
10098

10199
return root, eng
102100
}

pkg/indexer/index_status.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ func SaveIndexStatus(workspaceRoot string, status *IndexStatus) {
6565
}
6666
path := filepath.Join(dir, indexStatusFile)
6767
if err := os.Rename(tmpName, path); err != nil {
68-
os.Remove(tmpName)
69-
logger.Instance.Warn("index_status: rename failed for %s: %v", path, err)
68+
// Windows-safe fallback: os.Rename fails when dest exists on Windows.
69+
_ = os.Remove(path)
70+
if err2 := os.Rename(tmpName, path); err2 != nil {
71+
os.Remove(tmpName)
72+
logger.Instance.Warn("index_status: rename failed for %s: %v", path, err2)
73+
}
7074
}
7175
}
7276

pkg/parser/docs/treesitter.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,26 @@ func (p *TreeSitterParser) Parse(source []byte, filePath string, ext string) ([]
4747

4848
// A leaf or a reasonably sized chunk (~1500 chars) -> make it a valid symbol chunk
4949
if node.ChildCount() == 0 || nodeLen <= 1500 {
50-
text := strings.TrimSpace(node.Text(source))
50+
// Prevent massive leaf nodes (e.g. 50MB SQL INSERT values) from
51+
// allocating the full string — slice the underlying bytes directly.
52+
var text string
53+
if nodeLen > 8192 {
54+
end := int(node.StartByte()) + 8192
55+
if end > len(source) {
56+
end = len(source)
57+
}
58+
text = strings.TrimSpace(string(source[node.StartByte():end])) + "\n...[TRUNCATED]"
59+
} else {
60+
text = strings.TrimSpace(node.Text(source))
61+
}
62+
5163
if len(text) < 10 {
5264
for i := 0; i < node.ChildCount(); i++ {
5365
walk(node.Child(i), parentSig)
5466
}
5567
return
5668
}
5769

58-
// Prevent massive leaf nodes (e.g. 50MB SQL INSERT values) from crashing Ollama
59-
if len(text) > 8192 {
60-
text = text[:8192] + "\n...[TRUNCATED]"
61-
}
62-
6370
startLine := int(node.StartPoint().Row) + 1
6471
endLine := int(node.EndPoint().Row) + 1
6572

0 commit comments

Comments
 (0)