Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cli/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2948,8 +2948,31 @@ func (p *projectPrefixStore) DeleteDocument(ctx context.Context, filePath string
return p.store.DeleteDocument(ctx, prefixedPath)
}

// ListDocuments returns only the documents whose path begins with this
// project's workspace+project prefix, with the prefix stripped so the
// indexer sees relative paths that match what its scanner enumerates.
//
// Without this filter the inner shared store returns every document in
// the entire workspace; the indexer then treats every other project's
// docs as "no longer present" and runs RemoveFile against each one. The
// removes silently no-op (projectPrefixStore.DeleteByFile re-adds the
// prefix, producing a doubly-prefixed path that never matches a stored
// row), but the spurious work shows up as wildly inflated "files
// removed" counts (the workspace total, on every per-project scan) and
// thousands of pointless Postgres roundtrips on every restart.
func (p *projectPrefixStore) ListDocuments(ctx context.Context) ([]string, error) {
return p.store.ListDocuments(ctx)
all, err := p.store.ListDocuments(ctx)
if err != nil {
return nil, err
}
prefix := p.getPrefix() + "/"
out := make([]string, 0, len(all))
for _, path := range all {
if strings.HasPrefix(path, prefix) {
out = append(out, strings.TrimPrefix(path, prefix))
}
}
return out, nil
}

func (p *projectPrefixStore) Load(ctx context.Context) error {
Expand Down
28 changes: 24 additions & 4 deletions cli/watch_prefix_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,18 @@ func TestProjectPrefixStore_PassThroughAndGetChunks(t *testing.T) {
ctx := context.Background()
projectRoot := t.TempDir()
mock := &mockVectorStore{
searchResults: []store.SearchResult{{Score: 0.9}},
listDocumentsResult: []string{"a", "b"},
searchResults: []store.SearchResult{{Score: 0.9}},
// The underlying shared store sees the full workspace. ListDocuments
// must filter to this project's prefix and strip it before returning,
// so the indexer's scan-vs-stored diff doesn't treat other projects'
// documents as "removed".
listDocumentsResult: []string{
"ws/proj/main.go",
"ws/proj/sub/file.go",
"ws/other/main.go", // different project — must be filtered out
"different-ws/proj/main.go", // different workspace — must be filtered out
"unprefixed.go", // no workspace prefix — must be filtered out
},
getStatsResult: &store.IndexStats{TotalFiles: 2},
listFilesResult: []store.FileStats{{Path: "p"}},
getChunksForFileItems: []store.Chunk{{ID: "c1"}},
Expand All @@ -240,8 +250,18 @@ func TestProjectPrefixStore_PassThroughAndGetChunks(t *testing.T) {
}

docs, err := wrapped.ListDocuments(ctx)
if err != nil || len(docs) != 2 {
t.Fatalf("ListDocuments failed: %v %v", docs, err)
if err != nil {
t.Fatalf("ListDocuments failed: %v", err)
}
wantDocs := []string{"main.go", "sub/file.go"}
if len(docs) != len(wantDocs) {
t.Fatalf("ListDocuments: expected %d paths (filtered + stripped), got %d: %v",
len(wantDocs), len(docs), docs)
}
for i, want := range wantDocs {
if docs[i] != want {
t.Errorf("ListDocuments[%d]: got %q, want %q", i, docs[i], want)
}
}
if err := wrapped.Load(ctx); err != nil {
t.Fatalf("Load failed: %v", err)
Expand Down