Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 2 additions & 49 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ export class ClineProvider
private recentTasksCache?: string[]
public readonly taskHistoryStore: TaskHistoryStore
private taskHistoryStoreInitialized = false
private globalStateWriteThroughTimer: ReturnType<typeof setTimeout> | null = null
private static readonly GLOBAL_STATE_WRITE_THROUGH_DEBOUNCE_MS = 5000 // 5 seconds
public static readonly PENDING_OPERATION_TIMEOUT_MS = 30000 // 30 seconds
private providerProfileMutationQueue = Promise.resolve()
private historyTaskCreationQueue = Promise.resolve()
Expand Down Expand Up @@ -343,14 +341,8 @@ export class ClineProvider
this.mdmService = mdmService
void this.updateGlobalState("codebaseIndexModels", EMBEDDING_MODEL_PROFILES)

// Initialize the per-task file-based history store.
// The globalState write-through is debounced separately (not on every mutation)
// since per-task files are authoritative and globalState is only for downgrade compat.
this.taskHistoryStore = new TaskHistoryStore(this.contextProxy.globalStorageUri.fsPath, {
onWrite: async () => {
this.scheduleGlobalStateWriteThrough()
},
})
// Initialize the authoritative per-task file-based history store.
this.taskHistoryStore = new TaskHistoryStore(this.contextProxy.globalStorageUri.fsPath)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stops new writes, but the old "taskHistory" blob is still sitting in globalState from before migration. VS Code fires the large-state warning whenever it reads or writes the total extension state, so the warning will keep appearing even after this PR lands. Should initializeTaskHistoryStore (or the migration block in it) also call this.context.globalState.update("taskHistory", undefined) after marking the migration complete?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PierrunoYT - after reviewing the recent changes, lets revert this request, and instead file a separate ticket for it, it might not be a simple addition for handling old blobs.

this.initializeTaskHistoryStore().catch((error) => {
this.log(`Failed to initialize TaskHistoryStore: ${error}`)
})
Expand Down Expand Up @@ -896,7 +888,6 @@ export class ClineProvider
await this.marketplaceManager?.cleanup()
this.customModesManager?.dispose()
this.taskHistoryStore.dispose()
this.flushGlobalStateWriteThrough()
this.log("Disposed all disposables")
ClineProvider.activeInstances.delete(this)

Expand Down Expand Up @@ -3133,44 +3124,6 @@ export class ClineProvider
return history
}

/**
* Schedule a debounced write-through of task history to globalState.
* Only used for backward compatibility during the transition period.
* Per-task files are authoritative; globalState is the downgrade fallback.
*/
private scheduleGlobalStateWriteThrough(): void {
if (this.globalStateWriteThroughTimer) {
clearTimeout(this.globalStateWriteThroughTimer)
}

this.globalStateWriteThroughTimer = setTimeout(async () => {
this.globalStateWriteThroughTimer = null
try {
const items = this.taskHistoryStore.getAll()
await this.updateGlobalState("taskHistory", items)
} catch (err) {
this.log(
`[scheduleGlobalStateWriteThrough] Failed: ${err instanceof Error ? err.message : String(err)}`,
)
}
}, ClineProvider.GLOBAL_STATE_WRITE_THROUGH_DEBOUNCE_MS)
}

/**
* Flush any pending debounced globalState write-through immediately.
*/
private flushGlobalStateWriteThrough(): void {
if (this.globalStateWriteThroughTimer) {
clearTimeout(this.globalStateWriteThroughTimer)
this.globalStateWriteThroughTimer = null
}

const items = this.taskHistoryStore.getAll()
this.updateGlobalState("taskHistory", items).catch((err) => {
this.log(`[flushGlobalStateWriteThrough] Failed: ${err instanceof Error ? err.message : String(err)}`)
})
}

/**
* Broadcasts a task history update to the webview.
* This sends a lightweight message with just the task history, rather than the full state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ describe("ClineProvider Task History Synchronization", () => {
return calls.filter((call) => call[0]?.type === type)
}

it("uses per-task files without registering a globalState write-through callback", () => {
expect(provider.taskHistoryStore["onWrite"]).toBeUndefined()
})

describe("updateTaskHistory", () => {
it("broadcasts task history update by default", async () => {
await provider.resolveWebviewView(mockWebviewView)
Expand Down
Loading