Skip to content

Commit 4a0c0b1

Browse files
authored
Revert "Merge pull request #1682 from GitlyHallows/bug/old-task-deletion" (#1837)
This reverts commit bfd6009, reversing changes made to 7459ac5.
1 parent e694a2b commit 4a0c0b1

File tree

3 files changed

+22
-141
lines changed

3 files changed

+22
-141
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,51 +2326,33 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
23262326
}> {
23272327
const history = ((await this.getGlobalState("taskHistory")) as HistoryItem[] | undefined) || []
23282328
const historyItem = history.find((item) => item.id === id)
2329-
if (!historyItem) {
2330-
throw new Error("Task not found in history")
2331-
}
2332-
2333-
const taskDirPath = path.join(this.contextProxy.globalStorageUri.fsPath, "tasks", id)
2334-
const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
2335-
const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages)
2336-
2337-
const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
2338-
if (!fileExists) {
2339-
// Instead of silently deleting, throw a specific error
2340-
throw new Error("TASK_FILES_MISSING")
2341-
}
2342-
2343-
const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8"))
2344-
return {
2345-
historyItem,
2346-
taskDirPath,
2347-
apiConversationHistoryFilePath,
2348-
uiMessagesFilePath,
2349-
apiConversationHistory,
2329+
if (historyItem) {
2330+
const taskDirPath = path.join(this.contextProxy.globalStorageUri.fsPath, "tasks", id)
2331+
const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
2332+
const uiMessagesFilePath = path.join(taskDirPath, GlobalFileNames.uiMessages)
2333+
const fileExists = await fileExistsAtPath(apiConversationHistoryFilePath)
2334+
if (fileExists) {
2335+
const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8"))
2336+
return {
2337+
historyItem,
2338+
taskDirPath,
2339+
apiConversationHistoryFilePath,
2340+
uiMessagesFilePath,
2341+
apiConversationHistory,
2342+
}
2343+
}
23502344
}
2345+
// if we tried to get a task that doesn't exist, remove it from state
2346+
// FIXME: this seems to happen sometimes when the json file doesnt save to disk for some reason
2347+
await this.deleteTaskFromState(id)
2348+
throw new Error("Task not found")
23512349
}
23522350

23532351
async showTaskWithId(id: string) {
23542352
if (id !== this.getCurrentCline()?.taskId) {
2355-
try {
2356-
const { historyItem } = await this.getTaskWithId(id)
2357-
await this.initClineWithHistoryItem(historyItem)
2358-
} catch (error) {
2359-
if (error.message === "TASK_FILES_MISSING") {
2360-
const response = await vscode.window.showWarningMessage(
2361-
t("common:warnings.missing_task_files"),
2362-
t("common:answers.remove"),
2363-
t("common:answers.keep"),
2364-
)
2365-
2366-
if (response === t("common:answers.remove")) {
2367-
await this.deleteTaskFromState(id)
2368-
await this.postStateToWebview()
2369-
}
2370-
return
2371-
}
2372-
throw error
2373-
}
2353+
// Non-current task.
2354+
const { historyItem } = await this.getTaskWithId(id)
2355+
await this.initClineWithHistoryItem(historyItem) // Clears existing task.
23742356
}
23752357

23762358
await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
@@ -2857,28 +2839,4 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
28572839

28582840
return properties
28592841
}
2860-
2861-
async validateTaskHistory() {
2862-
const history = ((await this.getGlobalState("taskHistory")) as HistoryItem[] | undefined) || []
2863-
const validTasks: HistoryItem[] = []
2864-
2865-
for (const item of history) {
2866-
const taskDirPath = path.join(this.contextProxy.globalStorageUri.fsPath, "tasks", item.id)
2867-
const apiConversationHistoryFilePath = path.join(taskDirPath, GlobalFileNames.apiConversationHistory)
2868-
2869-
if (await fileExistsAtPath(apiConversationHistoryFilePath)) {
2870-
validTasks.push(item)
2871-
}
2872-
}
2873-
2874-
if (validTasks.length !== history.length) {
2875-
await this.updateGlobalState("taskHistory", validTasks)
2876-
await this.postStateToWebview()
2877-
2878-
const removedCount = history.length - validTasks.length
2879-
if (removedCount > 0) {
2880-
await vscode.window.showInformationMessage(t("common:info.history_cleanup", { count: removedCount }))
2881-
}
2882-
}
2883-
}
28842842
}

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -55,78 +55,6 @@ jest.mock("../../contextProxy", () => {
5555
}
5656
})
5757

