Skip to content

Commit 2a49fdb

Browse files
committed
fix: use relative paths in Qdrant deletion to match stored pathSegments
- Fixed critical bug where deletions used absolute paths while insertions used relative paths - This mismatch caused deletion filters to never match any points - Removed error swallowing for 400 errors now that root cause is fixed - Added debug logging to help verify correct behavior - Deletions now actually work as intended
1 parent 3ac6d99 commit 2a49fdb

File tree

3 files changed

+26
-65
lines changed

3 files changed

+26
-65
lines changed

src/services/code-index/processors/file-watcher.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -216,35 +216,16 @@ export class FileWatcher implements IFileWatcher {
216216
errorStatus: errorStatus,
217217
})
218218

219-
// Check if this is a bad request error that we should handle gracefully
220-
if (errorStatus === 400 || errorMessage.toLowerCase().includes("bad request")) {
221-
console.warn(
222-
`[FileWatcher] Received bad request error during deletion for ${allPathsToClearFromDB.size} files. Treating as successful deletion...`,
223-
)
224-
// Treat as successful deletion - remove from cache and mark as success
225-
for (const path of pathsToExplicitlyDelete) {
226-
this.cacheManager.deleteHash(path)
227-
batchResults.push({ path, status: "success" })
228-
processedCountInBatch++
229-
this._onBatchProgressUpdate.fire({
230-
processedInBatch: processedCountInBatch,
231-
totalInBatch: totalFilesInBatch,
232-
currentFile: path,
233-
})
234-
}
235-
} else {
236-
// For other errors, mark as error but don't set overallBatchError
237-
// This allows the rest of the batch to continue processing
238-
overallBatchError = error as Error
239-
for (const path of pathsToExplicitlyDelete) {
240-
batchResults.push({ path, status: "error", error: error as Error })
241-
processedCountInBatch++
242-
this._onBatchProgressUpdate.fire({
243-
processedInBatch: processedCountInBatch,
244-
totalInBatch: totalFilesInBatch,
245-
currentFile: path,
246-
})
247-
}
219+
// Mark all paths as error
220+
overallBatchError = error as Error
221+
for (const path of pathsToExplicitlyDelete) {
222+
batchResults.push({ path, status: "error", error: error as Error })
223+
processedCountInBatch++
224+
this._onBatchProgressUpdate.fire({
225+
processedInBatch: processedCountInBatch,
226+
totalInBatch: totalFilesInBatch,
227+
currentFile: path,
228+
})
248229
}
249230
}
250231
}

src/services/code-index/processors/scanner.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,8 @@ export class DirectoryScanner implements IDirectoryScanner {
297297
errorStatus: errorStatus,
298298
})
299299

300-
// Check if this is a bad request error that we should handle gracefully
301-
if (errorStatus === 400 || errorMessage.toLowerCase().includes("bad request")) {
302-
console.warn(
303-
`[DirectoryScanner] Received bad request error when deleting ${cachedFilePath}. File may not exist in vector store. Removing from cache anyway...`,
304-
)
305-
// Still remove from cache even if vector store deletion failed
306-
await this.cacheManager.deleteHash(cachedFilePath)
307-
} else if (onError) {
308-
// For other errors, report to error handler but don't throw
300+
if (onError) {
301+
// Report error to error handler
309302
onError(
310303
error instanceof Error
311304
? new Error(
@@ -318,7 +311,8 @@ export class DirectoryScanner implements IDirectoryScanner {
318311
),
319312
)
320313
}
321-
// Don't re-throw - allow scanning to continue
314+
// Re-throw to maintain consistent error handling
315+
throw error
322316
}
323317
}
324318
}
@@ -382,19 +376,11 @@ export class DirectoryScanner implements IDirectoryScanner {
382376
errorStatus: errorStatus,
383377
})
384378

385-
// Check if this is a bad request error that we should handle gracefully
386-
if (errorStatus === 400 || errorMessage.toLowerCase().includes("bad request")) {
387-
console.warn(
388-
`[DirectoryScanner] Received bad request error during deletion. Continuing with upsert operation...`,
389-
)
390-
// Don't throw - continue with the upsert operation
391-
} else {
392-
// For other errors, re-throw with workspace context
393-
throw new Error(
394-
`Failed to delete points for ${uniqueFilePaths.length} files. Workspace: ${scanWorkspace}. ${errorMessage}`,
395-
{ cause: deleteError },
396-
)
397-
}
379+
// Re-throw with workspace context
380+
throw new Error(
381+
`Failed to delete points for ${uniqueFilePaths.length} files. Workspace: ${scanWorkspace}. ${errorMessage}`,
382+
{ cause: deleteError },
383+
)
398384
}
399385
}
400386
// --- End Deletion Step ---

src/services/code-index/vector-store/qdrant-client.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,15 @@ export class QdrantVectorStore implements IVectorStore {
444444

445445
// Build filters using pathSegments to match the indexed fields
446446
const filters = filePaths.map((filePath) => {
447-
const absolutePath = path.resolve(workspaceRoot, filePath)
448-
const normalizedPath = path.normalize(absolutePath)
447+
// IMPORTANT: Use the relative path to match what's stored in upsertPoints
448+
// upsertPoints stores the relative filePath, not the absolute path
449+
const relativePath = path.isAbsolute(filePath) ? path.relative(workspaceRoot, filePath) : filePath
450+
451+
// Normalize the relative path
452+
const normalizedRelativePath = path.normalize(relativePath)
449453

450454
// Split the path into segments like we do in upsertPoints
451-
const segments = normalizedPath.split(path.sep).filter(Boolean)
455+
const segments = normalizedRelativePath.split(path.sep).filter(Boolean)
452456

453457
// Create a filter that matches all segments of the path
454458
// This ensures we only delete points that match the exact file path
@@ -490,16 +494,6 @@ export class QdrantVectorStore implements IVectorStore {
490494
samplePaths: filePaths.slice(0, 3),
491495
})
492496

493-
// Check if this is a "bad request" error that we can handle gracefully
494-
if (errorStatus === 400 || errorMessage.toLowerCase().includes("bad request")) {
495-
console.warn(
496-
`[QdrantVectorStore] Received bad request error during deletion. This might indicate the points don't exist or the filter is invalid. Continuing without throwing...`,
497-
)
498-
// Don't throw the error - allow the indexing process to continue
499-
return
500-
}
501-
502-
// For other errors, still throw them
503497
throw error
504498
}
505499
}

0 commit comments

Comments
 (0)