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(model-default): 目录刷新重新加载过的进行中任务也跟随 Auto 换来源

fmfsaisaiea92d3d9aebd
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts
index 95e0036455..690ee690f5 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/cindyAutoRouteFollow.test.ts
@@ -1,13 +1,19 @@
-import { describe, expect, it, vi } from 'vitest';
+import { afterEach, describe, expect, it, vi } from 'vitest';
import type { CatalogModel, ProviderSource, ProviderView } from '@cindy/model-providers';
import {
+ cindyAutoRouteToFollow,
followMovedCindyAutoRoutes,
movedCindyAutoProviderId,
type CindyAutoRoute,
type CindyAutoRouteFollowDeps,
} from '../cindyAutoRouteFollow.js';
+import {
+ acceptSessionRuntimeMutation,
+ clearSessionRuntimeControlState,
+ getSessionRuntimeControlSnapshot,
+} from '../sessionRuntimeControl.js';
const AUTO = 'auto/group-1';
@@ -263,3 +269,77 @@ describe('Auto 没有推理档位时的跨来源跟随', () => {
expect(stage).not.toHaveBeenCalled();
});
});
+
+describe('号池 → 平台:目录刷新按旧路由重新加载过的进行中任务', () => {
+ // 9333 上 706b7b9b 等任务的真实形态:任务库 effort 为空串;号池来源是 byok-<UUID>。
+ const TASK = '706b7b9b-ded3-4326-8c81-9bbf5a45857a';
+ const REAL_AUTO = 'auto/d00e8b7f-fb6f-4045-922f-310da7b839fc';
+ const POOL = 'byok-f83a176f-8e24-494c-8e88-290584b05a76';
+ const dbRow = {
+ agentKind: 'pi',
+ model: REAL_AUTO,
+ providerId: POOL,
+ effort: '',
+ fastMode: false,
+ } as const;
+ const poolRoute = { ...dbRow, effort: null };
+ /** Cindy AI 已列出 Auto,号池目录也已刷新、不再列它。 */
+ const afterBothRefreshed = [
+ provider('xd', 'builtin', ['auto', REAL_AUTO, 'z-ai/glm-5.3-flash']),
+ provider(POOL, 'organization', [`${POOL}/e2e-model`]),
+ ];
+
+ afterEach(() => clearSessionRuntimeControlState(TASK));
+
+ function runtimeState(hasPendingSelection = false) {
+ const control = getSessionRuntimeControlSnapshot(TASK);
+ return { effective: control.effectiveOverride ?? dbRow, control, hasPendingSelection };
+ }
+
+ /** 先刷新的 Cindy AI 触发上下文刷新:号池目录还是旧的,按号池路由重新加载(立即生效)。 */
+ function reloadWithStalePool() {
+ acceptSessionRuntimeMutation({
+ sessionId: TASK,
+ source: 'agent',
+ deferred: false,
+ profile: poolRoute,
+ });
+ }
+
+ it('重新加载写上的运行时覆盖就是当前路由,照常拿来跟随', () => {
+ reloadWithStalePool();
+ expect(cindyAutoRouteToFollow(runtimeState())).toEqual(poolRoute);
+ });
+
+ it('号池刷新后再跑跟随:登记下一条消息切到 Cindy AI', async () => {
+ reloadWithStalePool();
+ const stage = vi.fn(async () => {});
+ await expect(
+ followMovedCindyAutoRoutes({
+ listCandidates: async () => [{ sessionId: TASK, ...dbRow }],
+ listProviders: async () => afterBothRefreshed,
+ withSessionLock: async (_sessionId, run) => run(),
+ readRoute: async () => cindyAutoRouteToFollow(runtimeState()),
+ stage,
+ assertCurrent: () => {},
+ }),
+ ).resolves.toBe(1);
+ expect(stage).toHaveBeenCalledWith(TASK, { ...poolRoute, providerId: 'xd' });
+ });
+
+ it('负向:故障切换中的任务不跟随', () => {
+ acceptSessionRuntimeMutation({
+ sessionId: TASK,
+ source: 'fallback',
+ deferred: false,
+ previousProfile: poolRoute,
+ profile: { ...poolRoute, model: 'z-ai/glm-5.3-flash', providerId: 'xd' },
+ });
+ expect(cindyAutoRouteToFollow(runtimeState())).toBeNull();
+ });
+
+ it('负向:已有登记的切换不覆盖', () => {
+ reloadWithStalePool();
+ expect(cindyAutoRouteToFollow(runtimeState(true))).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts b/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts
index c76ba26081..206bc31061 100644
--- a/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts
+++ b/apps/desktop/src/main/maker-ipc/cindyAutoRouteFollow.ts
@@ -1,6 +1,7 @@
import { movedCindyAutoSourceId, type AgentKind, type ProviderView } from '@cindy/model-providers';
import { isSupportedRuntimeEffort } from './runtimeSelectionAxes.js';
+import type { SessionRuntimeControlSnapshot } from './sessionRuntimeControl.js';
/**
* 进行中任务跟随服务端挪动的 Auto。
@@ -31,6 +32,24 @@ export function movedCindyAutoProviderId(
});
}
+/** 加锁后重读到的任务运行时状态。 */
+export interface CindyAutoRuntimeState {
+ /** 任务当前实际路由(有运行时覆盖时就是覆盖的那条)。 */
+ effective: CindyAutoRoute;
+ control: Pick<SessionRuntimeControlSnapshot, 'fallbackHop'>;
+ /** 用户或系统已登记、下一条消息生效的切换(含延后的运行时选择)。 */
+ hasPendingSelection: boolean;
+}
+
+/**
+ * 要跟随的当前路由;已有登记的切换或正在故障切换时返回 null,不覆盖。
+ * 运行时覆盖本身不算改道:目录刷新按原路由重新加载进行中任务时也会写上它,这时它就是当前路由。
+ */
+export function cindyAutoRouteToFollow(state: CindyAutoRuntimeState): CindyAutoRoute | null {
+ if (state.hasPendingSelection || state.control.fallbackHop > 0) return null;
+ return state.effective;
+}
+
export interface CindyAutoRouteFollowDeps {
/**
* 本地数据库是否已就绪。启动早期目录先到、数据库还没接管时直接跳过(不算失败);
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index cba13fc0a9..184675d064 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -512,7 +512,7 @@ import {
} from '../localDb/schema.js';
import { nextBotModelRoute, normalizeBotModelChain, type BotModelRoute } from '../../shared/botModelChain.js';
import { createBotModelRouteReconciler } from './botModelRouteReconciler.js';
-import { followMovedCindyAutoRoutes } from './cindyAutoRouteFollow.js';
+import { cindyAutoRouteToFollow, followMovedCindyAutoRoutes } from './cindyAutoRouteFollow.js';
import { readEffectiveBotModelChain, readEffectiveBotModelSelection } from '../maker-host/bot-model-chain-settings-store.js';
import {
isOrcaWorkerPermissionMode,
@@ -15061,14 +15061,17 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
}),
withSessionLock: withSendToSessionLock,
readRoute: async (sessionId) => {
- // 用户或系统已登记的切换、运行时改道都是更晚的决定,不覆盖。
- if (agentSwitchPending.get(sessionId)) return null;
- const credentialSwitch = getPendingCredentialSwitchTarget(sessionId);
- if (credentialSwitch && credentialSwitch.selectionSource !== 'agent') return null;
const profiles = await readSessionRuntimeProfiles(sessionId);
- if (!profiles || profiles.pendingMutation || profiles.control.effectiveOverride)
- return null;
- return profiles.effective;
+ if (!profiles) return null;
+ const credentialSwitch = getPendingCredentialSwitchTarget(sessionId);
+ return cindyAutoRouteToFollow({
+ effective: profiles.effective,
+ control: profiles.control,
+ hasPendingSelection:
+ !!agentSwitchPending.get(sessionId) ||
+ (!!credentialSwitch && credentialSwitch.selectionSource !== 'agent') ||
+ !!profiles.pendingMutation,
+ });
},
stage: (sessionId, route) => stageSessionRouteSelection(sessionId, route, route.agentKind),
assertCurrent: () => {