Skip to content

Commit abb3a5b

Browse files
committed
fix(code-index): exclude private error details from indexing telemetry
1 parent 701260c commit abb3a5b

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

‎src/services/code-index/__tests__/orchestrator.spec.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, it, expect, beforeEach, vi } from "vitest"
22
import { CodeIndexOrchestrator } from "../orchestrator"
3+
import { TelemetryService } from "@roo-code/telemetry"
4+
import { TelemetryEventName } from "@roo-code/types"
35

46
import { clearAllMocks } from "../../../test-utils/reset"
57

@@ -280,6 +282,59 @@ describe("CodeIndexOrchestrator - error path cleanup gating", () => {
280282
},
281283
)
282284

285+
it.each([false, true])(
286+
"keeps private error details out of telemetry (cleanup failure: %s)",
287+
async (cleanupFails) => {
288+
const messages = [
289+
"Embedding failed (Workspace: /Users/private-user/Secret Project, File: /Users/private-user/Secret Project/src/private.ts)",
290+
"Embedding failed (Workspace: C:\\Users\\private-user\\Secret Project, File: C:\\Users\\private-user\\Secret Project\\private.ts)",
291+
]
292+
const failures = messages.map((message) => {
293+
const error = new Error(message)
294+
error.stack = `${message}\n at privateFunction (/Users/private-user/Secret Project/private.ts:12:3)`
295+
return error
296+
})
297+
vectorStore.initialize.mockResolvedValue(cleanupFails)
298+
vectorStore.hasIndexedData.mockResolvedValue(!cleanupFails)
299+
vectorStore.markIndexingIncomplete.mockResolvedValue(undefined)
300+
scanner.scanDirectory.mockImplementation(async (_dir: string, onError: (error: Error) => void) => {
301+
for (const failure of failures) onError(failure)
302+
return { stats: { processed: 0, skipped: 0 }, totalBlockCount: 0 }
303+
})
304+
if (cleanupFails) vectorStore.clearCollection.mockRejectedValue(failures[1])
305+
const orchestrator = new CodeIndexOrchestrator(
306+
configManager,
307+
stateManager,
308+
workspacePath,
309+
cacheManager,
310+
vectorStore,
311+
scanner,
312+
fileWatcher,
313+
)
314+
315+
await orchestrator.startIndexing()
316+
317+
const expectedEvents = [
318+
[TelemetryEventName.CODE_INDEX_ERROR, { error: "Indexing failed", location: "startIndexing" }],
319+
]
320+
if (cleanupFails) {
321+
expectedEvents.push([
322+
TelemetryEventName.CODE_INDEX_ERROR,
323+
{ error: "Index cleanup failed", location: "startIndexing.cleanup" },
324+
])
325+
}
326+
// Exact payload assertions also exclude stacks, nested causes and aggregate error objects.
327+
expect(vi.mocked(TelemetryService.instance.captureEvent).mock.calls).toEqual(expectedEvents)
328+
expect(stateManager.setSystemState).toHaveBeenLastCalledWith("Error", expect.stringContaining(messages[0]))
329+
if (!cleanupFails) {
330+
expect(stateManager.setSystemState).toHaveBeenLastCalledWith(
331+
"Error",
332+
expect.stringContaining(messages[1]),
333+
)
334+
}
335+
},
336+
)
337+
283338
it("preserves an existing index after an incremental failure and a failed full-scan retry", async () => {
284339
let complete = true
285340
vectorStore.initialize.mockResolvedValue(false)

‎src/services/code-index/orchestrator.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ export class CodeIndexOrchestrator {
186186
}
187187

188188
console.error("[CodeIndexOrchestrator] Error during indexing:", error)
189+
// Scanner/provider errors and stacks may contain local paths or other private data.
190+
// Keep details local; send only a fixed failure category across the telemetry boundary.
189191
TelemetryService.instance.captureEvent(TelemetryEventName.CODE_INDEX_ERROR, {
190-
error: error instanceof Error ? error.message : String(error),
191-
stack: error instanceof Error ? error.stack : undefined,
192+
error: "Indexing failed",
192193
location: "startIndexing",
193194
})
194195
if (clearIndexOnError) {
@@ -197,8 +198,7 @@ export class CodeIndexOrchestrator {
197198
} catch (cleanupError) {
198199
console.error("[CodeIndexOrchestrator] Failed to clean up after error:", cleanupError)
199200
TelemetryService.instance.captureEvent(TelemetryEventName.CODE_INDEX_ERROR, {
200-
error: cleanupError instanceof Error ? cleanupError.message : String(cleanupError),
201-
stack: cleanupError instanceof Error ? cleanupError.stack : undefined,
201+
error: "Index cleanup failed",
202202
location: "startIndexing.cleanup",
203203
})
204204
}

0 commit comments

Comments
 (0)