Skip to content

Commit a84833a

Browse files
vitalyiegorovclaude
andcommitted
fix(web): resolve sidebar provider icons from the thread's own environment
The sidebar built its provider-instance map from primaryServerProvidersAtom alone, so threads on non-primary environments (T3 Connect, hosted app.t3.codes, multi-environment) either lost their provider icon and account badge entirely (no primary set) or silently borrowed the primary environment's entries when instance ids collide — and default instance ids are just driver slugs, so they always collide. Build a per-environment map from environmentServerConfigsAtom instead (with the primary backfill CommandPalette already uses) and scope row lookups and the badge heuristic to the thread's environmentId. Fixes #5289 Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent f2d5fc9 commit a84833a

3 files changed

Lines changed: 96 additions & 11 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ import { ProjectFavicon } from "./ProjectFavicon";
164164
import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
165165
import { getTriggerDisplayModelLabel } from "./chat/providerIconUtils";
166166
import {
167-
deriveProviderInstanceEntries,
167+
deriveProviderEntriesByEnvironment,
168168
shouldShowInstanceBadge,
169169
type ProviderInstanceEntry,
170170
} from "../providerInstances";
171-
import { primaryServerProvidersAtom } from "../state/server";
172171
import { useThreadRunningTerminalIds } from "../state/terminalSessions";
173172
import { stackedThreadToast, toastManager } from "./ui/toast";
174173
import { Button } from "./ui/button";
@@ -246,6 +245,8 @@ function WorkingDuration(props: { startedAt: string | null }) {
246245
);
247246
}
248247

