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(bots): preserve automation routes and retire stale restores

Chrisc013cfc1c325
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts
index 812ace0933..dab2735416 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts
@@ -18,6 +18,33 @@ function harness() {
}
describe('permanent Bot model selection', () => {
+ // Real companion automation failed before queued dispatch because its ordinary
+ // send reconciler switched back to the profile. Cover that consumer's decision,
+ // including cold startup and companions following the global default (unit tier).
+ it.each([false, true])('preserves an automation route across repeated sends and restart (default=%s)', async (followsCindyDefault) => {
+ const h = harness();
+ const state = { ...h.state, followsCindyDefault, hasScheduledModelOverride: true };
+ const deps = { ownerEpoch: () => 'owner', read: async () => state, apply: h.apply };
+ const reconcile = createBotModelRouteReconciler(deps);
+ await reconcile('canonical');
+ await reconcile('canonical');
+ await createBotModelRouteReconciler(deps)('canonical');
+ expect(h.apply).not.toHaveBeenCalled();
+ state.hasScheduledModelOverride = false;
+ await reconcile('canonical');
+ expect(h.apply).toHaveBeenCalledWith('canonical', expect.objectContaining({ model: 'luna' }), state.current);
+ });
+ it('lands a saved companion choice even when it equals the temporary automation route', async () => {
+ const h = harness();
+ const state = { ...h.state, hasScheduledModelOverride: true };
+ const reconcile = createBotModelRouteReconciler({ ownerEpoch: () => 'owner', read: async () => state, apply: h.apply });
+ await reconcile('canonical');
+ state.chain = [{ harness: 'pi', model: 'glm', providerId: 'xd', effort: 'high', fastMode: false }];
+ await reconcile.profileChanged('canonical');
+ // The landing callback must retire the old saved preference even for a no-op
+ // runtime switch, so the next ordinary message cannot resurrect the old model.
+ expect(h.apply).toHaveBeenCalledExactlyOnceWith('canonical', state.current, state.current);
+ });
it('stops a send instead of retaining the old runtime model when no enabled default remains', async () => {
const h = harness();
h.state.chain = [];
diff --git a/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts b/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts
index 671aa68771..421f7f7703 100644
--- a/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts
+++ b/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts
@@ -15,6 +15,7 @@ interface BotRouteState {
chain: BotModelRoute[];
current: RuntimeRoute;
hasRuntimeOverride: boolean;
+ hasScheduledModelOverride?: boolean;
followsCindyDefault?: boolean;
next?: RuntimeRoute;
}
@@ -26,6 +27,9 @@ function configuredRoute(
): RuntimeRoute | null {
const key = JSON.stringify(chain);
const isDraftChange = key !== JSON.stringify(state.chain);
+ // An automation owns its temporary route until ordinary input restores it.
+ // This also applies to companions following Cindy defaults and after restart.
+ if (!isDraftChange && state.hasScheduledModelOverride && (previous === undefined || previous === key)) return null;
if (!state.followsCindyDefault && !isDraftChange && state.hasRuntimeOverride && (previous === undefined || previous === key)) return null;
const primary = chain[0];
if (!primary) return null;
@@ -93,7 +97,7 @@ export function createBotModelRouteReconciler(deps: {
return;
}
const current = state.current;
- if (!sameRoute(route, current) || (state.next && !sameRoute(route, state.next))) {
+ if (state.hasScheduledModelOverride || !sameRoute(route, current) || (state.next && !sameRoute(route, state.next))) {
try {
await deps.apply(sessionId, route, state.current);
} catch (error) {
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 18dae74717..375c4a9fb1 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -15956,6 +15956,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
providerId: sessions.providerId,
effort: sessions.effort,
fastMode: sessions.fastMode,
+ scheduledModelBaseline: sessions.scheduledModelBaseline,
}).from(botSessionLinks)
.innerJoin(botProfiles, eq(botProfiles.id, botSessionLinks.botId))
.innerJoin(botProfileVersions, and(
@@ -15983,6 +15984,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
return {
chain: selection.chain,
followsCindyDefault: selection.followsCindyDefault,
+ hasScheduledModelOverride: parseScheduledModelBaseline(row.scheduledModelBaseline) !== null,
current: {
agentDeviceId: row.agentDeviceId,
agentKind: live?.agentKind ?? dbToMakerAgentKind(row.agentKind),
@@ -16000,6 +16002,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
},
apply: async (sessionId, route, current) => {
await stageSessionRouteSelection(sessionId, { ...route, agentDeviceId: route.agentDeviceId ?? null }, current.agentKind);
+ // A changed permanent companion choice supersedes the automation's saved
+ // preference, even if it selects the already-running temporary model.
+ // Keep the old preference if staging fails; never detach IM default following.
+ await updateScheduledPreference(sessionId, null);
// Consume the same model/Harness intent as the normal send path. Its
// verified window protection and history handoff also apply here; a Bot
// settings save need not wait for a second user message. Busy runtimes
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 14cdebd478..27a94a7f7e 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -371,6 +371,7 @@ harness + provider + model + effort + fastMode
- 同一轮最多按生效候选链各尝试一次;不得循环。用户显式配置的链不得追加目录候选。
- 同 harness 可在安全边界切模型;跨 harness 必须走既有 agent-switch / 交接重建事务。
- 伙伴设置中的显式模型保存立即同步当前主任务的运行选择;空闲时在既有安全边界完成切换,运行中先记录最新选择,在回复、工具与审批结束后的安全边界接替,不要求用户再发一条消息才能登记。连续改选以最后一次为准,选回当前路由应取消不同的待切换路由。
+- 自动化指定的临时模型在本轮发送中不被伙伴默认模型对齐覆盖,包括跟随全局默认的伙伴。主人随后保存新的伙伴模型选择时,该选择取代自动化留下的旧恢复偏好;即使新选择恰好等于临时运行模型,下一次聊天也不得恢复到旧选择。
- 模型配置只保留统一选择器入口,备用链仍在原组件内折叠;思考深度、Fast 与 Harness 不拆成独立设置页。缩窗交接复用已经核实目标窗口的延迟选择处理,完整记录与主任务身份保留,不绕过原生副作用重放限制。
- fallback 只改变当前任务的有效路由,不暗改 Profile 顺序。下一次确定性重建仍从首选开始。
- 存量单模型配置归一成一项候选链,不能在升级时改变用户已有选择。