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(desktop): 预测 IPC 拒绝已删除会话

Shinku3f7fee04196f
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/predictPromptIpcBoundary.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/predictPromptIpcBoundary.test.ts
index 7feb8abe92..f2c588ef69 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/predictPromptIpcBoundary.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/predictPromptIpcBoundary.test.ts
@@ -28,7 +28,7 @@ const h = vi.hoisted(() => ({
},
),
/** 模拟 DB 返回的 session row */
- sessionRow: { remoteHostId: null, agentKind: null } as { remoteHostId: string | null; source?: string | null; agentKind: string | null; workingDir?: string | null } | undefined,
+ sessionRow: { remoteHostId: null, agentKind: null } as { remoteHostId: string | null; source?: string | null; agentKind: string | null; workingDir?: string | null; status?: string | null } | undefined,
}));
function nativeImageEmpty() {
@@ -303,6 +303,13 @@ describe('maker:predict-prompt — DB 防御纵深(远程会话拒绝)', () => {
await expect(invokePredict(VALID_REQUEST)).resolves.toEqual({ prompt: null });
expect(h.predict).not.toHaveBeenCalled();
});
+
+ it('session 为已删除(soft-deleted)时静默返回 null,不触发付费调用', async () => {
+ h.sessionRow = { remoteHostId: null, agentKind: 'cc', status: 'deleted' };
+
+ await expect(invokePredict(VALID_REQUEST)).resolves.toEqual({ prompt: null });
+ expect(h.predict).not.toHaveBeenCalled();
+ });
});
describe('maker:predict-prompt — 多窗口去重', () => {
diff --git a/apps/desktop/src/main/maker-ipc/title.ts b/apps/desktop/src/main/maker-ipc/title.ts
index 5155064a78..d5c7594033 100644
--- a/apps/desktop/src/main/maker-ipc/title.ts
+++ b/apps/desktop/src/main/maker-ipc/title.ts
@@ -450,12 +450,13 @@ export function registerMakerTitleIpc(options: RegisterMakerTitleIpcOptions = {}
// 防御纵深:即使 renderer 有 UI 守卫,main 侧也需从 DB 确认 session 真实存在且非远程
// (SSH / device-link),避免受信 renderer 绕过 UI 守卫携带远程会话内容触发付费调用。
// 同时拒绝 review session:reviewer 会话的 composer 被禁用(disabled),不可编辑也不可发送,
- // 对其做预测是浪费付费调用。
+ // 对其做预测是浪费付费调用。也拒绝 soft-deleted session:删除态会话的消息仍保留在 DB,
+ // 但已从用户会话列表移除,对其做预测会外发已删除转写并产生付费调用。
const [sessionRow] = await getDbClient()
- .drizzle.select({ remoteHostId: sessions.remoteHostId, source: sessions.source, agentKind: sessions.agentKind, workingDir: sessions.workingDir })
+ .drizzle.select({ remoteHostId: sessions.remoteHostId, source: sessions.source, agentKind: sessions.agentKind, workingDir: sessions.workingDir, status: sessions.status })
.from(sessions)
.where(eq(sessions.id, sessionId));
- if (!sessionRow || sessionRow.remoteHostId || sessionRow.source === 'review') {
+ if (!sessionRow || sessionRow.remoteHostId || sessionRow.source === 'review' || sessionRow.status === 'deleted') {
return { prompt: null };
}
// 防御纵深:校验 renderer 上报的 agentKind 与 DB 记录一致,避免受信 renderer 绕过