From aec21bb299b556eeabb8d933d336e21e65bae79b Mon Sep 17 00:00:00 2001 From: pashpashpash Date: Fri, 28 Mar 2025 16:54:43 -0700 Subject: [PATCH] Capturing telemetry events for write to file failures (#2527) * added telemetry to track diff edit failures * changeset --- .changeset/dirty-rice-film.md | 5 +++++ src/core/Cline.ts | 10 ++++++++++ src/services/telemetry/TelemetryService.ts | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 .changeset/dirty-rice-film.md diff --git a/.changeset/dirty-rice-film.md b/.changeset/dirty-rice-film.md new file mode 100644 index 00000000..b26ac34e --- /dev/null +++ b/.changeset/dirty-rice-film.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +added telemetry to track replace_in_file tool failures diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 53cfc4a7..d95de767 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1748,6 +1748,16 @@ export class Cline { ) } catch (error) { await this.say("diff_error", relPath) + + // Extract error type from error message if possible, or use a generic type + const errorType = + error instanceof Error && error.message.includes("does not match anything") + ? "search_not_found" + : "other_diff_error" + + // Add telemetry for diff edit failure + telemetryService.captureDiffEditFailure(this.taskId, errorType) + pushToolResult( formatResponse.toolError( `${(error as Error)?.message}\n\n` + diff --git a/src/services/telemetry/TelemetryService.ts b/src/services/telemetry/TelemetryService.ts index 9ffc1198..621aad6a 100644 --- a/src/services/telemetry/TelemetryService.ts +++ b/src/services/telemetry/TelemetryService.ts @@ -32,6 +32,8 @@ class PostHogClient { HISTORICAL_LOADED: "task.historical_loaded", // Tracks when the retry button is clicked for failed operations RETRY_CLICKED: "task.retry_clicked", + // Tracks when a diff edit (replace_in_file) operation fails + DIFF_EDIT_FAILED: "task.diff_edit_failed", }, // UI interaction events for tracking user engagement UI: { @@ -377,6 +379,21 @@ class PostHogClient { }) } + /** + * Records when a diff edit (replace_in_file) operation fails + * @param taskId Unique identifier for the task + * @param errorType Type of error that occurred (e.g., "search_not_found", "invalid_format") + */ + public captureDiffEditFailure(taskId: string, errorType?: string) { + this.capture({ + event: PostHogClient.EVENTS.TASK.DIFF_EDIT_FAILED, + properties: { + taskId, + errorType, + }, + }) + } + /** * Records when a different model is selected for use * @param model Name of the selected model