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(runtime): preserve Codex transport in automatic fallback

Dante8c2c3d1a3348
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionRuntimeControl.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionRuntimeControl.test.ts
index ff6ddcbf79..483af4e44a 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionRuntimeControl.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionRuntimeControl.test.ts
@@ -663,6 +663,30 @@ describe('session runtime fallback selection', () => {
});
});
+ it('skips an exact-name bridge and keeps searching native Responses defaults', () => {
+ const bridge = provider('bridge', [{ id: 'gpt-main' }]);
+ bridge.routing.codex!.wireProtocol = 'openai-chat';
+ const result = pickSessionRuntimeFallback({
+ providers: [provider('openai', [{ id: 'gpt-main' }]), bridge,
+ provider('native', [{ id: 'recommended', defaults: true }])],
+ current, visitedRoutes: [], currentHop: 0, maxHops: 2,
+ });
+ expect(result).toMatchObject({ providerId: 'native', model: 'recommended' });
+ });
+
+ it('honors model-level bridge overrides and fails closed without the current route', () => {
+ const mixed = provider('mixed', [{ id: 'gpt-main' }]);
+ mixed.models.codex![0]!.codexCompatibilityWireProtocol = 'openai-chat';
+ for (const providers of [
+ [provider('openai', [{ id: 'gpt-main' }]), mixed],
+ [provider('native', [{ id: 'gpt-main' }])],
+ ]) {
+ expect(pickSessionRuntimeFallback({
+ providers, current, visitedRoutes: [], currentHop: 0, maxHops: 2,
+ })).toBeNull();
+ }
+ });
+
it('ignores disconnected sources even when they offer the same model', () => {
const disconnected = provider('disconnected', [{ id: 'gpt-main' }]);
disconnected.connected = false;
@@ -717,7 +741,7 @@ describe('session runtime fallback selection', () => {
]),
provider('chat-default', [{ id: 'chat-recommended', defaults: true }]),
],
- current: { ...current, model: 'missing-model' },
+ current,
visitedRoutes: [],
currentHop: 0,
maxHops: 2,
@@ -736,7 +760,7 @@ describe('session runtime fallback selection', () => {
'user',
),
],
- current: { ...current, model: 'missing-model' },
+ current,
visitedRoutes: [],
currentHop: 0,
maxHops: 2,
diff --git a/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts b/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts
index f0cdb0af56..e084c2de05 100644
--- a/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts
@@ -3,6 +3,7 @@ import type { Session as RendererSession } from '../../renderer/lib/ccAgent.type
import {
connectedProvidersForAgent,
isModelSelectableForNewRoute,
+ resolveCodexCompatibilityWireProtocol,
type CatalogModel,
type ProviderView,
} from '@cindy/model-providers';
@@ -458,6 +459,22 @@ export function pickSessionRuntimeFallback(params: {
visited.add(routeKey(params.current));
const rail = connectedProvidersForAgent([...params.providers], params.current.agentKind);
const candidates: Array<{ providerId: string; model: CatalogModel }> = [];
+ const currentProvider = params.providers.find((provider) => provider.id === params.current.providerId);
+ const currentModel = currentProvider?.models[params.current.agentKind]?.find(
+ (model) => model.id === params.current.model,
+ );
+ // Model names do not establish wire compatibility. In particular, a completed
+ // web_search_call may be serializable by a bridge while the next native search
+ // remains unsupported. Generic fallback has no task/request capability proof,
+ // so keep Codex on its current transport instead of silently introducing a bridge.
+ const currentCompatibility = currentProvider
+ ? resolveCodexCompatibilityWireProtocol(currentProvider, params.current.agentKind, currentModel)
+ : null;
+ const compatibleProvider = (provider: ProviderView, model: CatalogModel): boolean =>
+ params.current.agentKind !== 'codex' || (
+ currentProvider !== undefined && currentModel !== undefined &&
+ resolveCodexCompatibilityWireProtocol(provider, params.current.agentKind, model) === currentCompatibility
+ );
for (const provider of rail) {
for (const model of provider.models[params.current.agentKind] ?? []) {
@@ -468,7 +485,7 @@ export function pickSessionRuntimeFallback(params: {
) {
continue;
}
- if (model.id === params.current.model && provider.id !== params.current.providerId) {
+ if (compatibleProvider(provider, model) && model.id === params.current.model && provider.id !== params.current.providerId) {
candidates.push({ providerId: provider.id, model });
}
}
@@ -482,7 +499,7 @@ export function pickSessionRuntimeFallback(params: {
) {
continue;
}
- if (!model.newSessionDefault?.includes(params.current.agentKind)) continue;
+ if (!compatibleProvider(provider, model) || !model.newSessionDefault?.includes(params.current.agentKind)) continue;
candidates.push({ providerId: provider.id, model });
}
}