GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): keep a shared instance ID even when environments report oth… · pingdotgg/t3code@edaf9c0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/settings
    • scopedModelSelection.ts
    • scopedSettings.test.ts
    • scopedSettings.ts
    • useScopedModelAvailability.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/settings/scopedModelSelection.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/scopedModelSelection.ts
+16-48Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,52 +39,34 @@ export interface ScopedModelEnvironment {
3939
readonly settings: Pick<ServerSettings, "textGenerators">;
4040
}
4141

42-
const identity = ({ auth }: ServerProvider) => [
43-
auth.type,
44-
auth.email?.toLowerCase(),
45-
auth.workspaceId,
46-
];
47-
48-
/** Unreported login, email, or workspace is unknown, not a conflict. */
49-
const knownConflict = (first: ServerProvider, second: ServerProvider) =>
50-
first.driver !== second.driver ||
51-
identity(first).some((value, index) => {
52-
const other = identity(second)[index];
53-
return value && other && value !== other;
54-
});
55-
5642
/** Instance IDs and names are machine-local; only a reported ChatGPT login identifies the account. */
57-
const chatGptAccount = (provider: ServerProvider) =>
58-
provider.driver === "codex" &&
59-
provider.auth.status === "authenticated" &&
60-
provider.auth.type === "chatgpt" &&
61-
provider.auth.email &&
62-
provider.auth.workspaceId
63-
? JSON.stringify(identity(provider))
43+
const chatGptAccount = ({ driver, auth }: ServerProvider) =>
44+
driver === "codex" &&
45+
auth.status === "authenticated" &&
46+
auth.type === "chatgpt" &&
47+
auth.email &&
48+
auth.workspaceId
49+
? `${auth.email.toLowerCase()}\n${auth.workspaceId}`
6450
: null;
6551

6652
const find = (providers: readonly ServerProvider[], instanceId: ProviderInstanceId) =>
6753
providers.find((provider) => provider.instanceId === instanceId);
6854

55+
/** Keeps an ID the destination has; remaps an absent one only through a unique ChatGPT account. */
6956
export function resolveScopedModelInstanceId(
7057
instanceId: ProviderInstanceId,
7158
sourceEnvironment: Pick<ScopedModelEnvironment, "providers">,
7259
destination: ScopedModelEnvironment,
73-
peers: readonly ServerProvider[] = [],
7460
key: ScopedModelSettingKey = "defaultModelSelection",
7561
): ProviderInstanceId | null {
76-
const source = find(sourceEnvironment.providers, instanceId);
77-
if (!source) return null;
7862
if (
7963
key === "reviewGuideModelSelection" &&
8064
scopedTextGenerator(destination.settings, instanceId, key)
8165
)
8266
return null;
83-
const sameId = find(destination.providers, instanceId);
84-
const compatible = (provider: ServerProvider) =>
85-
!peers.some((peer) => knownConflict(peer, provider));
86-
if (sameId && !knownConflict(source, sameId) && compatible(sameId)) return instanceId;
87-
const account = chatGptAccount(source);
67+
if (find(destination.providers, instanceId)) return instanceId;
68+
const source = find(sourceEnvironment.providers, instanceId);
69+
const account = source ? chatGptAccount(source) : null;
8870
if (account === null) return null;
8971
const matches = (providers: readonly ServerProvider[]) =>
9072
providers.filter((provider) => chatGptAccount(provider) === account);
@@ -93,7 +75,6 @@ export function resolveScopedModelInstanceId(
9375
return match &&
9476
rest.length === 0 &&
9577
matches(sourceEnvironment.providers).length === 1 &&
96-
compatible(match) &&
9778
scopedTextGenerator(destination.settings, match.instanceId, key) === undefined
9879
? match.instanceId
9980
: null;
@@ -117,24 +98,11 @@ export function scopedModelSelectionsEqual(
11798
Equal.equals(first, second)
11899
);
119100
}
120-
const firstProvider = find(firstEnvironment.providers, first.instanceId);
121-
const secondProvider = find(secondEnvironment.providers, second.instanceId);
122101
const sameInstance =
123-
first.instanceId === second.instanceId
124-
? !(firstProvider && secondProvider && knownConflict(firstProvider, secondProvider))
125-
: resolveScopedModelInstanceId(
126-
first.instanceId,
127-
firstEnvironment,
128-
secondEnvironment,
129-
[],
130-
key,
131-
) === second.instanceId &&
132-
resolveScopedModelInstanceId(
133-
second.instanceId,
134-
secondEnvironment,
135-
firstEnvironment,
136-
[],
137-
key,
138-
) === first.instanceId;
102+
first.instanceId === second.instanceId ||
103+
(resolveScopedModelInstanceId(first.instanceId, firstEnvironment, secondEnvironment, key) ===
104+
second.instanceId &&
105+
resolveScopedModelInstanceId(second.instanceId, secondEnvironment, firstEnvironment, key) ===
106+
first.instanceId);
139107
return sameInstance && Equal.equals({ ...first, instanceId: second.instanceId }, second);
140108
}
Collapse file