58-
describe("validateTaskHistory", () => {
59-
let provider: ClineProvider
60-
let mockContext: vscode.ExtensionContext
61-
let mockOutputChannel: vscode.OutputChannel
62-
let mockUpdate: jest.Mock
63-
64-
beforeEach(() => {
65-
// Reset mocks
66-
jest.clearAllMocks()
67-
68-
mockUpdate = jest.fn()
69-
70-
// Setup basic mocks
71-
mockContext = {
72-
globalState: {
73-
get: jest.fn(),
74-
update: mockUpdate,
75-
keys: jest.fn().mockReturnValue([]),
76-
},
77-
secrets: { get: jest.fn(), store: jest.fn(), delete: jest.fn() },
78-
extensionUri: {} as vscode.Uri,
79-
globalStorageUri: { fsPath: "/test/path" },
80-
extension: { packageJSON: { version: "1.0.0" } },
81-
} as unknown as vscode.ExtensionContext
82-
83-
mockOutputChannel = { appendLine: jest.fn() } as unknown as vscode.OutputChannel
84-
provider = new ClineProvider(mockContext, mockOutputChannel)
85-
})
86-
87-
test("should remove tasks with missing files", async () => {
88-
// Mock the global state with some test data
89-
const mockHistory = [
90-
{ id: "task1", ts: Date.now() },
91-
{ id: "task2", ts: Date.now() },
92-
]
93-
94-
// Setup mocks
95-
jest.spyOn(mockContext.globalState, "get").mockReturnValue(mockHistory)
96-
97-
// Mock fileExistsAtPath to only return true for task1
98-
const mockFs = require("../../../utils/fs")
99-
mockFs.fileExistsAtPath = jest.fn().mockImplementation((path) => Promise.resolve(path.includes("task1")))
100-
101-
// Call validateTaskHistory
102-
await provider.validateTaskHistory()
103-
104-
// Verify the results
105-
const expectedHistory = [expect.objectContaining({ id: "task1" })]
106-
107-
expect(mockUpdate).toHaveBeenCalledWith("taskHistory", expect.arrayContaining(expectedHistory))
108-
expect(mockUpdate.mock.calls[0][1].length).toBe(1)
109-
})
110-
111-
test("should handle empty history", async () => {
112-
// Mock empty history
113-
jest.spyOn(mockContext.globalState, "get").mockReturnValue([])
114-
115-
await provider.validateTaskHistory()
116-
117-
expect(mockUpdate).toHaveBeenCalledWith("taskHistory", [])
118-
})
119-
120-
test("should handle null history", async () => {
121-
// Mock null history
122-
jest.spyOn(mockContext.globalState, "get").mockReturnValue(null)
123-
124-
await provider.validateTaskHistory()
125-
126-
expect(mockUpdate).toHaveBeenCalledWith("taskHistory", [])
127-
})
128-
})
129-
13058
// Mock dependencies
13159
jest.mock("vscode")
13260
jest.mock("delay")

src/extension.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ export function activate(context: vscode.ExtensionContext) {
6464
const provider = new ClineProvider(context, outputChannel, "sidebar")
6565
telemetryService.setProvider(provider)
6666

67-
// Validate task history on extension activation
68-
provider.validateTaskHistory().catch((error) => {
69-
outputChannel.appendLine(`Failed to validate task history: ${error}`)
70-
})
71-
7267
context.subscriptions.push(
7368
vscode.window.registerWebviewViewProvider(ClineProvider.sideBarId, provider, {
7469
webviewOptions: { retainContextWhenHidden: true },

0 commit comments

Comments
 (0)