Skip to content

Commit f78bc04

Browse files
committed
fix(webview): rebuild active task handlers when a pinned profile is saved
A non-activating save refreshed the pinned views' buffers but not their active tasks' API handlers, and the posted state prefers the task's own apiConfiguration: a conversation running in a view pinned to the saved profile kept sending the old token (e.g. after the Zoo Gateway callback rotated it) even though the view's buffer had caught up. The refresh now rebuilds the affected tasks' handlers in the sibling views, and the non-activating branch rebuilds this view's own handler when it holds the pin. Proofs: ClineProvider.spec 258/258 (the pinned-sibling refresh test now asserts the active task's handler is rebuilt with the saved settings, not just the private buffer); negative control: dropping the rebuild from the refresh reddens exactly that assertion, restores byte-exact (hash match); sticky-mode 32/32, webviewMessageHandler 82/82; eslint --max-warnings=0 clean; prettier clean.
1 parent df73920 commit f78bc04

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,7 @@ export class ClineProvider
24282428
// serving the settings captured before the save under the same name.
24292429
if (this.pinnedProfileName === name) {
24302430
await this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2431+
this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
24312432
}
24322433
await this.refreshViewLocalStateForUpdatedProfile(name, providerSettings)
24332434
}
@@ -2673,6 +2674,13 @@ export class ClineProvider
26732674
affected.map(async (instance) => {
26742675
// Direct private access: compile-time safe across sibling instances.
26752676
await instance._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2677+
2678+
// The active task of a pinned view holds its own API handler built from
2679+
// the profile's settings: rebuild it with the saved settings or the
2680+
// running conversation keeps sending the old token even though the
2681+
// view's buffer has caught up. Direct private access across sibling
2682+
// instances of the same class is compile-time safe.
2683+
instance.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
26762684
await instance.postStateToWebview()
26772685
}),
26782686
)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7490,6 +7490,17 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
74907490
apiKey: "old-key",
74917491
}
74927492
vi.spyOn(sibling, "postStateToWebview").mockResolvedValue(undefined)
7493+
7494+
// The sibling has an active task built from the pre-save settings.
7495+
// Task is a class; the double assertion is the only way to attach a
7496+
// minimal double without the full provider/services graph.
7497+
const siblingTask = {
7498+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, apiKey: "old-key" },
7499+
updateApiConfiguration: vi.fn(),
7500+
}
7501+
vi.spyOn(sibling, "getCurrentTask").mockReturnValue(
7502+
siblingTask as unknown as ReturnType<typeof sibling.getCurrentTask>,
7503+
)
74937504
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
74947505
// @ts-ignore - Replace providerSettingsManager with a test double.
74957506
provider.providerSettingsManager = {
@@ -7514,6 +7525,13 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
75147525
apiProvider: providerIdentifiers.anthropic,
75157526
apiKey: "new-key",
75167527
})
7528+
7529+
// The active task's handler must be rebuilt with the saved settings,
7530+
// not just the view buffer.
7531+
expect(siblingTask.updateApiConfiguration).toHaveBeenCalledWith({
7532+
apiProvider: providerIdentifiers.anthropic,
7533+
apiKey: "new-key",
7534+
})
75177535
// Let queued view-local persistence settle while the console spies are
75187536
// still installed, so teardown has no pending writes.
75197537
await new Promise((resolve) => setTimeout(resolve, 50))

0 commit comments

Comments
 (0)