Skip to content

Commit 4e5cc92

Browse files
Fixes issue where deleting tasks wasn't clearing the task metadata or context history files; let model recording fail gracefully (RooCodeInc#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 <[email protected]>
1 parent b42c0f2 commit 4e5cc92

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

.changeset/clean-boats-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Fixes issue where deleting tasks wasn't clearing the task metadata or context history files; let model recording fail gracefully

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/controller/index.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
17041704
taskDirPath: string
17051705
apiConversationHistoryFilePath: string
17061706
uiMessagesFilePath: string
1707+
contextHistoryFilePath: string
1708+
taskMetadataFilePath: string
17071709
apiConversationHistory: Anthropic.MessageParam[]
17081710
}> {
17091711
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
17121714
const taskDirPath = path.join(this.context.globalStorageUri.fsPath, "tasks", id)
17131715
const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
17141716
const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages)
1717+
const contextHistoryFilePath = path.join(taskDirPath, GlobalFileNames.contextHistory)
1718+
const taskMetadataFilePath = path.join(taskDirPath, GlobalFileNames.taskMetadata)
17151719
const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
17161720
if (fileExists) {
17171721
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
17201724
taskDirPath,
17211725
apiConversationHistoryFilePath,
17221726
uiMessagesFilePath,
1727+
contextHistoryFilePath,
1728+
taskMetadataFilePath,
17231729
apiConversationHistory,
17241730
}
17251731
}
@@ -1791,22 +1797,28 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
17911797
console.debug("cleared task")
17921798
}
17931799

1794-
const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this.getTaskWithId(id)
1795-
1800+
const {
1801+
taskDirPath,
1802+
apiConversationHistoryFilePath,
1803+
uiMessagesFilePath,
1804+
contextHistoryFilePath,
1805+
taskMetadataFilePath,
1806+
} = await this.getTaskWithId(id)
1807+
const legacyMessagesFilePath = path.join(taskDirPath, "claude_messages.json")
17961808
const updatedTaskHistory = await this.deleteTaskFromState(id)
17971809

17981810
// Delete the task files
1799-
const apiConversationHistoryFileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
1800-
if (apiConversationHistoryFileExists) {
1801-
await fs.unlink(apiConversationHistoryFilePath)
1802-
}
1803-
const uiMessagesFileExists = await fileExistsAtPath(uiMessagesFilePath)
1804-
if (uiMessagesFileExists) {
1805-
await fs.unlink(uiMessagesFilePath)
1806-
}
1807-
const legacyMessagesFilePath = path.join(taskDirPath, "claude_messages.json")
1808-
if (await fileExistsAtPath(legacyMessagesFilePath)) {
1809-
await fs.unlink(legacyMessagesFilePath)
1811+
for (const filePath of [
1812+
apiConversationHistoryFilePath,
1813+
uiMessagesFilePath,
1814+
contextHistoryFilePath,
1815+
taskMetadataFilePath,
1816+
legacyMessagesFilePath,
1817+
]) {
1818+
const fileExists = await fileExistsAtPath(filePath)
1819+
if (fileExists) {
1820+
await fs.unlink(filePath)
1821+
}
18101822
}
18111823

18121824
await fs.rmdir(taskDirPath) // succeeds if the dir is empty

src/core/task/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3113,8 +3113,11 @@ export class Task {
31133113
throw new Error("Cline instance aborted")
31143114
}
31153115

3116+
// Used to know what models were used in the task if user wants to export metadata for error reporting purposes
31163117
if (this.apiProvider && this.api.getModel().id) {
3117-
await this.modelContextTracker.recordModelUsage(this.apiProvider, this.api.getModel().id, this.chatSettings.mode)
3118+
try {
3119+
await this.modelContextTracker.recordModelUsage(this.apiProvider, this.api.getModel().id, this.chatSettings.mode)
3120+
} catch {}
31183121
}
31193122

31203123
if (this.consecutiveMistakeCount >= 3) {

0 commit comments

Comments
 (0)