‎apps/web/src/components/settings/scopedSettings.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/scopedSettings.test.ts
+9-29Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -869,18 +869,12 @@ describe("model selections across environments' provider instances", () => {
869869
const lower = { email: "[email protected]" };
870870
const team = { workspaceId: "team" };
871871
const apiKey = { type: "apiKey" };
872-
const none = { type: undefined, email: undefined, workspaceId: undefined };
873872
const nameOnly = (id: string) => ({ ...a(id, { workspaceId: undefined }), displayName: "Gmail" });
874873
const claude = "claudeAgent";
875-
const cursor = "cursor";
876874
it.each([
877875
["same ID takes precedence", [a("x"), a("l")], [a("s"), a("x")], "x"],
878-
["same ID, email case differs", [a("x")], [a("x", lower)], "x"],
879-
["same ID, unknown identity", [a("x", {}, cursor)], [a("x", none, cursor)], "x"],
880-
["conflicting ID beside matching account", [a("l")], [a("l", other), a("s")], "s"],
881-
["the same ID on another account", [a("x")], [a("x", other)], null],
882-
["the same ID with another login", [a("x")], [a("x", apiKey)], null],
883-
["the same ID on another driver", [a("x")], [a("x", {}, claude)], null],
876+
["the same ID on another account", [a("x", {}, claude)], [a("x", other, claude)], "x"],
877+
["case-insensitive email", [a("l")], [a("s", lower)], "s"],
884878
["Claude, different IDs", [a("l", {}, claude)], [a("s", {}, claude)], null],
885879
["an API key account", [a("l", apiKey)], [a("s", apiKey)], null],
886880
["another workspace", [a("l")], [a("s", team)], null],
@@ -929,12 +923,6 @@ describe("model selections across environments' provider instances", () => {
929923
"textGenerationModelSelection",
930924
),
931925
).toBe(true);
932-
expect(
933-
scopedModelSelectionsEqual(selection, generator, selection, {
934-
...generator,
935-
providers: [a(id, other)],
936-
}),
937-
).toBe(false);
938926
expect(
939927
planScopedSettingsPatch(
940928
all,
@@ -990,23 +978,15 @@ describe("model selections across environments' provider instances", () => {
990978
expect.soft(mixed(luna, onServer)).toEqual([false, false]);
991979
expect.soft(mixed(luna, { ...onServer, model: "gpt-6-sol" })).toEqual([true, true]);
992980
expect.soft(mixed(x, x, new Map())).toEqual([false, false]);
993-
expect.soft(mixed(x, x, providers([a("x")], [a("x", other)]))).toEqual([true, true]);
994-
const third = environment("Third");
995-
const three = [target(laptop, x), target(server, x), target(third, x)];
996-
const identities = new Map([
997-
[laptop.environmentId, [a("x", none)]],
998-
[server.environmentId, [a("x")]],
999-
[third.environmentId, [a("x", other)]],
1000-
]);
1001-
expect.soft(scopedSettingsAreMixed(three, keys, identities)).toBe(true);
1002-
const connected = [laptop, server, third];
981+
// Main writes a shared ID everywhere even when each machine reports another account.
982+
expect.soft(mixed(x, x, providers([a("x")], [a("x", other)]))).toEqual([false, false]);
1003983
expect(
1004984
planScopedSettingsPatch(
1005-
resolveSettingsScope({}, [], connected),
1006-
connected,
985+
all,
986+
environments,
1007987
forKeys(x),
1008-
from(identities),
1009-
).serverWrites,
1010-
).toEqual([]);
988+
from(providers([a("x")], [a("x", other)])),
989+
).serverWrites.map((write) => write.patch),
990+
).toEqual([forKeys(x), forKeys(x)]);
1011991
});
1012992
});
Collapse file

‎apps/web/src/components/settings/scopedSettings.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/scopedSettings.ts
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ function forDestinationModels(
249249
patch: ServerSettingsPatch,
250250
modelSource: ScopedModelSource | null | undefined,
251251
destination: ScopedSettingsEnvironment,
252-
matched: Map<string, ServerProvider[]>,
253252
): ServerSettingsPatch | null {
254253
if (!modelSource || destination.environmentId === modelSource.target.environmentId) return patch;
255254
const { target: source, providersByEnvironment } = modelSource;
@@ -274,16 +273,13 @@ function forDestinationModels(
274273
continue;
275274
}
276275
if (!providers) return null;
277-
const peers = matched.get(key) ?? [];
278276
const instanceId = resolveScopedModelInstanceId(
279277
selection.instanceId,
280278
{ providers: providersByEnvironment.get(source.environmentId) ?? [] },
281279
{ providers, settings },
282-
peers,
283280
key,
284281
);
285282
if (instanceId === null) return null;
286-
matched.set(key, [...peers, providers.find((provider) => provider.instanceId === instanceId)!]);
287283
Object.assign(next, { [key]: { ...selection, instanceId } });
288284
}
289285
return next;
@@ -314,9 +310,8 @@ export function planScopedSettingsPatch(
314310
? serverKeys.filter((key) => !isProjectScopedSettingKey(key))
315311
: [];
316312
const unmatched = new Set<string>();
317-
const matched = new Map<string, ServerProvider[]>();
318313
const serverPatchFor = (environment: ScopedSettingsEnvironment) => {
319-
const mapped = forDestinationModels(serverPatch, modelSource, environment, matched);
314+
const mapped = forDestinationModels(serverPatch, modelSource, environment);
320315
if (mapped === null) unmatched.add(environment.label);
321316
return mapped ?? serverPatch;
322317
};
Collapse file

‎apps/web/src/components/settings/useScopedModelAvailability.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/settings/useScopedModelAvailability.ts
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
type ProviderInstanceId,
3-
type ServerProvider,
4-
type UnifiedSettings,
5-
} from "@t3tools/contracts";
1+
import { type ProviderInstanceId, type UnifiedSettings } from "@t3tools/contracts";
62

73
import { mergeEnvironmentSettings } from "../../hooks/useSettings";
84
import { getCustomModelOptionsByInstance } from "../../modelSelection";
@@ -34,7 +30,6 @@ export function useScopedModelDisabledReason(
3430
providers: (source && providersByEnvironment.get(source.environmentId)) ?? [],
3531
};
3632
const shownGenerator = scopedTextGenerator(settings, instanceId, key);
37-
const peers: ServerProvider[] = [];
3833
for (const candidate of targets) {
3934
const environment = environments.find(
4035
(entry) => entry.environmentId === candidate.environmentId,
@@ -59,13 +54,11 @@ export function useScopedModelDisabledReason(
5954
instanceId,
6055
sourceEnvironment,
6156
{ providers, settings: candidate.settings },
62-
peers,
6357
key,
6458
);
6559
if (localId === null) {
6660
return `A unique matching account could not be verified on ${environment.label}. Select that environment to choose its model separately.`;
6761
}
68-
peers.push(providers.find((provider) => provider.instanceId === localId)!);
6962
const entry = applyProviderInstanceSettings(
7063
deriveProviderInstanceEntries(providers),
7164
candidate.settings,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.