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(chat): preserve answered cards after stale dismissals

xda592b069c6b4
diff --git a/apps/desktop/src/renderer/__tests__/askUserDoneRace.test.ts b/apps/desktop/src/renderer/__tests__/askUserDoneRace.test.ts
index add1150227..11ba35bbea 100644
--- a/apps/desktop/src/renderer/__tests__/askUserDoneRace.test.ts
+++ b/apps/desktop/src/renderer/__tests__/askUserDoneRace.test.ts
@@ -456,6 +456,53 @@ describe('ask_user 与 done 的时序', () => {
expect(pendingAskStatuses()).toEqual(['expired']);
});
+ // #7144: the live IPC path must retain submitted answers after a stale close.
+ // Existing tests cover pending expiry, but not answered -> empty dismissal.
+ // Unit: two questions, one skipped, turn done before submitting the answer.
+ it.each(['resolved-push', 'accepted-receipt'] as const)(
+ 'keeps an answered cross-turn card after an empty dismissal (%s)',
+ async (completion) => {
+ makerChatStore.setSessionRuntime(SESSION_ID, { agentKind: 'codex' });
+ emitAskUserRequest('answered-card', [{ question: 'First?' }, { question: 'Second?' }]);
+ emitDone('codex');
+ const answers = { 'First?': 'Custom answer', 'Second?': '' };
+ makerChatStore.answerUserQuestion(SESSION_ID, 'answered-card', answers);
+ if (completion === 'resolved-push') {
+ onInteractionDismissed?.({
+ sessionId: SESSION_ID, requestId: 'answered-card', reason: 'resolved',
+ decision: { kind: 'ask_user_question', answers },
+ });
+ }
+ await vi.waitFor(() => expect(pendingAskStatuses()).toEqual(['answered']));
+ const answered = makerChatStore.getSnapshot(SESSION_ID).messages.find(
+ (m) => m.askUserRequestId === 'answered-card',
+ );
+
+ onInteractionDismissed?.({
+ sessionId: SESSION_ID, requestId: 'answered-card',
+ reason: 'server_request_resolved', resolvedAs: 'deny',
+ });
+
+ const after = makerChatStore.getSnapshot(SESSION_ID);
+ expect(after.pendingAskUser).toBeNull();
+ expect(after.messages.find((m) => m.askUserRequestId === 'answered-card')).toBe(answered);
+ expect(pendingAskStatuses()).toEqual(['answered']);
+ expect(answered?.askUserAnswers).toEqual(answers);
+ expect(answered?.askUserReply).toBe('First?: Custom answer\nSecond?: (skipped)');
+ expect(updateMessageContent).not.toHaveBeenCalled();
+
+ // A real winning decision remains authoritative even for answered rows.
+ const winningAnswers = { 'First?': 'Winning answer', 'Second?': '' };
+ onInteractionDismissed?.({
+ sessionId: SESSION_ID, requestId: 'answered-card', reason: 'resolved',
+ decision: { kind: 'ask_user_question', answers: winningAnswers },
+ });
+ expect(makerChatStore.getSnapshot(SESSION_ID).messages.find(
+ (m) => m.askUserRequestId === 'answered-card',
+ )).toMatchObject({ askUserStatus: 'answered', askUserAnswers: winningAnswers });
+ },
+ );
+
it('codex:答题只走 resolveInteraction,不本地落库', async () => {
makerChatStore.setSessionRuntime(SESSION_ID, { agentKind: 'codex' });
emitAskUserRequest('ask-4');
diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
index 0c949fa4ea..1dba1109fd 100644
--- a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
+++ b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
@@ -704,6 +704,15 @@ describe('device-link 远程交互 — dismissed / 顺序 / 本机零回归', ()
.messages.find((m) => m.askUserRequestId === 'ask-other');
expect(askMsg?.askUserStatus).toBe('answered'); // 与答题端一致,而非 expired
expect(askMsg?.askUserAnswers).toEqual({ 'X?': 'A' });
+
+ // #7144: replaying a close through the real remote-push subscription must
+ // not hide the already answered history row. Pending expiry is tested below.
+ host.hostDismiss(s, 'ask-other', 'server_request_resolved');
+ await flush();
+ expect(makerChatStore.getSnapshot(s).messages.find(
+ (m) => m.askUserRequestId === 'ask-other',
+ )).toBe(askMsg);
+ expect(askMsg?.askUserStatus).toBe('answered');
});
it('对端 dismiss 但无 decision(真·放弃 / 老被控端)→ ask 仍标 expired(兜底)', async () => {
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index fdeae40fb7..7623414089 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -6805,7 +6805,7 @@ export function handleStreamEvent(
state.messages.some((m) => m.role === 'ask_user' && m.askUserRequestId === data.requestId)
) {
// resolved + answers → 翻成 answered 并填答案(与答题端 answerUserQuestion 同款 reply / answers,
- // 卡片据此渲染 ✓ 选项);否则(真·放弃)标 expired。
+ // 卡片据此渲染 ✓ 选项);无答案关闭只将 pending 标 expired,保留已回答记录。
// 多窗口输家可能已经乐观写成 answered;仍要用赢家决策覆盖,不能只认 pending。
const answers = resolved?.answers as Record<string, string> | undefined;
const dismissed = resolved?.dismissed === true;
@@ -6829,7 +6829,9 @@ export function handleStreamEvent(
askUserReply,
askUserAnswers: answers,
}
- : { ...m, askUserStatus: 'expired' as const }
+ : m.askUserStatus === 'pending'
+ ? { ...m, askUserStatus: 'expired' as const }
+ : m
: m,
),
};