Skip to content

Commit 268bb11

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 62070d1 commit 268bb11

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
@@ -2567,6 +2567,7 @@ export class ClineProvider
25672567
// serving the settings captured before the save under the same name.
25682568
if (this.pinnedProfileName === name) {
25692569
await this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2570+
this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
25702571
}
25712572
await this.refreshViewLocalStateForUpdatedProfile(name, providerSettings)
25722573
}
@@ -2916,6 +2917,13 @@ export class ClineProvider
29162917
affected.map(async (instance) => {
29172918
// Direct private access: compile-time safe across sibling instances.
29182919
await instance._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2920+
2921+
// The active task of a pinned view holds its own API handler built from
2922+
// the profile's settings: rebuild it with the saved settings or the
2923+
// running conversation keeps sending the old token even though the
2924+
// view's buffer has caught up. Direct private access across sibling
2925+
// instances of the same class is compile-time safe.
2926+
instance.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
29192927
await instance.postStateToWebview()
29202928
}),
29212929
)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8992,6 +8992,17 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
89928992
apiKey: "old-key",
89938993
}
89948994
vi.spyOn(sibling, "postStateToWebview").mockResolvedValue(undefined)
8995+
8996+
// The sibling has an active task built from the pre-save settings.
8997+
// Task is a class; the double assertion is the only way to attach a
8998+
// minimal double without the full provider/services graph.
8999+
const siblingTask = {
9000+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, apiKey: "old-key" },
9001+
updateApiConfiguration: vi.fn(),
9002+
}
9003+
vi.spyOn(sibling, "getCurrentTask").mockReturnValue(
9004+
siblingTask as unknown as ReturnType<typeof sibling.getCurrentTask>,
9005+
)
89959006
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
89969007
// @ts-ignore - Replace providerSettingsManager with a test double.
89979008
provider.providerSettingsManager = {
@@ -9012,6 +9023,13 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
90129023
apiProvider: providerIdentifiers.anthropic,
90139024
apiKey: "new-key",
90149025
})
9026+
9027+
// The active task's handler must be rebuilt with the saved settings,
9028+
// not just the view buffer.
9029+
expect(siblingTask.updateApiConfiguration).toHaveBeenCalledWith({
9030+
apiProvider: providerIdentifiers.anthropic,
9031+
apiKey: "new-key",
9032+
})
90159033
// Let queued view-local persistence settle while the console spies are
90169034
// still installed, so teardown has no pending writes.
90179035
await new Promise((resolve) => setTimeout(resolve, 50))

0 commit comments

Comments
 (0)