eng-245 / More checkpoints git telemetry (#2258)

* Checkpoints telemetry improvements

* Checkpoints telemetry improvements
This commit is contained in:
canvrno authored and GitHub committed 2025-03-14 17:03:43 -07:00
1 parent 8cc7759584
commit 087f1d3be3
4 files changed
+46 -6

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Updated checkpoints telemetry to including timings, and better capture a true git init
@@ -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<string> {
public async initShadowGit(gitPath: string, cwd: string, taskId: string): Promise<string> {
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<CheckpointAddResult> {
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)
@@ -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<boolean>("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<string | undefined> {
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<void> {
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<number> {
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
}
}
+7 -1
View File
@@ -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,
},
})
}