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(bot): retain model chain across temporary unavailability

xuzini-xzn0695b7307919
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 8ea70119d7..eb3426427a 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts
@@ -137,6 +137,40 @@ describe('permanent Bot model selection', () => {
expect(await h.reconcile.preview('canonical')).toEqual(h.state.next);
expect(h.apply).not.toHaveBeenCalled();
});
+ describe.each(['paused', 'no-enabled-model'] as const)('after a temporarily %s profile', (unavailable) => {
+ it.each([
+ { pending: false, changed: false },
+ { pending: true, changed: false },
+ { pending: false, changed: true },
+ { pending: true, changed: true },
+ ])('compares the last known default chain (pending=$pending, changed=$changed)', async ({ pending, changed }) => {
+ const h = harness();
+ h.state.followsCindyDefault = true;
+ h.state.hasRuntimeOverride = true;
+ if (pending) h.state.next = { ...h.state.current, model: 'pending-fallback' };
+ await h.reconcile('canonical');
+ const chain = h.state.chain;
+ if (unavailable === 'paused') {
+ h.read.mockResolvedValueOnce(null);
+ await h.reconcile('canonical');
+ } else {
+ h.state.chain = [];
+ await expect(h.reconcile('canonical')).rejects.toThrow('[PRECONDITION_FAILED]');
+ }
+ expect(h.apply).not.toHaveBeenCalled();
+ h.state.chain = changed ? [{ ...chain[0]!, model: 'new-primary', providerId: 'new-source' }] : chain;
+ const expected = changed
+ ? expect.objectContaining({ agentKind: 'codex', model: 'new-primary', providerId: 'new-source' })
+ : h.state.next ?? h.state.current;
+ await expect(h.reconcile.preview('canonical')).resolves.toEqual(expected);
+ await h.reconcile('canonical');
+ if (changed) {
+ expect(h.apply).toHaveBeenCalledExactlyOnceWith('canonical', expected, h.state.current);
+ } else {
+ expect(h.apply).not.toHaveBeenCalled();
+ }
+ });
+ });
it('previews a draft and then saved chain without consuming the next-send change', async () => {
const h = harness();
h.state.hasRuntimeOverride = true;
diff --git a/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts b/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts
index aab4b80436..32a8785d2e 100644
--- a/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts
+++ b/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts
@@ -119,13 +119,12 @@ export function createBotModelRouteReconciler(deps: {
if (deps.ownerEpoch() !== epoch) throw new Error('Bot model route owner changed');
if ((revisions.get(sessionId) ?? 0) !== revision) continue;
if (!state) {
- // Paused profiles are absent from the apply reader. Keep an explicit
- // save pending until resume can accept it and invalidate the scope.
- if (configured.get(sessionId) !== '') configured.delete(sessionId);
+ // Paused profiles are absent from the apply reader. Retain the last
+ // known chain (or explicit-save marker) so resume can detect changes.
return;
}
if (!state.chain.length) {
- configured.delete(sessionId);
+ // A temporary loss of model visibility must not erase that baseline.
throwIpcError('PRECONDITION_FAILED', '请先选择已开启的伙伴模型');
}
const key = JSON.stringify(state.chain);