Skip to content

Commit a5a2f60

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 c6eac93 commit a5a2f60

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
@@ -2551,6 +2551,7 @@ export class ClineProvider
25512551
// serving the settings captured before the save under the same name.
25522552
if (this.pinnedProfileName === name) {
25532553
await this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2554+
this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
25542555
}
25552556
await this.refreshViewLocalStateForUpdatedProfile(name, providerSettings)
25562557
}
@@ -2904,6 +2905,13 @@ export class ClineProvider
29042905
affected.map(async (instance) => {
29052906
// Direct private access: compile-time safe across sibling instances.
29062907
await instance._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2908+
2909+
// The active task of a pinned view holds its own API handler built from
2910+
// the profile's settings: rebuild it with the saved settings or the
2911+
// running conversation keeps sending the old token even though the
2912+
// view's buffer has caught up. Direct private access across sibling
2913+
// instances of the same class is compile-time safe.
2914+
instance.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
29072915
await instance.postStateToWebview()
29082916
}),
29092917
)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8719,6 +8719,17 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
87198719
apiKey: "old-key",
87208720
}
87218721
vi.spyOn(sibling, "postStateToWebview").mockResolvedValue(undefined)
8722+
8723+
// The sibling has an active task built from the pre-save settings.
8724+
// Task is a class; the double assertion is the only way to attach a
8725+
// minimal double without the full provider/services graph.
8726+
const siblingTask = {
8727+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, apiKey: "old-key" },
8728+
updateApiConfiguration: vi.fn(),
8729+
}
8730+
vi.spyOn(sibling, "getCurrentTask").mockReturnValue(
8731+
siblingTask as unknown as ReturnType<typeof sibling.getCurrentTask>,
8732+
)
87228733
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
87238734
// @ts-ignore - Replace providerSettingsManager with a test double.
87248735
provider.providerSettingsManager = {
@@ -8739,6 +8750,13 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
87398750
apiProvider: providerIdentifiers.anthropic,
87408751
apiKey: "new-key",
87418752
})
8753+
8754+
// The active task's handler must be rebuilt with the saved settings,
8755+
// not just the view buffer.
8756+
expect(siblingTask.updateApiConfiguration).toHaveBeenCalledWith({
8757+
apiProvider: providerIdentifiers.anthropic,
8758+
apiKey: "new-key",
8759+
})
87428760
// Let queued view-local persistence settle while the console spies are
87438761
// still installed, so teardown has no pending writes.
87448762
await new Promise((resolve) => setTimeout(resolve, 50))

0 commit comments

Comments
 (0)