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(update): 确认卡同时提示会被重启中断的后台工作

Dash5ce511b99429
diff --git a/apps/desktop/src/main/__tests__/relaunchBusyActivityIpcBoundary.test.ts b/apps/desktop/src/main/__tests__/relaunchBusyActivityIpcBoundary.test.ts
index e4875f6a2c..ab25894749 100644
--- a/apps/desktop/src/main/__tests__/relaunchBusyActivityIpcBoundary.test.ts
+++ b/apps/desktop/src/main/__tests__/relaunchBusyActivityIpcBoundary.test.ts
@@ -51,6 +51,7 @@ vi.mock('../security/trustedAppRenderer', () => ({
import {
RELAUNCH_BLOCKING_ACTIVITY_CHANNEL,
+ readRelaunchBackgroundActivity,
registerRelaunchBusyActivityIpc,
} from '../relaunchBusyActivityIpc.js';
@@ -134,3 +135,26 @@ describe('registerRelaunchBusyActivityIpc', () => {
expect(h.reads).toBe(0);
});
});
+
+describe('readRelaunchBackgroundActivity', () => {
+ it('ignores model turns but still reads every background source, scheduler included', async () => {
+ let schedulerRead = false;
+ registerRelaunchBusyActivityIpc(() => ({
+ ...countingSources(true)(),
+ anySchedulerRunRunning: async () => { schedulerRead = true; return false; },
+ }));
+ await expect(readRelaunchBackgroundActivity()).resolves.toMatchObject({ busy: false });
+ expect(schedulerRead).toBe(true);
+ });
+
+ it('reports background work a restart would stop', async () => {
+ registerRelaunchBusyActivityIpc(() => ({
+ ...countingSources(false)(),
+ anyBackgroundBashRunning: () => true,
+ }));
+ await expect(readRelaunchBackgroundActivity()).resolves.toMatchObject({
+ busy: true,
+ reasons: ['background-bash'],
+ });
+ });
+});
diff --git a/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts b/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts
index f095a6c673..bb51759292 100644
--- a/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts
+++ b/apps/desktop/src/main/agent-app-update/__tests__/agentAppUpdateService.test.ts
@@ -44,6 +44,7 @@ function setup(overrides: Partial<AgentAppUpdateDeps> = {}) {
}),
resolveCaller: vi.fn(() => 'owner' as const),
countOtherRunningTasks: vi.fn(() => 2),
+ hasBackgroundWork: vi.fn(async () => false),
requestHostPermission: vi.fn(async () => allow()),
waitForCallerTurnToEnd: vi.fn(async () => undefined),
captureOwner: vi.fn(() => activeOwner),
@@ -482,6 +483,28 @@ describe('Agent app update install', () => {
expect(card.description).toContain('update.agentInstall.noOtherTasks');
expect(card.description).toContain('update.agentInstall.linuxAuth');
});
+
+ it('warns about background work instead of claiming nothing else is running', async () => {
+ const { deps, service } = setup({
+ countOtherRunningTasks: vi.fn(() => 0),
+ hasBackgroundWork: vi.fn(async () => true),
+ });
+ await service.install(caller);
+ const card = vi.mocked(deps.requestHostPermission).mock.calls[0]![2];
+ expect(card.description).toContain('update.agentInstall.backgroundWork');
+ expect(card.description).not.toContain('update.agentInstall.noOtherTasks');
+ });
+
+ it('treats an unreadable background probe as background work', async () => {
+ const { deps, service } = setup({
+ countOtherRunningTasks: vi.fn(() => 0),
+ hasBackgroundWork: vi.fn(async () => { throw new Error('probe failed'); }),
+ });
+ await service.install(caller);
+ const card = vi.mocked(deps.requestHostPermission).mock.calls[0]![2];
+ expect(card.description).toContain('update.agentInstall.backgroundWork');
+ expect(card.description).not.toContain('update.agentInstall.noOtherTasks');
+ });
});
describe('Agent app update result after restart', () => {
diff --git a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts
index 45009ca034..8ab69945e3 100644
--- a/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts
+++ b/apps/desktop/src/main/agent-app-update/agentAppUpdateService.ts
@@ -99,6 +99,8 @@ export interface AgentAppUpdateDeps {
/** 'owner' only for a live local turn the account owner started (see callerAuthority.ts). */
resolveCaller(caller: AgentAppUpdateCaller): 'owner' | 'not-owner' | 'unavailable';
countOtherRunningTasks(callerSessionId: string): number;
+ /** Background work a restart would also stop (see relaunchBusyActivity.ts); unknown is true. */
+ hasBackgroundWork(): Promise<boolean>;
/** Host permission card on the calling task; null when that task is gone. */
requestHostPermission(
sessionId: string,
@@ -212,17 +214,18 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {
};
};
- const buildInstallCard = (
+ const buildInstallCard = async (
caller: AgentAppUpdateCaller,
from: string,
to: string,
- ): PermissionRequest => {
+ ): Promise<PermissionRequest> => {
const others = deps.countOtherRunningTasks(caller.sessionId);
+ const background = await deps.hasBackgroundWork().catch(() => true);
const lines = [
text('update.agentInstall.versions', { from, to }),
- others > 0
- ? text('update.agentInstall.otherTasks', { count: others })
- : text('update.agentInstall.noOtherTasks'),
+ ...(others > 0 ? [text('update.agentInstall.otherTasks', { count: others })] : []),
+ ...(background ? [text('update.agentInstall.backgroundWork')] : []),
+ ...(others === 0 && !background ? [text('update.agentInstall.noOtherTasks')] : []),
text('update.agentInstall.thisTask'),
text('update.agentInstall.remote'),
...(deps.platform === 'linux' ? [text('update.agentInstall.linuxAuth')] : []),
@@ -431,7 +434,7 @@ export function createAgentAppUpdateService(deps: AgentAppUpdateDeps) {
const from = check.currentVersion;
const to = check.targetVersion;
flow.targetVersion = to;
- const outcome = await decide(caller, buildInstallCard(caller, from, to));
+ const outcome = await decide(caller, await buildInstallCard(caller, from, to));
if (outcome !== 'allow') return declined(outcome);
// The user may have stopped or replaced the task while the card was open.
const current = deps.resolveCaller(caller);
diff --git a/apps/desktop/src/main/agent-app-update/index.ts b/apps/desktop/src/main/agent-app-update/index.ts
index 5417fcd508..bf366c73ba 100644
--- a/apps/desktop/src/main/agent-app-update/index.ts
+++ b/apps/desktop/src/main/agent-app-update/index.ts
@@ -24,6 +24,7 @@ import { sessions } from '../localDb/schema.js';
import { t } from '../i18n.js';
import { createMessage } from '../localDb/ipc/messages.js';
import { createLogger } from '../logger.js';
+import { readRelaunchBackgroundActivity } from '../relaunchBusyActivityIpc.js';
import {
applyConfirmedAppUpdateForAgent,
checkAppUpdateForAgent,
@@ -103,6 +104,7 @@ function getService(): AgentAppUpdateService {
writeAutoUpdate: setAutoRelaunchOnIdleForAgent,
resolveCaller: (caller) => sessionHost?.resolveCaller(caller) ?? 'unavailable',
countOtherRunningTasks: (sessionId) => requireSessionHost().countOtherRunningTasks(sessionId),
+ hasBackgroundWork: async () => (await readRelaunchBackgroundActivity()).busy,
requestHostPermission: (...args) => requireSessionHost().requestHostPermission(...args),
waitForCallerTurnToEnd: (caller) => requireSessionHost().waitForCallerTurnToEnd(caller),
captureOwner,
diff --git a/apps/desktop/src/main/relaunchBusyActivityIpc.ts b/apps/desktop/src/main/relaunchBusyActivityIpc.ts
index e98aa0b5b1..c69c37f753 100644
--- a/apps/desktop/src/main/relaunchBusyActivityIpc.ts
+++ b/apps/desktop/src/main/relaunchBusyActivityIpc.ts
@@ -29,6 +29,16 @@ export async function readRelaunchBlockingActivity() {
: { busy: true, reasons: ['not-ready'] };
}
+/**
+ * Restart-sensitive work other than model turns (background Bash, Claude/Ghost background
+ * activity, Cindy slot jobs, PI Subagents, scheduler runs). Unknown counts as busy.
+ */
+export async function readRelaunchBackgroundActivity() {
+ return currentSources
+ ? evaluateRelaunchBusyActivity({ ...currentSources(), anySessionInTurn: () => false })
+ : { busy: true, reasons: ['not-ready'] };
+}
+
/**
* 横幅延后轮询会反复问同一条探针,但不能把每次 busy 都打成「manual relaunch」INFO。
* Renderer 传入的 payload 不可信:只有精确 `{ silent: true }` 才静默,其余一律按手动查询打日志。
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index d46b0b0eca..d9e659509a 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -8049,6 +8049,7 @@
"title": "Update {{appName}} to {{version}}?",
"versions": "Update from {{from}} to {{to}}. After you confirm, {{appName}} downloads and installs it with the built-in updater, then restarts.",
"otherTasks": "{{count}} other task(s) are running and will be interrupted by the restart. Afterwards, click Continue in each task to resume.",
+ "backgroundWork": "Background work is also in progress (such as background commands, media generation, Subagents or automation runs) and will be interrupted by the restart.",
"noOtherTasks": "No other tasks are running.",
"thisTask": "This task restarts with {{appName}} after the current reply finishes.",
"remote": "Phones and other remote connections disconnect briefly during the restart. Reconnect to see the result in this task.",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 1bdb28c733..214ddc732a 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -8041,6 +8041,7 @@
"title": "{{appName}} を {{version}} に更新しますか?",
"versions": "{{from}} から {{to}} に更新します。確認後、{{appName}} は内蔵アップデーターでダウンロードとインストールを行い、自動的に再起動します。",
"otherTasks": "ほかに {{count}} 件のタスクが実行中で、再起動により中断されます。再起動後、各タスクで「続行」を押すと再開できます。",
+ "backgroundWork": "バックグラウンドの作業(バックグラウンドコマンド、メディア生成、サブエージェント、自動化の実行など)も進行中で、再起動すると中断されます。",
"noOtherTasks": "ほかに実行中のタスクはありません。",
"thisTask": "このタスクは現在の返信が終わった後、{{appName}} とともに再起動します。",
"remote": "再起動中はスマートフォンなどのリモート接続が一時的に切断されます。再接続後、このタスクで結果を確認できます。",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 6df0647770..b58c9e4cdf 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -8041,6 +8041,7 @@
"title": "{{appName}}을(를) {{version}}(으)로 업데이트할까요?",
"versions": "{{from}}에서 {{to}}(으)로 업데이트합니다. 확인하면 {{appName}}이(가) 내장 업데이터로 다운로드·설치한 뒤 자동으로 다시 시작합니다.",
"otherTasks": "다른 작업 {{count}}개가 실행 중이며 다시 시작하면 중단됩니다. 다시 시작한 뒤 각 작업에서 \"계속\"을 눌러 재개할 수 있습니다.",
+ "backgroundWork": "백그라운드 작업(백그라운드 명령, 미디어 생성, 하위 에이전트, 자동화 실행 등)도 진행 중이며 재시작하면 중단됩니다.",
"noOtherTasks": "실행 중인 다른 작업이 없습니다.",
"thisTask": "이 작업은 현재 답변이 끝난 뒤 {{appName}}과(와) 함께 다시 시작됩니다.",
"remote": "다시 시작하는 동안 휴대폰 등 원격 연결이 잠시 끊깁니다. 다시 연결되면 이 작업에서 결과를 확인할 수 있습니다.",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 90767f2773..0bb3f672de 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -8041,6 +8041,7 @@
"title": "更新 {{appName}} 到 {{version}}?",
"versions": "从 {{from}} 更新到 {{to}}。确认后 {{appName}} 会用内置更新器下载并安装,然后自动重启。",
"otherTasks": "另有 {{count}} 个任务正在运行,重启会中断它们;重启后可在对应任务中点「继续」恢复。",
+ "backgroundWork": "还有后台工作正在进行(如后台命令、媒体生成、Subagent 或自动化运行),重启也会中断它们。",
"noOtherTasks": "目前没有其他正在运行的任务。",
"thisTask": "本任务会在这轮回复结束后随 {{appName}} 重启。",
"remote": "重启期间手机等远程连接会暂时断开,重连后可在本任务中查看更新结果。",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index a876c8efa2..b2f984a78f 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -8041,6 +8041,7 @@
"title": "將 {{appName}} 更新到 {{version}}?",
"versions": "從 {{from}} 更新到 {{to}}。確認後 {{appName}} 會用內建更新器下載並安裝,然後自動重新啟動。",
"otherTasks": "另有 {{count}} 個任務正在執行,重新啟動會中斷它們;重新啟動後可在對應任務中點「繼續」恢復。",
+ "backgroundWork": "還有背景工作正在進行(如背景命令、媒體生成、Subagent 或自動化執行),重新啟動也會中斷它們。",
"noOtherTasks": "目前沒有其他正在執行的任務。",
"thisTask": "本任務會在這輪回覆結束後隨 {{appName}} 重新啟動。",
"remote": "重新啟動期間手機等遠端連線會暫時中斷,重新連線後可在本任務中查看更新結果。",
diff --git a/docs/product-rules/agent-app-update.md b/docs/product-rules/agent-app-update.md
index 943ad3cb73..8c4c03ca09 100644
--- a/docs/product-rules/agent-app-update.md
+++ b/docs/product-rules/agent-app-update.md
@@ -13,7 +13,8 @@ Agent 只能反复引导用户去点「检查更新」;那次收紧的起因
- 确认卡复用通用 `permission` 交互(`cindy.app.update` / `cindy.app.auto_update`),桌面、
同账号手机远控与 IM 渠道卡共用 interaction router 的同一决定,旧版手机无需升级。
安装卡写明从哪个版本到哪个版本、Cindy 会重启、另有几个任务正在运行会被中断(重启后在任务里点
- 「继续」恢复)、本任务在这轮回复后重启、远程连接会短暂断开;Linux 另提示需要输入系统密码。
+ 「继续」恢复)、是否还有后台工作(后台命令、媒体生成、Subagent、自动化运行等,口径同
+ `relaunchBusyActivity.ts`,读不出按有)会被中断、本任务在这轮回复后重启、远程连接会短暂断开;Linux 另提示需要输入系统密码。
- 确认后走「设置 → 关于」同一条更新状态机:`checkForUpdate()` 下载(单飞,重复调用不重复下载),
等调用任务这轮回复结束(最多 2 分钟)后 `executeRelaunch()` 重启;Windows / Linux 会等更新器真正启动
(5 秒内成功即退出、失败即写回原因)再收尾。确认卡总是写明具体目标版本(后台正在下载时用实际下载的版本;读不到就不弹卡),安装只认卡片上确认的版本: