Skip to content

Commit 8023403

Browse files
committed
fix(task): scope profile updates to the focused task
1 parent 1e5ba45 commit 8023403

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/core/task/Task.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
703703
}
704704

705705
this.providerProfileChangeListener = async () => {
706+
if (provider.getCurrentTask()?.taskId !== this.taskId) {
707+
return
708+
}
709+
706710
try {
707711
const newState = await provider.getState()
708712
if (newState?.apiConfiguration) {

src/core/task/__tests__/Task.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Anthropic } from "@anthropic-ai/sdk"
88

99
import {
1010
providerIdentifiers,
11+
RooCodeEventName,
1112
type GlobalState,
1213
type ProviderSettings,
1314
type ModelInfo,
@@ -526,6 +527,48 @@ describe("Cline", () => {
526527
const metadata = requireDefined(createMessage.mock.calls[0])[2]
527528
expect(metadata?.mode).toBe("ask")
528529
})
530+
531+
it("only applies profile changes to the focused task", async () => {
532+
const parentConfiguration: ProviderSettings = {
533+
...mockApiConfig,
534+
apiModelId: "parent-model",
535+
rateLimitSeconds: 4,
536+
}
537+
const childConfiguration: ProviderSettings = {
538+
...mockApiConfig,
539+
apiModelId: "child-model",
540+
rateLimitSeconds: 8,
541+
}
542+
const activeConfiguration: ProviderSettings = {
543+
...mockApiConfig,
544+
apiModelId: "active-model",
545+
rateLimitSeconds: 12,
546+
}
547+
const parent = new Task({
548+
provider: mockProvider,
549+
apiConfiguration: parentConfiguration,
550+
taskId: "parent-task",
551+
task: "parent task",
552+
startTask: false,
553+
})
554+
const child = new Task({
555+
provider: mockProvider,
556+
apiConfiguration: childConfiguration,
557+
taskId: "child-task",
558+
task: "child task",
559+
startTask: false,
560+
})
561+
vi.spyOn(mockProvider, "getCurrentTask").mockReturnValue(child)
562+
vi.spyOn(mockProvider, "getState").mockResolvedValue({ apiConfiguration: activeConfiguration })
563+
564+
mockProvider.emit(RooCodeEventName.ProviderProfileChanged, {
565+
name: "active-profile",
566+
provider: activeConfiguration.apiProvider,
567+
})
568+
569+
await vi.waitFor(() => expect(child.apiConfiguration).toEqual(activeConfiguration))
570+
expect(parent.apiConfiguration).toEqual(parentConfiguration)
571+
})
529572
})
530573

531574
describe("sayAndCreateMissingParamError", () => {

0 commit comments

Comments
 (0)