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(maker-ipc): omit null effort from sessions DB patch for fixed-effort models (#3727)

lengjingxu6628012916db
diff --git a/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts b/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts
index 36921b43c4..c472e8c15e 100644
--- a/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts
+++ b/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts
@@ -280,6 +280,34 @@ describe('session runtime control wiring', () => {
expect(axisValidation).toBeLessThan(setModel.indexOf('persistSessionFields(sessionId'));
});
+ it('omits effort from the DB patch for fixed-effort models (sessions.effort NOT NULL)', () => {
+ const setModel = handlerBody(
+ registerSource,
+ 'const handleSetModel = async (',
+ 'const recoverRemoteRuntimeAxisPersistence',
+ );
+ // 固定 effort 模型(efforts.length === 0)的运行时语义是 effort: null,但
+ // sessions.effort 列是 NOT NULL——把 null 写进 DB patch 会让整个模型切换被
+ // NOT NULL 约束炸掉(issue #3691)。持久化 patch 必须省略该字段,内存 store
+ // 照常清 null,重启后按目标模型能力重新归一化。
+ const atomicPatch = setModel.indexOf('if (atomicSelection) {', setModel.indexOf('const patch: Record<string, unknown>'));
+ expect(atomicPatch).toBeGreaterThan(-1);
+ const persistCall = setModel.indexOf('persistSessionFields(sessionId', atomicPatch);
+ expect(persistCall).toBeGreaterThan(atomicPatch);
+ const patchBlock = setModel.slice(atomicPatch, persistCall);
+ expect(patchBlock).toContain('if (atomicSelection.effort !== null) {');
+ expect(patchBlock).toContain('patch.effort = atomicSelection.effort;');
+ });
+
+ it('normalizes hydrated effort to the current model capability on restart', () => {
+ // 重启后 DB 行里的 effort 是历史值;bootstrapSession hydrate 必须按当前模型
+ // 能力归一化(固定 effort → null,可调 → 兼容档),否则旧值会作为
+ // reasoningEffort 打给不支持的模型被 provider 拒绝(Greptile P1)。
+ expect(registerSource).toContain(
+ 'resolveCompatibleSessionRuntimeEffort(hydrateModel, efRow?.effort ?? null)',
+ );
+ });
+
it('commits user effort and Fast state only after the live runtime call succeeds', () => {
const effort = handlerBody(
registerSource,
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 18ae35322b..a490516576 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -946,6 +946,7 @@ import {
recordRecoveredSessionRuntimeAxisMutation,
recordUserSessionRuntimeAxisMutation,
recordUserSessionRuntimeMutation,
+ resolveCompatibleSessionRuntimeEffort,
resolveCompatibleSessionRuntimeAxisPatch,
resolveSessionRuntimeAxes,
sessionRuntimeGenerationMatches,
@@ -7860,7 +7861,25 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
setSessionEffort(session.id, runtimeOverride.effort);
setSessionFastMode(session.id, runtimeOverride.fastMode);
} else {
- setSessionEffort(session.id, efRow?.effort);
+ // DB 行里的 effort 是历史合法值(固定 effort 模型切换时省略了字段),
+ // hydrate 时必须按**当前模型能力**归一化:固定 effort 模型 → null,
+ // 可调模型 → 兼容档位。直接回灌旧值会把不支持 reasoningEffort 的模型
+ // 请求打给 provider 被拒(issue #3691 / PR #3727 Greptile P1)。
+ const hydrateProviderId = getSessionProvider(session.id) ?? o.providerId ?? null;
+ const hydrateProvider = getActiveCatalog().providers.find(
+ (candidate) => candidate.id === hydrateProviderId,
+ );
+ const hydrateModel = findCatalogModel(
+ hydrateProvider,
+ session.model,
+ o.agentKind,
+ );
+ setSessionEffort(
+ session.id,
+ hydrateModel
+ ? resolveCompatibleSessionRuntimeEffort(hydrateModel, efRow?.effort ?? null)
+ : efRow?.effort,
+ );
setSessionFastMode(session.id, !!efRow?.fastMode);
}
} catch (err) {
@@ -15810,7 +15829,14 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
);
}
if (atomicSelection) {
- patch.effort = atomicSelection.effort;
+ // 固定 effort 模型(efforts.length === 0)的运行时语义是 effort: null,
+ // 但 sessions.effort 列是 NOT NULL —— 运行时能力与持久化表示在此分离:
+ // DB patch 省略该字段,行内保留旧模型的历史合法值;内存 store(上面
+ // commitControlStores / setSessionEffort)照常清为 null,重启后按目标
+ // 模型能力重新归一化。不写 ''/"none" 等枚举外值,不改 schema。
+ if (atomicSelection.effort !== null) {
+ patch.effort = atomicSelection.effort;
+ }
patch.fastMode = atomicSelection.fastMode;
}
try {