Skip to content

Commit 7b107d3

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 ccde56d commit 7b107d3

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,6 +2771,7 @@ export class ClineProvider
27712771
// serving the settings captured before the save under the same name.
27722772
if (this.pinnedProfileName === name) {
27732773
await this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings })
2774+
this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
27742775
}
27752776
await this.refreshViewLocalStateForUpdatedProfile(name, providerSettings)
27762777
}
@@ -3313,6 +3314,12 @@ export class ClineProvider
33133314
if (snapshot.instance._disposed) {
33143315
return
33153316
}
3317+
// The active task of a pinned view holds its own API handler built from
3318+
// the profile's settings: rebuild it with the saved settings or the
3319+
// running conversation keeps sending the old token even though the
3320+
// view's buffer has caught up. Direct private access across sibling
3321+
// instances of the same class is compile-time safe.
3322+
snapshot.instance.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true })
33163323
await snapshot.instance.postStateToWebview()
33173324
}),
33183325
)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10666,6 +10666,17 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
1066610666
apiKey: "old-key",
1066710667
}
1066810668
vi.spyOn(sibling, "postStateToWebview").mockResolvedValue(undefined)
10669+
10670+
// The sibling has an active task built from the pre-save settings.
10671+
// Task is a class; the double assertion is the only way to attach a
10672+
// minimal double without the full provider/services graph.
10673+
const siblingTask = {
10674+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, apiKey: "old-key" },
10675+
updateApiConfiguration: vi.fn(),
10676+
}
10677+
vi.spyOn(sibling, "getCurrentTask").mockReturnValue(
10678+
siblingTask as unknown as ReturnType<typeof sibling.getCurrentTask>,
10679+
)
1066910680
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
1067010681
// @ts-ignore - Replace providerSettingsManager with a test double.
1067110682
provider.providerSettingsManager = {
@@ -10690,6 +10701,13 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
1069010701
apiProvider: providerIdentifiers.anthropic,
1069110702
apiKey: "new-key",
1069210703
})
10704+
10705+
// The active task's handler must be rebuilt with the saved settings,
10706+
// not just the view buffer.
10707+
expect(siblingTask.updateApiConfiguration).toHaveBeenCalledWith({
10708+
apiProvider: providerIdentifiers.anthropic,
10709+
apiKey: "new-key",
10710+
})
1069310711
// Let queued view-local persistence settle while the console spies are
1069410712
// still installed, so teardown has no pending writes.
1069510713
await new Promise((resolve) => setTimeout(resolve, 50))

0 commit comments

Comments
 (0)