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): 按源模型能力恢复刷新时的历史档位

Dash86f2f6684ce2
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 b0e92035b7..aa3753fa08 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionRuntimeControl.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionRuntimeControl.test.ts
@@ -1,5 +1,7 @@
import { afterEach, describe, expect, it } from 'vitest';
import type { ProviderView } from '@cindy/model-providers';
+import { clearAllSessionRuntimeAxes, getSessionEffort, setSessionEffort } from '../../maker-host/session-effort-store.js';
+import { buildDeferredRuntimeSelectionProfile } from '../../../shared/runtimeModelSwitchGate';
import {
acceptSessionRuntimeAxisMutation,
@@ -20,6 +22,7 @@ import {
recordUserSessionRuntimeMutation,
resolveCompatibleSessionRuntimeAxisPatch,
resolveSessionRuntimeAxes,
+ resolveSessionRuntimeRefreshEffort,
sessionRuntimeControlOwnerEpochMatches,
sessionRuntimeGenerationMatches,
settlePendingSessionRuntimeMutation,
@@ -28,6 +31,7 @@ import {
afterEach(() => {
clearAllSessionRuntimeControlStates();
+ clearAllSessionRuntimeAxes();
});
const current: SessionRuntimeProfile = {
@@ -608,6 +612,36 @@ describe('session runtime fallback selection', () => {
.toMatchObject({ ok: true, fastMode: false });
});
+ // PR #6872: the store and override are cleared on a fixed-effort user switch,
+ // while the NOT NULL row retains xhigh. Builder-only tests missed this lookup.
+ // Unit tier: use the real store/control lifecycle and observe the refresh profile.
+ it.each([false, true])('refresh preserves a cleared fixed effort (cold=%s)', (cold) => {
+ const sessionId = 'runtime-refresh-fixed';
+ const model = provider('xd', [{ id: 'fixed', efforts: [] }]).models.codex![0]!;
+ if (!cold) {
+ setSessionEffort(sessionId, 'xhigh');
+ acceptSessionRuntimeMutation({ sessionId, source: 'agent', profile: current, deferred: false });
+ setSessionEffort(sessionId, null);
+ recordUserSessionRuntimeMutation(sessionId);
+ }
+ expect(getSessionRuntimeControlSnapshot(sessionId).effectiveOverride).toBeNull();
+ const profile = buildDeferredRuntimeSelectionProfile({
+ agentKind: 'pi', model: model.id, providerId: 'xd', currentFastMode: false,
+ currentEffort: resolveSessionRuntimeRefreshEffort({ model,
+ storedEffort: getSessionEffort(sessionId) as SessionRuntimeProfile['effort'],
+ persistedEffort: 'xhigh' }),
+ });
+ expect(profile.effort).toBeNull();
+ });
+
+ it('keeps live adjustable effort and normalizes cold persisted effort', () => {
+ const model = provider('xd', [{ id: 'adjustable', efforts: ['medium', 'xhigh'] }]).models.codex![0]!;
+ expect(resolveSessionRuntimeRefreshEffort({ model, storedEffort: 'xhigh', persistedEffort: 'medium' }))
+ .toBe('xhigh');
+ expect(resolveSessionRuntimeRefreshEffort({ model, storedEffort: null, persistedEffort: 'ultra' }))
+ .toBe('medium');
+ });
+
it('rejects explicit unsupported axes and normalizes inherited axes', () => {
const model = provider('xd', [
{ id: 'gpt-main', efforts: ['medium'], fast: false },
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 8f1a4f5f70..18dae74717 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -172,6 +172,7 @@ import type {
UserMessage,
} from '@cindy/maker-core';
import {
+ actualSourceIdForModel,
effectiveSourceIdForModel,
isModelSelectableForNewRoute,
buildUserProvider,
@@ -1293,6 +1294,7 @@ import {
resolveCompatibleSessionRuntimeEffort,
resolveCompatibleSessionRuntimeAxisPatch,
resolveSessionRuntimeAxes,
+ resolveSessionRuntimeRefreshEffort,
sessionRuntimeGenerationMatches,
sessionRuntimeControlOwnerEpochMatches,
settlePendingSessionRuntimeMutation,
@@ -21907,13 +21909,6 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
return { deferred: false, superseded: true };
}
const routeExplicit = internalOptions.routeExplicit !== false;
- // Pi configuration refreshes (including scheduled sends) omit selection.
- // Omission must preserve the effective effort, including an explicit null;
- // otherwise the UI and the next send see a different axis from native Pi.
- const currentRuntimeProfile = getSessionRuntimeControlSnapshot(sessionId).effectiveOverride;
- const currentEffort = currentRuntimeProfile
- ? currentRuntimeProfile.effort
- : ((getSessionEffort(sessionId) ?? runtimeStatus.effort ?? null) as SessionRuntimeProfile['effort']);
// 同引擎重选是 switch ack 后的第二段写入。另一控制端若在两段之间更新(含
// set→clear ABA),修订号已变化:旧 SET_MODEL 必须在任何 route/DB 副作用前让位。
if (
@@ -21986,6 +21981,28 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const sshCodexProviders = runtimeStatus.remoteHostId && runtimeStatus.agentKind === 'codex'
? await readSshCodexModelList({ id: runtimeStatus.remoteHostId }, listSshCodexProviders)
: null;
+ // Route-only refreshes preserve the current axes. A cleared store can mean a
+ // fixed-effort model, so normalize the NOT NULL row against the SOURCE model
+ // before using it; the requested target must not revive its historical rank.
+ const currentRuntimeProfile = getSessionRuntimeControlSnapshot(sessionId).effectiveOverride;
+ const currentLiveSession = maker.getSession(sessionId);
+ const currentAgentKind = currentLiveSession?.agentKind ?? dbToMakerAgentKind(runtimeStatus.agentKind);
+ const currentModelId = currentLiveSession?.model ?? internalOptions.previousPiRoute?.model ?? runtimeStatus.model;
+ const runtimeProviders = sshCodexProviders ?? await getDesktopProviderService().listProviders({
+ allowSideEffects: false,
+ catalog: getActiveCatalog(),
+ });
+ const currentSourceId = currentProviderId ?? actualSourceIdForModel(
+ runtimeProviders, null, currentModelId, currentAgentKind,
+ );
+ const currentEffort = currentRuntimeProfile
+ ? currentRuntimeProfile.effort
+ : resolveSessionRuntimeRefreshEffort({
+ model: findCatalogModel(runtimeProviders.find(p => p.id === currentSourceId),
+ currentModelId, currentAgentKind, { exact: true }) ?? null,
+ storedEffort: getSessionEffort(sessionId) as SessionRuntimeProfile['effort'],
+ persistedEffort: runtimeStatus.effort ?? null,
+ });
if (sshCodexProviders) {
assertSshCodexModel(sshCodexProviders, model, guardProviderId);
} else if (routeExplicit) {
@@ -22028,10 +22045,6 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
effectiveProviderId === null
? null
: (normalizeSessionProviderId(effectiveProviderId) ?? currentProviderId);
- const runtimeProviders = sshCodexProviders ?? await getDesktopProviderService().listProviders({
- allowSideEffects: false,
- catalog: getActiveCatalog(),
- });
const actualProviderId =
selectedProviderId ??
effectiveSourceIdForModel(runtimeProviders, null, model, runtimeAgentKind);
diff --git a/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts b/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts
index 90ff96c2f6..45c9bed2bc 100644
--- a/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionRuntimeControl.ts
@@ -418,6 +418,17 @@ export function resolveCompatibleSessionRuntimeEffort(
);
}
+/** A cleared fixed-effort axis must not revive the NOT NULL row's historical rank. */
+export function resolveSessionRuntimeRefreshEffort(params: {
+ model: CatalogModel | null;
+ storedEffort: Effort | null;
+ persistedEffort: Effort | null;
+}): Effort | null {
+ return params.storedEffort ?? (params.model
+ ? resolveCompatibleSessionRuntimeEffort(params.model, params.persistedEffort)
+ : params.persistedEffort);
+}
+
export function resolveSessionRuntimeAxes(params: {
model: CatalogModel;
effort: Effort | null;