Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(codex): match account provider catalog identities

Cindy85a4c79d1c45
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts
index 5e2078d376..3eaf82ab65 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts
@@ -1,4 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
+import { BUNDLED_CATALOG, buildUserProvider } from '@cindy/model-providers';
import {
isCodexThreadModelProviderIdentityMismatch,
@@ -9,9 +10,11 @@ import {
type PrepareLocalCodexCredentialModeSwitchInput,
} from '../codex-credential-switch.js';
import { rehydrateCloseSuppression } from '../rehydrateCloseSuppression.js';
+import { setActiveCatalog } from '../active-catalog.js';
afterEach(() => {
rehydrateCloseSuppression.resetForTest();
+ setActiveCatalog(BUNDLED_CATALOG);
});
describe('shouldCloseSessionForCredentialSwitch codex mode', () => {
@@ -169,6 +172,29 @@ describe('shouldCloseSessionForCredentialSwitch codex mode', () => {
expect(shouldCloseSessionForCredentialSwitch(input)).toBe(false);
});
+ it('matches a raw OpenAI identity for an account-specific Codex provider id', () => {
+ const account = buildUserProvider({
+ id: 'openai-account', name: 'OpenAI account',
+ auth: { method: 'oauth', native: 'codex' },
+ runtimes: { codex: { baseUrl: 'https://chatgpt.com/backend-api/codex', models: [] } },
+ }, { modelRegistry: BUNDLED_CATALOG.modelRegistry });
+ setActiveCatalog({
+ ...BUNDLED_CATALOG,
+ providers: [...BUNDLED_CATALOG.providers, account],
+ });
+ const input = {
+ agentKind: 'codex',
+ currentProviderId: 'openai',
+ nextProviderId: 'openai-account',
+ currentModel: 'gpt-5.4',
+ nextModel: 'gpt-5.5',
+ currentCodexProxyActive: true,
+ currentCodexThreadModelProviderId: 'openai',
+ } as const;
+ expect(isCodexThreadModelProviderIdentityMismatch(input)).toBe(false);
+ expect(shouldCloseSessionForCredentialSwitch(input)).toBe(false);
+ });
+
it('still closes a gateway Codex session when switching to OAuth on a proxy-active host', () => {
expect(shouldCloseSessionForCredentialSwitch({
agentKind: 'codex',
diff --git a/apps/desktop/src/main/maker-host/codex-credential-switch.ts b/apps/desktop/src/main/maker-host/codex-credential-switch.ts
index 830c95c422..8e7429b852 100644
--- a/apps/desktop/src/main/maker-host/codex-credential-switch.ts
+++ b/apps/desktop/src/main/maker-host/codex-credential-switch.ts
@@ -210,13 +210,19 @@ export function isCodexThreadModelProviderIdentityMismatch(
const actualIsAppliedCustomProviderIdentity = isAppliedCodexCustomProviderIdentity(
actualThreadModelProviderId,
);
+ const targetProvider = getActiveCatalog().providers.find(
+ (provider) => provider.id === nextProviderId,
+ );
+ const targetCatalogId = targetProvider ? providerCatalogId(targetProvider) : null;
// Older app-server versions may report the logical provider id directly
// (for example `openai`) instead of Cindy's materialized `cindy_openai`
- // alias. When the target logical route is the same provider, that raw id is
- // a matching identity; only a route crossing needs a rebuild.
+ // alias. Account-specific OpenAI ids also share the catalog identity
+ // `openai`; when the target catalog identity matches, only a route crossing
+ // needs a rebuild.
const actualMatchesTargetLogicalProvider =
actualThreadModelProviderId !== null &&
- actualThreadModelProviderId === nextProviderId;
+ (actualThreadModelProviderId === nextProviderId ||
+ actualThreadModelProviderId === targetCatalogId);
// The app-server may report a provider id that is not one of Cindy's
// materialized identities (for example `openai`, Azure, or a custom provider).
// It is still a sticky thread identity. Treating those ids as unknown lets a