Skip to content

Commit 8708abf

Browse files
committed
fix: Gate auth-driven Roo model refresh to active provider only
Prevents unnecessary router model fetches when auth state changes and Roo is not the active provider. This reduces memory pressure by avoiding large model payload fetches and cache reconciliation when using non-Roo providers. - Gate requestRooModels by current provider === 'roo' - Add test coverage for auth gating behavior
1 parent ff0c65a commit 8708abf

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,13 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
440440
// Watch for authentication state changes and refresh Roo models
441441
useEffect(() => {
442442
const currentAuth = state.cloudIsAuthenticated ?? false
443-
if (!prevCloudIsAuthenticated && currentAuth) {
444-
// User just authenticated - refresh Roo models with the new auth token
443+
const currentProvider = state.apiConfiguration?.apiProvider
444+
if (!prevCloudIsAuthenticated && currentAuth && currentProvider === "roo") {
445+
// User just authenticated and Roo is the active provider - refresh Roo models
445446
vscode.postMessage({ type: "requestRooModels" })
446447
}
447448
setPrevCloudIsAuthenticated(currentAuth)
448-
}, [state.cloudIsAuthenticated, prevCloudIsAuthenticated])
449+
}, [state.cloudIsAuthenticated, prevCloudIsAuthenticated, state.apiConfiguration?.apiProvider])
449450

450451
const contextValue: ExtensionStateContextType = {
451452
...state,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { render, waitFor } from "@/utils/test-utils"
2+
import React from "react"
3+
4+
vi.mock("@src/utils/vscode", () => ({
5+
vscode: {
6+
postMessage: vi.fn(),
7+
},
8+
}))
9+
10+
import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
11+
import { vscode } from "@src/utils/vscode"
12+
13+
describe("ExtensionStateContext Roo auth gate", () => {
14+
beforeEach(() => {
15+
vi.clearAllMocks()
16+
})
17+
18+
function postStateMessage(state: any) {
19+
window.dispatchEvent(
20+
new MessageEvent("message", {
21+
data: {
22+
type: "state",
23+
state,
24+
},
25+
}),
26+
)
27+
}
28+
29+
it("does not post requestRooModels when auth flips and provider !== 'roo'", async () => {
30+
render(
31+
<ExtensionStateContextProvider>
32+
<div />
33+
</ExtensionStateContextProvider>,
34+
)
35+
36+
// Flip auth to true with a non-roo provider (anthropic)
37+
postStateMessage({
38+
cloudIsAuthenticated: true,
39+
apiConfiguration: { apiProvider: "anthropic" },
40+
})
41+
42+
// Should NOT fire auth-driven Roo refresh
43+
await waitFor(() => {
44+
const calls = (vscode.postMessage as any).mock.calls as any[][]
45+
const hasRequest = calls.some((c) => c[0]?.type === "requestRooModels")
46+
expect(hasRequest).toBe(false)
47+
})
48+
})
49+
50+
it("posts requestRooModels when auth flips and provider === 'roo'", async () => {
51+
render(
52+
<ExtensionStateContextProvider>
53+
<div />
54+
</ExtensionStateContextProvider>,
55+
)
56+
57+
// Ensure prev false (explicit)
58+
postStateMessage({
59+
cloudIsAuthenticated: false,
60+
apiConfiguration: { apiProvider: "roo" },
61+
})
62+
63+
vi.clearAllMocks()
64+
65+
// Flip to true with provider roo - should trigger
66+
postStateMessage({
67+
cloudIsAuthenticated: true,
68+
apiConfiguration: { apiProvider: "roo" },
69+
})
70+
71+
await waitFor(() => {
72+
expect(vscode.postMessage).toHaveBeenCalledWith({ type: "requestRooModels" })
73+
})
74+
})
75+
})

0 commit comments

Comments
 (0)