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): skip reminders for inactive handoff steps

guyongbe7804352752
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
index 22ce90cc9c..3330716dec 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
@@ -451,26 +451,36 @@ describe('getRunningSnapshot pending request identity', () => {
it('publishes a new handoff step without a pending-state transition', () => {
// #3259: the same request stays pending through multiple owner-input steps.
const sessionId = 'pending-handoff-step';
- const handoff = (stepNumber: number, revision: number): void => {
+ const handoff = (stepNumber: number, revision: number, phase: 'ready' | 'finishing' = 'ready'): void => {
makerChatStore.__applyInputHandoffRequestForTest(sessionId, {
kind: 'input_handoff', requestId: 'same-request', revision,
- phase: 'ready', purpose: 'Sign in', source: { app: 'Test' },
- stepNumber, controls: [],
+ phase, purpose: 'Sign in', source: { app: 'Test' },
+ stepNumber, controls: phase === 'ready'
+ ? [{ id: 'email', kind: 'text', label: 'Email', contentType: 'email' }]
+ : [],
});
};
try {
handoff(1, 1);
const first = makerChatStore.getRunningSnapshot();
expect(first.get(sessionId)?.pendingRequestKeys).toEqual(['handoff:same-request:1']);
+ expect(first.get(sessionId)?.hasActionableInputHandoff).toBe(true);
handoff(1, 2);
expect(makerChatStore.getRunningSnapshot()).toBe(first);
- handoff(2, 3);
+ handoff(2, 3, 'finishing');
const second = makerChatStore.getRunningSnapshot();
expect(second).not.toBe(first);
expect(second.get(sessionId)?.hasPendingInputHandoff).toBe(true);
+ expect(second.get(sessionId)?.hasActionableInputHandoff).toBe(false);
expect(second.get(sessionId)?.pendingRequestKeys).toEqual(['handoff:same-request:2']);
+
+ handoff(2, 4);
+ const third = makerChatStore.getRunningSnapshot();
+ expect(third).not.toBe(second);
+ expect(third.get(sessionId)?.hasActionableInputHandoff).toBe(true);
+ expect(third.get(sessionId)?.pendingRequestKeys).toEqual(['handoff:same-request:2']);
} finally {
makerChatStore.purgeSession(sessionId);
}
diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
index 0068930b07..50c9862dd6 100644
--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
@@ -667,8 +667,8 @@ describe('useSessionRunningStatus silenced completion handling', () => {
setDataOwnerGeneration('handoff-owner');
const onSessionNeedsReply = vi.fn();
const first = renderHook(() => useSessionRunningStatus(undefined, { onSessionNeedsReply }));
- const handoffStatus = (step: number): SessionStatusInfo => ({
- ...status(false), hasPendingInputHandoff: true,
+ const handoffStatus = (step: number, actionable = true): SessionStatusInfo => ({
+ ...status(false), hasPendingInputHandoff: true, hasActionableInputHandoff: actionable,
pendingRequestKeys: [`handoff:same-request:${step}`],
});
@@ -682,6 +682,15 @@ describe('useSessionRunningStatus silenced completion handling', () => {
expect(onSessionNeedsReply).toHaveBeenCalledTimes(1);
expect(addSessionAttention).not.toHaveBeenCalledWith('s-handoff', 'awaiting');
+ await emitSnapshot(new Map([['s-handoff', handoffStatus(1, false)]]));
+ await emitSnapshot(new Map([['s-handoff', handoffStatus(1)]]));
+ expect(onSessionNeedsReply).toHaveBeenCalledTimes(1);
+
+ // The Host advances stepNumber before publishing a non-actionable finishing card.
+ await emitSnapshot(new Map([['s-handoff', handoffStatus(2, false)]]));
+ expect(onSessionNeedsReply).toHaveBeenCalledTimes(1);
+ expect(addSessionAttention).not.toHaveBeenCalledWith('s-handoff', 'awaiting');
+
await emitSnapshot(new Map([['s-handoff', handoffStatus(2)]]));
expect(onSessionNeedsReply).toHaveBeenCalledTimes(2);
expect(addSessionAttention).toHaveBeenCalledWith('s-handoff', 'awaiting');
diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
index fb9518a9a7..8cdd06d0f3 100644
--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
@@ -363,11 +363,13 @@ export function useSessionRunningStatus(
info.hasPendingPermission ||
info.hasPendingPlanReview ||
info.hasPendingPluginSetup ||
- info.hasPendingInputHandoff === true
+ info.hasActionableInputHandoff === true
) {
currentPendingSet.add(id);
const isActive = id === activeSessionId;
- const keys = info.pendingRequestKeys;
+ const keys = info.hasActionableInputHandoff
+ ? info.pendingRequestKeys
+ : info.pendingRequestKeys?.filter((key) => !key.startsWith('handoff:'));
const wasAlreadyPending = keys?.length
? !keys.some((key) =>
!notifiedPendingRequests.get(id)?.has(key)
@@ -385,7 +387,9 @@ export function useSessionRunningStatus(
// Other hook consumers only read running status. They may add the
// in-app dot, but must not consume the system notification owner's edge.
if (keys?.length && onSessionNeedsReplyRef.current) {
- notifiedPendingRequests.set(id, new Set(keys));
+ const seen = notifiedPendingRequests.get(id) ?? new Set<string>();
+ for (const key of keys) seen.add(key);
+ notifiedPendingRequests.set(id, seen);
}
}
}
@@ -394,12 +398,9 @@ export function useSessionRunningStatus(
// Sidebar was unmounted is removed on the next snapshot.
for (const [id, seen] of notifiedPendingRequests) {
const current = currentPendingKeys.get(id);
- if (!current) {
- notifiedPendingRequests.delete(id);
- continue;
- }
+ const stillPending = statusMap.get(id)?.pendingRequestKeys;
for (const key of seen) {
- if (!current.has(key)) seen.delete(key);
+ if (!current?.has(key) && !stillPending?.includes(key)) seen.delete(key);
}
if (seen.size === 0) notifiedPendingRequests.delete(id);
}
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 4efa00ed4c..bd4e56de07 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -162,7 +162,7 @@ import {
requestRemoteReseed,
} from '@/features/device-link/remoteProjectsStore';
import { getStickySessionDeviceId } from '@/features/device-link/stickySessionOrigin';
-import { isInputHandoffAwaitingOwner, parsePendingInputHandoff } from '@/features/input-handoff/inputHandoffModel';
+import { inputHandoffDialogHasContent, isInputHandoffAwaitingOwner, parsePendingInputHandoff } from '@/features/input-handoff/inputHandoffModel';
import { clearCachedMessages, readCachedMessages, persistListMessage, sessionCacheInvalidationToken } from '@/features/device-link/mirrorCacheClient';
import {
noteRemoteSessionSyncCompleted,
@@ -10121,8 +10121,10 @@ export interface SessionStatusInfo {
hasPendingPermission: boolean;
hasPendingPlanReview: boolean;
hasPendingPluginSetup: boolean;
- /** 代输入: owner input requested for an on-screen step (survives the turn). */
+ /** A nonterminal input-handoff card exists, including reading/working/finishing phases. */
hasPendingInputHandoff?: boolean;
+ /** The current handoff step actually needs an owner action and may trigger a reminder. */
+ hasActionableInputHandoff?: boolean;
/** Stable identities for pending interactions; changes even when pending booleans stay true. */
pendingRequestKeys?: readonly string[];
}
@@ -10222,6 +10224,8 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
state.pendingPluginSetupQueue,
);
const hasPendingInputHandoff = isInputHandoffAwaitingOwner(state.pendingInputHandoff);
+ const hasActionableInputHandoff = !!state.pendingInputHandoff &&
+ inputHandoffDialogHasContent(state.pendingInputHandoff, false);
const requestKeys = pendingRequestKeys(state);
// 后台 subagent 折算:主 turn 已结束但 wake 型后台任务(local_agent /
@@ -10245,6 +10249,7 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
hasPendingPlanReview,
hasPendingPluginSetup,
hasPendingInputHandoff,
+ hasActionableInputHandoff,
pendingRequestKeys: requestKeys,
});
} else if (
@@ -10264,6 +10269,7 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
hasPendingPlanReview,
hasPendingPluginSetup,
hasPendingInputHandoff,
+ hasActionableInputHandoff,
pendingRequestKeys: requestKeys,
});
}
@@ -10289,6 +10295,8 @@ function computeRunningSnapshot(): Map<string, SessionStatusInfo> {
state.pendingPluginSetupQueue,
),
hasPendingInputHandoff: isInputHandoffAwaitingOwner(state.pendingInputHandoff),
+ hasActionableInputHandoff: !!state.pendingInputHandoff &&
+ inputHandoffDialogHasContent(state.pendingInputHandoff, false),
pendingRequestKeys: pendingRequestKeys(state),
});
}
@@ -10329,6 +10337,7 @@ function getRunningSnapshot(): ReadonlyMap<string, SessionStatusInfo> {
prev.hasPendingPlanReview !== info.hasPendingPlanReview ||
prev.hasPendingPluginSetup !== info.hasPendingPluginSetup ||
!!prev.hasPendingInputHandoff !== !!info.hasPendingInputHandoff ||
+ !!prev.hasActionableInputHandoff !== !!info.hasActionableInputHandoff ||
!samePendingRequestKeys(prev.pendingRequestKeys, info.pendingRequestKeys)
) {
same = false;