248+
const EMPTY_PROVIDER_ENTRIES: ReadonlyMap<string, ProviderInstanceEntry> = new Map();
249+
249250
function terminalProcessLabel(count: number): string {
250251
return `${count} terminal ${count === 1 ? "process" : "processes"} running`;
251252
}
@@ -1860,15 +1861,18 @@ export default function Sidebar() {
18601861
() => sortLogicalProjectsForSidebar(unsortedProjectGroups, threads, sidebarProjectSortOrder),
18611862
[sidebarProjectSortOrder, threads, unsortedProjectGroups],
18621863
);
1863-
const serverProviders = useAtomValue(primaryServerProvidersAtom);
1864-
const providerEntryByInstanceId = useMemo(
1864+
const serverConfigs = useAtomValue(environmentServerConfigsAtom);
1865+
// Threads on non-primary environments (T3 Connect, hosted) resolve their
1866+
// provider entry from their own environment's config: default instance ids
1867+
// are driver slugs, so a flat map would collide across environments.
1868+
const providerEntriesByEnvironment = useMemo(
18651869
() =>
1866-
new Map(
1867-
deriveProviderInstanceEntries(serverProviders).map(
1868-
(entry) => [entry.instanceId as string, entry] as const,
1870+
deriveProviderEntriesByEnvironment(
1871+
[...serverConfigs].map(
1872+
([environmentId, config]) => [environmentId, config.providers] as const,
18691873
),
18701874
),
1871-
[serverProviders],
1875+
[serverConfigs],
18721876
);
18731877
const projectCwdByKey = useMemo(
18741878
() =>
@@ -1989,7 +1993,6 @@ export default function Sidebar() {
19891993
// the partition works directly off live shells: no archived-snapshot
19901994
// merging, no optimistic holds. Archived threads remain hidden here —
19911995
// archive keeps its original "remove from sidebar" meaning.
1992-
const serverConfigs = useAtomValue(environmentServerConfigsAtom);
19931996
const {
19941997
pinnedThreads,
19951998
reorderablePinnedKeys,
@@ -3596,7 +3599,10 @@ export default function Sidebar() {
35963599
) ?? null
35973600
}
35983601
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
3599-
providerEntryByInstanceId={providerEntryByInstanceId}
3602+
providerEntryByInstanceId={
3603+
providerEntriesByEnvironment.get(thread.environmentId) ??
3604+
EMPTY_PROVIDER_ENTRIES
3605+
}
36003606
isHighlighted={activeSearchResultIndex === index}
36013607
isRouteActive={routeThreadKey === threadKey}
36023608
resultId={`sidebar-thread-search-result-${index}`}
@@ -3705,7 +3711,10 @@ export default function Sidebar() {
37053711
`${thread.environmentId}:${thread.projectId}`,
37063712
) ?? null
37073713
}
3708-
providerEntryByInstanceId={providerEntryByInstanceId}
3714+
providerEntryByInstanceId={
3715+
providerEntriesByEnvironment.get(thread.environmentId) ??
3716+
EMPTY_PROVIDER_ENTRIES
3717+
}
37093718
timestampFormat={timestampFormat}
37103719
onThreadClick={handleThreadClick}
37113720
onThreadActivate={navigateToThread}

‎apps/web/src/providerInstances.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3
22
import { describe, expect, it } from "vite-plus/test";
33
import {
44
applyProviderInstanceSettings,
5+
deriveProviderEntriesByEnvironment,
56
deriveProviderInstanceEntries,
67
getDefaultProviderInstanceModel,
78
isProviderInstancePickerReady,
@@ -17,13 +18,15 @@ function provider(input: {
1718
enabled?: boolean;
1819
availability?: ServerProvider["availability"];
1920
displayName?: string;
21+
accentColor?: string;
2022
status?: ServerProvider["status"];
2123
models?: ServerProvider["models"];
2224
}): ServerProvider {
2325
return {
2426
instanceId: ProviderInstanceId.make(input.instanceId),
2527
driver: input.provider,
2628
...(input.displayName ? { displayName: input.displayName } : {}),
29+
...(input.accentColor ? { accentColor: input.accentColor } : {}),
2730
enabled: input.enabled ?? true,
2831
installed: true,
2932
version: null,
@@ -132,6 +135,52 @@ describe("deriveProviderInstanceEntries", () => {
132135
});
133136
});
134137

138+
describe("deriveProviderEntriesByEnvironment", () => {
139+
it("keeps same-id default instances distinct per environment", () => {
140+
const byEnvironment = deriveProviderEntriesByEnvironment([
141+
[
142+
"local",
143+
[
144+
provider({
145+
provider: ProviderDriverKind.make("claude"),
146+
instanceId: "claude",
147+
displayName: "Claude Local",
148+
accentColor: "#112233",
149+
}),
150+
],
151+
],
152+
[
153+
"remote",
154+
[
155+
provider({
156+
provider: ProviderDriverKind.make("claude"),
157+
instanceId: "claude",
158+
displayName: "Claude Remote",
159+
accentColor: "#445566",
160+
}),
161+
],
162+
],
163+
]);
164+
165+
expect(byEnvironment.get("local")?.get("claude")?.displayName).toBe("Claude Local");
166+
expect(byEnvironment.get("local")?.get("claude")?.accentColor).toBe("#112233");
167+
expect(byEnvironment.get("remote")?.get("claude")?.displayName).toBe("Claude Remote");
168+
expect(byEnvironment.get("remote")?.get("claude")?.accentColor).toBe("#445566");
169+
});
170+
171+
it("never falls back to another environment's instances", () => {
172+
const byEnvironment = deriveProviderEntriesByEnvironment([
173+
["local", [provider({ provider: ProviderDriverKind.make("codex"), instanceId: "codex" })]],
174+
["empty", []],
175+
]);
176+
177+
expect(byEnvironment.get("empty")?.get("codex")).toBeUndefined();
178+
// Every environment gets its own bucket, so an absent lookup is a real
179+
// "this environment has no such instance", not a missing key.
180+
expect(byEnvironment.get("empty")?.size).toBe(0);
181+
});
182+
});
183+
135184
describe("resolveSelectableProviderInstance", () => {
136185
it("returns the requested instance when it is enabled and available", () => {
137186
const requested = ProviderInstanceId.make("claude_work");

‎apps/web/src/providerInstances.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,33 @@ export function deriveProviderInstanceEntries(
200200
});
201201
}
202202

203+
/**
204+
* Project several environments' `ServerProvider[]` into a nested
205+
* `environmentId → instanceId → entry` lookup.
206+
*
207+
* Instance ids are per-environment routing keys, and `defaultInstanceIdForDriver`
208+
* makes the default id literally the driver slug, so every environment running
209+
* the same driver reports the same id. Flattening across environments would
210+
* clobber entries and mis-resolve accent colors; lookups must stay scoped to
211+
* the thread's own environment.
212+
*/
213+
export function deriveProviderEntriesByEnvironment(
214+
providersByEnvironment: Iterable<readonly [string, ReadonlyArray<ServerProvider>]>,
215+
): ReadonlyMap<string, ReadonlyMap<string, ProviderInstanceEntry>> {
216+
const byEnvironment = new Map<string, ReadonlyMap<string, ProviderInstanceEntry>>();
217+
for (const [environmentId, providers] of providersByEnvironment) {
218+
byEnvironment.set(
219+
environmentId,
220+
new Map(
221+
deriveProviderInstanceEntries(providers).map(
222+
(entry) => [entry.instanceId as string, entry] as const,
223+
),
224+
),
225+
);
226+
}
227+
return byEnvironment;
228+
}
229+
203230
/**
204231
* Overlay the current settings configuration onto streamed provider snapshots.
205232
* Provider probes can briefly retain their previous `enabled` value after a

0 commit comments

Comments
 (0)