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): 中断任务弹窗提交前复核、按账号隔离并统一日韩术语

Dash8c6687e10441
diff --git a/apps/desktop/src/renderer/features/cc-agent/InterruptedTasksResumeDialog.tsx b/apps/desktop/src/renderer/features/cc-agent/InterruptedTasksResumeDialog.tsx
index 6efe8faf76..f07794b453 100644
--- a/apps/desktop/src/renderer/features/cc-agent/InterruptedTasksResumeDialog.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/InterruptedTasksResumeDialog.tsx
@@ -17,6 +17,7 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useAuth } from '@/contexts/AuthContext';
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
import { VendorIcon, agentKindToVendor } from '@/components/sidebar/VendorIcon';
import type { Session } from '@/lib/ccAgent.types';
@@ -35,9 +36,12 @@ const log = createLogger('interrupted-tasks-resume');
/** localDb 登录后才 ready,首拉沿用 usePendingAlertAttention 的线性退避。 */
const MAX_LOAD_ATTEMPTS = 5;
-/** 窗口级单例:布局重挂载不重复查询;弹窗关过一次后本窗口不再弹。 */
-let _loadPromise: Promise<InterruptedTask[]> | null = null;
-let _handledThisWindow = false;
+/**
+ * 窗口级单例:布局重挂载不重复查询;弹窗关过一次后本窗口不再弹。
+ * 都按数据所有者(账号)隔离:同一窗口换账号登录时,旧账号的任务列表与「已处理」标记不得带入。
+ */
+let _load: { ownerId: string | null; promise: Promise<InterruptedTask[]> } | null = null;
+let _handledOwnerId: string | null | undefined;
interface InterruptedTask {
session: Session;
@@ -45,6 +49,11 @@ interface InterruptedTask {
activity: string | null;
}
+async function listStillInterruptedIds(): Promise<Set<string>> {
+ const candidates = await window.electronAPI.localDb.sessions.interruptedResumeCandidates();
+ return new Set(candidates.map((c) => c.sessionId));
+}
+
async function loadInterruptedTasks(): Promise<InterruptedTask[]> {
const sessionsApi = window.electronAPI.localDb.sessions;
const candidates = await sessionsApi.interruptedResumeCandidates();
@@ -106,15 +115,18 @@ function TaskCheckbox({
export function InterruptedTasksResumeDialog({ suspended = false }: { suspended?: boolean }) {
const { t } = useTranslation();
+ const { dataOwnerId } = useAuth();
const [tasks, setTasks] = useState<InterruptedTask[]>([]);
const [deselected, setDeselected] = useState<ReadonlySet<string>>(() => new Set());
const [open, setOpen] = useState(false);
useEffect(() => {
let active = true;
- _loadPromise ??= loadInterruptedTasksWithRetry();
- void _loadPromise.then((loaded) => {
- if (!active || _handledThisWindow || loaded.length === 0) return;
+ if (_load?.ownerId !== dataOwnerId) {
+ _load = { ownerId: dataOwnerId, promise: loadInterruptedTasksWithRetry() };
+ }
+ void _load.promise.then((loaded) => {
+ if (!active || _handledOwnerId === dataOwnerId || loaded.length === 0) return;
log.info(`found ${loaded.length} interrupted task(s) to offer for resume`);
setTasks(loaded);
setOpen(true);
@@ -122,10 +134,10 @@ export function InterruptedTasksResumeDialog({ suspended = false }: { suspended?
return () => {
active = false;
};
- }, []);
+ }, [dataOwnerId]);
const handleOpenChange = (next: boolean) => {
- if (!next) _handledThisWindow = true;
+ if (!next) _handledOwnerId = dataOwnerId;
setOpen(next);
};
@@ -157,15 +169,24 @@ export function InterruptedTasksResumeDialog({ suspended = false }: { suspended?
};
const handleContinue = () => {
- const ids = selectedIds;
- void Promise.allSettled(
- ids.map((id) => makerChatStore.sendUiTrigger(id, CONTINUE_AFTER_APP_EXIT_PROMPT)),
- ).then((results) => {
+ const picked = selectedIds;
+ void (async () => {
+ // 弹窗可能在更新说明后才出现,期间任务可能已被其它窗口/横幅继续:提交前重新取
+ // 仍处于中断态的集合再取交集,避免对已恢复的任务重复续跑。
+ const stillInterrupted = await listStillInterruptedIds().catch(() => null);
+ if (!stillInterrupted) {
+ toast.error(t('chat.interruptedResumeDialog.continueFailed', { count: picked.length }));
+ return;
+ }
+ const ids = picked.filter((id) => stillInterrupted.has(id));
+ const results = await Promise.allSettled(
+ ids.map((id) => makerChatStore.sendUiTrigger(id, CONTINUE_AFTER_APP_EXIT_PROMPT)),
+ );
const failed = results.filter((r) => r.status === 'rejected');
if (failed.length === 0) return;
log.warn(`failed to continue ${failed.length}/${ids.length} interrupted task(s)`);
toast.error(t('chat.interruptedResumeDialog.continueFailed', { count: failed.length }));
- });
+ })();
};
if (total === 0) return null;
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx
index 6e40ba477b..3463be3fc2 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx
@@ -1,9 +1,11 @@
// @vitest-environment jsdom
/**
- * 启动「继续上次中断的任务」弹窗:只对仍勾选的任务发续跑指令。
+ * 启动「继续上次中断的任务」弹窗:只对仍勾选、且提交时仍处于中断态的任务发续跑指令。
*
* 依据:产品决策(2026-10-19)默认全选、可去掉不想继续的;没勾选的任务不得被续跑,
* 它们的中断横幅留给用户之后单独处理。续跑复用横幅的 CONTINUE_AFTER_APP_EXIT_PROMPT。
+ * 弹窗打开期间任务可能已被其它窗口继续(PR #6390 review),提交前必须重新取中断集合,
+ * 否则会对已恢复的任务重复续跑一轮。
*/
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
@@ -16,6 +18,7 @@ const sendUiTrigger = vi.hoisted(() => vi.fn(async () => {}));
vi.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
+vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => ({ dataOwnerId: 'owner-1' }) }));
vi.mock('@/lib/scrollbarAutoHide', () => ({ flashScrollbar: () => {} }));
vi.mock('@/lib/makerChatStore', () => ({ makerChatStore: { sendUiTrigger } }));
vi.mock('@/lib/toast', () => ({ toast: { error: vi.fn() } }));
@@ -23,7 +26,7 @@ vi.mock('@/lib/toast', () => ({ toast: { error: vi.fn() } }));
afterEach(cleanup);
describe('InterruptedTasksResumeDialog', () => {
- it('continues only the tasks that stay checked', async () => {
+ it('continues only checked tasks that are still interrupted at submit time', async () => {
const now = Date.now();
const session = (id: string, title: string) => ({
id,
@@ -34,15 +37,28 @@ describe('InterruptedTasksResumeDialog', () => {
workspaceKind: 'project',
createdAt: new Date(now).toISOString(),
});
+ const listCandidates = vi
+ .fn()
+ .mockResolvedValueOnce([
+ { sessionId: 's-a', interruptedAt: now - 120_000, activity: '运行测试' },
+ { sessionId: 's-b', interruptedAt: now - 60_000, activity: null },
+ { sessionId: 's-c', interruptedAt: now - 30_000, activity: null },
+ ])
+ // 提交时 s-c 已在别处被继续,不再中断。
+ .mockResolvedValueOnce([
+ { sessionId: 's-a', interruptedAt: now - 120_000, activity: '运行测试' },
+ { sessionId: 's-b', interruptedAt: now - 60_000, activity: null },
+ ]);
Object.assign(window, {
electronAPI: {
localDb: {
sessions: {
- interruptedResumeCandidates: async () => [
- { sessionId: 's-a', interruptedAt: now - 120_000, activity: '运行测试' },
- { sessionId: 's-b', interruptedAt: now - 60_000, activity: null },
+ interruptedResumeCandidates: listCandidates,
+ getMany: async () => [
+ session('s-a', '任务 A'),
+ session('s-b', '任务 B'),
+ session('s-c', '任务 C'),
],
- getMany: async () => [session('s-a', '任务 A'), session('s-b', '任务 B')],
},
},
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index ed308cbc62..a165e49adb 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -11178,9 +11178,9 @@
"dismissTitle": "この中断通知を閉じる"
},
"interruptedResumeDialog": {
- "title": "中断したタスクを再開",
- "description_one": "{{appName}} が前回予期せず終了し、{{count}} 件のタスクが完了していません。選択したタスクは会話履歴から進捗を確認し、中断したところから再開します。",
- "description_other": "{{appName}} が前回予期せず終了し、{{count}} 件のタスクが完了していません。選択したタスクは会話履歴から進捗を確認し、中断したところから再開します。",
+ "title": "中断したセッションを再開",
+ "description_one": "{{appName}} が前回予期せず終了し、{{count}} 件のセッションが完了していません。選択したセッションは会話履歴から進捗を確認し、中断したところから再開します。",
+ "description_other": "{{appName}} が前回予期せず終了し、{{count}} 件のセッションが完了していません。選択したセッションは会話履歴から進捗を確認し、中断したところから再開します。",
"selectAll": "すべて選択",
"selectedCount": "{{selected}} / {{total}} 件を選択",
"interruptedAgo": "{{time}}前に中断",
@@ -11189,8 +11189,8 @@
"continueSelected_other": "{{count}} 件を再開",
"continueNone": "再開",
"later": "後で",
- "continueFailed_one": "{{count}} 件のタスクを再開できませんでした。タスクを開いて再試行してください。",
- "continueFailed_other": "{{count}} 件のタスクを再開できませんでした。タスクを開いて再試行してください。"
+ "continueFailed_one": "{{count}} 件のセッションを再開できませんでした。セッションを開いて再試行してください。",
+ "continueFailed_other": "{{count}} 件のセッションを再開できませんでした。セッションを開いて再試行してください。"
},
"unreadFailedScheduleBanner": {
"text": "自動実行に失敗した記録があります。",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 9e13229dbc..f492d93f2a 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -11178,19 +11178,19 @@
"dismissTitle": "이 중단 알림 닫기"
},
"interruptedResumeDialog": {
- "title": "중단된 작업 이어서 하기",
- "description_one": "{{appName}}이(가) 지난번에 예기치 않게 종료되어 작업 {{count}}개가 끝나지 않았습니다. 선택한 작업은 대화 기록으로 진행 상황을 확인하고 중단된 곳부터 이어서 진행합니다.",
- "description_other": "{{appName}}이(가) 지난번에 예기치 않게 종료되어 작업 {{count}}개가 끝나지 않았습니다. 선택한 작업은 대화 기록으로 진행 상황을 확인하고 중단된 곳부터 이어서 진행합니다.",
+ "title": "중단된 세션 이어서 하기",
+ "description_one": "{{appName}}이(가) 지난번에 예기치 않게 종료되어 세션 {{count}}개가 끝나지 않았습니다. 선택한 세션은 대화 기록으로 진행 상황을 확인하고 중단된 곳부터 이어서 진행합니다.",
+ "description_other": "{{appName}}이(가) 지난번에 예기치 않게 종료되어 세션 {{count}}개가 끝나지 않았습니다. 선택한 세션은 대화 기록으로 진행 상황을 확인하고 중단된 곳부터 이어서 진행합니다.",
"selectAll": "모두 선택",
"selectedCount": "{{total}}개 중 {{selected}}개 선택",
"interruptedAgo": "{{time}} 전 중단",
"interruptedJustNow": "방금 중단",
- "continueSelected_one": "작업 {{count}}개 이어서 하기",
- "continueSelected_other": "작업 {{count}}개 이어서 하기",
+ "continueSelected_one": "세션 {{count}}개 이어서 하기",
+ "continueSelected_other": "세션 {{count}}개 이어서 하기",
"continueNone": "이어서 하기",
"later": "나중에",
- "continueFailed_one": "작업 {{count}}개를 이어서 진행하지 못했습니다. 작업을 열어 다시 시도하세요.",
- "continueFailed_other": "작업 {{count}}개를 이어서 진행하지 못했습니다. 작업을 열어 다시 시도하세요."
+ "continueFailed_one": "세션 {{count}}개를 이어서 진행하지 못했습니다. 세션을 열어 다시 시도하세요.",
+ "continueFailed_other": "세션 {{count}}개를 이어서 진행하지 못했습니다. 세션을 열어 다시 시도하세요."
},
"unreadFailedScheduleBanner": {
"text": "실패한 자동 실행이 있습니다.",