From 4e5cc92065cab1cfca2be9da060f803fc746b513 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Thu, 10 Apr 2025 02:04:10 -0700 Subject: [PATCH] Fixes issue where deleting tasks wasn't clearing the task metadata or context history files; let model recording fail gracefully (#2778) * Fixes issue where deleting tasks wasn't clearing the task metadata or context history files; let model recording fail gracefully * Create clean-boats-film.md --------- Co-authored-by: Dennis Bartlett --- .changeset/clean-boats-film.md | 5 +++++ package-lock.json | 4 ++-- src/core/controller/index.ts | 38 ++++++++++++++++++++++------------ src/core/task/index.ts | 5 ++++- 4 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 .changeset/clean-boats-film.md diff --git a/.changeset/clean-boats-film.md b/.changeset/clean-boats-film.md new file mode 100644 index 00000000..681d4298 --- /dev/null +++ b/.changeset/clean-boats-film.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Fixes issue where deleting tasks wasn't clearing the task metadata or context history files; let model recording fail gracefully diff --git a/package-lock.json b/package-lock.json index 561b86b5..291b9f6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "claude-dev", - "version": "3.10.0", + "version": "3.10.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "claude-dev", - "version": "3.10.0", + "version": "3.10.1", "license": "Apache-2.0", "dependencies": { "@anthropic-ai/bedrock-sdk": "^0.12.4", diff --git a/src/core/controller/index.ts b/src/core/controller/index.ts index edb02689..f2e81281 100644 --- a/src/core/controller/index.ts +++ b/src/core/controller/index.ts @@ -1704,6 +1704,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont taskDirPath: string apiConversationHistoryFilePath: string uiMessagesFilePath: string + contextHistoryFilePath: string + taskMetadataFilePath: string apiConversationHistory: Anthropic.MessageParam[] }> { const history = ((await getGlobalState(this.context, "taskHistory")) as HistoryItem[] | undefined) || [] @@ -1712,6 +1714,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont const taskDirPath = path.join(this.context.globalStorageUri.fsPath, "tasks", id) const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory) const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages) + const contextHistoryFilePath = path.join(taskDirPath, GlobalFileNames.contextHistory) + const taskMetadataFilePath = path.join(taskDirPath, GlobalFileNames.taskMetadata) const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath) if (fileExists) { const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8")) @@ -1720,6 +1724,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath, + contextHistoryFilePath, + taskMetadataFilePath, apiConversationHistory, } } @@ -1791,22 +1797,28 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont console.debug("cleared task") } - const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this.getTaskWithId(id) - + const { + taskDirPath, + apiConversationHistoryFilePath, + uiMessagesFilePath, + contextHistoryFilePath, + taskMetadataFilePath, + } = await this.getTaskWithId(id) + const legacyMessagesFilePath = path.join(taskDirPath, "claude_messages.json") const updatedTaskHistory = await this.deleteTaskFromState(id) // Delete the task files - const apiConversationHistoryFileExists = await fileExistsAtPath(apiConversationHistoryFilePath) - if (apiConversationHistoryFileExists) { - await fs.unlink(apiConversationHistoryFilePath) - } - const uiMessagesFileExists = await fileExistsAtPath(uiMessagesFilePath) - if (uiMessagesFileExists) { - await fs.unlink(uiMessagesFilePath) - } - const legacyMessagesFilePath = path.join(taskDirPath, "claude_messages.json") - if (await fileExistsAtPath(legacyMessagesFilePath)) { - await fs.unlink(legacyMessagesFilePath) + for (const filePath of [ + apiConversationHistoryFilePath, + uiMessagesFilePath, + contextHistoryFilePath, + taskMetadataFilePath, + legacyMessagesFilePath, + ]) { + const fileExists = await fileExistsAtPath(filePath) + if (fileExists) { + await fs.unlink(filePath) + } } await fs.rmdir(taskDirPath) // succeeds if the dir is empty diff --git a/src/core/task/index.ts b/src/core/task/index.ts index d85c3d7a..ca10fa7e 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -3113,8 +3113,11 @@ export class Task { throw new Error("Cline instance aborted") } + // Used to know what models were used in the task if user wants to export metadata for error reporting purposes if (this.apiProvider && this.api.getModel().id) { - await this.modelContextTracker.recordModelUsage(this.apiProvider, this.api.getModel().id, this.chatSettings.mode) + try { + await this.modelContextTracker.recordModelUsage(this.apiProvider, this.api.getModel().id, this.chatSettings.mode) + } catch {} } if (this.consecutiveMistakeCount >= 3) {