From 087f1d3be34a7dbfe26ec975b8191c12df6aebf1 Mon Sep 17 00:00:00 2001 From: canvrno <46584286+canvrno@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:03:43 -0700 Subject: [PATCH] eng-245 / More checkpoints git telemetry (#2258) * Checkpoints telemetry improvements * Checkpoints telemetry improvements --- .changeset/curvy-seahorses-behave.md | 5 ++++ .../checkpoints/CheckpointGitOperations.ts | 10 ++++++- .../checkpoints/CheckpointTracker.ts | 29 ++++++++++++++++--- src/services/telemetry/TelemetryService.ts | 8 ++++- 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 .changeset/curvy-seahorses-behave.md diff --git a/.changeset/curvy-seahorses-behave.md b/.changeset/curvy-seahorses-behave.md new file mode 100644 index 00000000..9d3b5826 --- /dev/null +++ b/.changeset/curvy-seahorses-behave.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Updated checkpoints telemetry to including timings, and better capture a true git init diff --git a/src/integrations/checkpoints/CheckpointGitOperations.ts b/src/integrations/checkpoints/CheckpointGitOperations.ts index 519cf5d3..09c9dd3a 100644 --- a/src/integrations/checkpoints/CheckpointGitOperations.ts +++ b/src/integrations/checkpoints/CheckpointGitOperations.ts @@ -4,6 +4,7 @@ import * as path from "path" import simpleGit, { SimpleGit } from "simple-git" import { fileExistsAtPath } from "../../utils/fs" import { getLfsPatterns, writeExcludesFile } from "./CheckpointExclusions" +import { telemetryService } from "../../services/telemetry/TelemetryService" interface CheckpointAddResult { success: boolean @@ -53,7 +54,7 @@ export class GitOperations { * - Unable to create initial commit * - LFS pattern setup fails */ - public async initShadowGit(gitPath: string, cwd: string): Promise { + public async initShadowGit(gitPath: string, cwd: string, taskId: string): Promise { console.info(`Initializing shadow git`) // If repo exists, just verify worktree @@ -72,6 +73,7 @@ export class GitOperations { } // Initialize new repo + const startTime = performance.now() const checkpointsDir = path.dirname(gitPath) console.warn(`Creating new shadow git in ${checkpointsDir}`) @@ -93,6 +95,9 @@ export class GitOperations { // Initial commit only on first repo creation await git.commit("initial commit", { "--allow-empty": null }) + const durationMs = Math.round(performance.now() - startTime) + telemetryService.captureCheckpointUsage(taskId, "shadow_git_initialized", durationMs) + console.warn(`Shadow git initialization completed`) return gitPath @@ -179,6 +184,7 @@ export class GitOperations { * - Nested git repo handling fails */ public async addCheckpointFiles(git: SimpleGit): Promise { + const startTime = performance.now() try { // Update exclude patterns before each commit await this.renameNestedGitRepos(true) @@ -186,6 +192,8 @@ export class GitOperations { try { await git.add(".") + const durationMs = Math.round(performance.now() - startTime) + console.debug(`Checkpoint add operation completed in ${durationMs}ms`) return { success: true } } catch (error) { console.error("Checkpoint add operation failed:", error) diff --git a/src/integrations/checkpoints/CheckpointTracker.ts b/src/integrations/checkpoints/CheckpointTracker.ts index 10277779..eeb63c95 100644 --- a/src/integrations/checkpoints/CheckpointTracker.ts +++ b/src/integrations/checkpoints/CheckpointTracker.ts @@ -88,6 +88,7 @@ class CheckpointTracker { } try { console.info(`Creating new CheckpointTracker for task ${taskId}`) + const startTime = performance.now() // Check if checkpoints are disabled in VS Code settings const enableCheckpoints = vscode.workspace.getConfiguration("cline").get("enableCheckpoints") ?? true @@ -109,9 +110,10 @@ class CheckpointTracker { const newTracker = new CheckpointTracker(globalStoragePath, taskId, workingDir, cwdHash) const gitPath = await getShadowGitPath(newTracker.globalStoragePath, newTracker.taskId, newTracker.cwdHash) - await newTracker.gitOperations.initShadowGit(gitPath, workingDir) + await newTracker.gitOperations.initShadowGit(gitPath, workingDir, taskId) - telemetryService.captureCheckpointUsage(taskId, "shadow_git_initialized") + const durationMs = Math.round(performance.now() - startTime) + telemetryService.captureCheckpointUsage(taskId, "shadow_git_initialized", durationMs) return newTracker } catch (error) { @@ -148,6 +150,8 @@ class CheckpointTracker { public async commit(): Promise { try { console.info(`Creating new checkpoint commit for task ${this.taskId}`) + const startTime = performance.now() + const gitPath = await getShadowGitPath(this.globalStoragePath, this.taskId, this.cwdHash) const git = simpleGit(path.dirname(gitPath)) @@ -163,7 +167,10 @@ class CheckpointTracker { }) const commitHash = result.commit || "" console.warn(`Checkpoint commit created.`) - telemetryService.captureCheckpointUsage(this.taskId, "commit_created") + + const durationMs = Math.round(performance.now() - startTime) + telemetryService.captureCheckpointUsage(this.taskId, "commit_created", durationMs) + return commitHash } catch (error) { console.error("Failed to create checkpoint:", { @@ -229,12 +236,16 @@ class CheckpointTracker { */ public async resetHead(commitHash: string): Promise { console.info(`Resetting to checkpoint: ${commitHash}`) + const startTime = performance.now() + const gitPath = await getShadowGitPath(this.globalStoragePath, this.taskId, this.cwdHash) const git = simpleGit(path.dirname(gitPath)) console.debug(`Using shadow git at: ${gitPath}`) await git.reset(["--hard", commitHash]) // Hard reset to target commit console.debug(`Successfully reset to checkpoint: ${commitHash}`) - telemetryService.captureCheckpointUsage(this.taskId, "restored") + + const durationMs = Math.round(performance.now() - startTime) + telemetryService.captureCheckpointUsage(this.taskId, "restored", durationMs) } /** @@ -261,6 +272,8 @@ class CheckpointTracker { after: string }> > { + const startTime = performance.now() + const gitPath = await getShadowGitPath(this.globalStoragePath, this.taskId, this.cwdHash) const git = simpleGit(path.dirname(gitPath)) @@ -308,6 +321,9 @@ class CheckpointTracker { }) } + const durationMs = Math.round(performance.now() - startTime) + telemetryService.captureCheckpointUsage(this.taskId, "diff_generated", durationMs) + return result } @@ -320,6 +336,8 @@ class CheckpointTracker { * @returns The number of files changed between the commits */ public async getDiffCount(lhsHash: string, rhsHash?: string): Promise { + const startTime = performance.now() + const gitPath = await getShadowGitPath(this.globalStoragePath, this.taskId, this.cwdHash) const git = simpleGit(path.dirname(gitPath)) @@ -331,6 +349,9 @@ class CheckpointTracker { const diffRange = rhsHash ? `${lhsHash}..${rhsHash}` : lhsHash const diffSummary = await git.diffSummary([diffRange]) + const durationMs = Math.round(performance.now() - startTime) + telemetryService.captureCheckpointUsage(this.taskId, "diff_generated", durationMs) + return diffSummary.files.length } } diff --git a/src/services/telemetry/TelemetryService.ts b/src/services/telemetry/TelemetryService.ts index 574911ae..4814a270 100644 --- a/src/services/telemetry/TelemetryService.ts +++ b/src/services/telemetry/TelemetryService.ts @@ -250,13 +250,19 @@ class PostHogClient { * Records interactions with the git-based checkpoint system * @param taskId Unique identifier for the task * @param action The type of checkpoint action + * @param durationMs Optional duration of the operation in milliseconds */ - public captureCheckpointUsage(taskId: string, action: "shadow_git_initialized" | "commit_created" | "restored") { + public captureCheckpointUsage( + taskId: string, + action: "shadow_git_initialized" | "commit_created" | "restored" | "diff_generated", + durationMs?: number, + ) { this.capture({ event: PostHogClient.EVENTS.TASK.CHECKPOINT_USED, properties: { taskId, action, + durationMs, }, }) }