Skip to content

Commit 0dae49a

Browse files
committed
fix(provider): keep committed deletions committed and compensate once
The outer write-group restore must not roll back a replacement activation failure (the deletion has committed by contract) and must not run a second compensation after the scoped activation rollback already ran. Guard both with a rethrow, strengthen the activation-failure test with a saveConfig spy, and re-key the cancelled-deletion double for the snapshot read.
1 parent 6a82b9e commit 0dae49a

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,10 @@ export class ClineProvider
31043104
const previousSelection = globalSettings.currentApiConfigName
31053105
const previousSharedSettings = this.contextProxy.getProviderSettings()
31063106
const previousViewStates = this.getPersistedViewStates({ fresh: true })
3107+
// Tracks whether the scoped activation compensation inside the try
3108+
// already ran, so the outer write-group restore does not run a second,
3109+
// conflicting compensation.
3110+
let innerCompensationRan = false
31073111

31083112
// Remove the profile from the settings store (context.secrets) so it cannot be
31093113
// resurrected by a later listApiConfigMeta sync. A not-found rejection means
@@ -3289,6 +3293,9 @@ export class ClineProvider
32893293
survivingSettings,
32903294
)
32913295
} catch (error: unknown) {
3296+
// This scoped compensation is authoritative for the stores it
3297+
// covers; the outer write-group restore must not run again below.
3298+
innerCompensationRan = true
32923299
// A cancelled (timed-out) deletion still compensates. The queue is chained to this run,
32933300
// so no later mutation can have written these stores in the meantime: holding the queue
32943301
// until the run settles is exactly what makes the rollback safe again. Skipping it would
@@ -3444,6 +3451,13 @@ export class ClineProvider
34443451

34453452
await this.postStateToWebview()
34463453
} catch (error) {
3454+
// Two failures must NOT be compensated here: a replacement activation
3455+
// failure after the deletion committed (documented contract: the
3456+
// deletion stands), and any failure whose scoped compensation
3457+
// already ran inside the try.
3458+
if (error instanceof ProfileDeletionActivationError || innerCompensationRan) {
3459+
throw error
3460+
}
34473461
// The manager delete committed but a later write failed: restore the
34483462
// deleted record first, then the shared metadata, selection, and shared
34493463
// settings the deletion had rewritten, and finally merge the affected

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,9 +3488,13 @@ describe("ClineProvider", () => {
34883488
id: "keeper-id",
34893489
apiProvider: providerIdentifiers.anthropic,
34903490
}
3491+
// The record restore must not resurrect the deleted profile: a
3492+
// saveConfig call here would put the committed deletion back.
3493+
const saveSpy = vi.fn().mockResolvedValue("doomed-id")
34913494
// @ts-ignore - Replace providerSettingsManager with a test double whose activation fails.
34923495
provider.providerSettingsManager = {
34933496
deleteConfig: vi.fn().mockResolvedValue(undefined),
3497+
saveConfig: saveSpy,
34943498
getProfile: vi.fn().mockImplementation(({ name }: { name: string }) =>
34953499
Promise.resolve(
34963500
name === "doomed-profile"
@@ -3520,6 +3524,8 @@ describe("ClineProvider", () => {
35203524
expect(postSpy).toHaveBeenCalled()
35213525
// The committed deletion is not rolled back by the failed activation.
35223526
expect(provider.providerSettingsManager.deleteConfig).toHaveBeenCalledTimes(1)
3527+
// The outer write-group restore must not resurrect the deleted record.
3528+
expect(saveSpy).not.toHaveBeenCalled()
35233529
await provider.dispose()
35243530
})
35253531

@@ -5395,6 +5401,7 @@ describe("ClineProvider", () => {
53955401
getProfile: vi
53965402
.fn()
53975403
.mockResolvedValueOnce({ name: "doomed-profile", ...doomedSettings })
5404+
.mockResolvedValueOnce({ name: "doomed-profile", ...doomedSettings })
53985405
.mockResolvedValueOnce({ name: "keeper-profile", ...keeperSettings }),
53995406
}
54005407
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)

0 commit comments

Comments
 (0)