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): check agent binaries after automatic update relaunch (#4950)

Lizie54ba5cd699c
diff --git a/apps/desktop/src/main/__tests__/piSubagentUpdateRelaunchGate.test.ts b/apps/desktop/src/main/__tests__/piSubagentUpdateRelaunchGate.test.ts
index dac4eecc43..b2a0fa12a5 100644
--- a/apps/desktop/src/main/__tests__/piSubagentUpdateRelaunchGate.test.ts
+++ b/apps/desktop/src/main/__tests__/piSubagentUpdateRelaunchGate.test.ts
@@ -142,7 +142,7 @@ describe('PI Subagent reclaim before an update relaunch', () => {
source.indexOf('async function executeRelaunch('),
source.indexOf('async function executeRelaunchUnguarded('),
);
- expect(wrapper).toMatch(/try \{\s*await executeRelaunchUnguarded\(theme, checkForBinaryUpdates\);\s*\} catch/);
+ expect(wrapper).toMatch(/try \{\s*await executeRelaunchUnguarded\(theme\);\s*\} catch/);
expect(wrapper).toContain("handleApplyFailure('relaunch_failed')");
// The gate and everything after it live in the guarded body.
const guarded = source.slice(source.indexOf('async function executeRelaunchUnguarded('));
@@ -154,7 +154,7 @@ describe('PI Subagent reclaim before an update relaunch', () => {
// `executeRelaunch` is now async; a forgotten `void` would silently drop
// the gate's rejection handling.
expect([...source.matchAll(/(?<!void )executeRelaunch\((?:resolved|theme)(?:,[^)]*)?\)/g)]).toHaveLength(0);
- expect(source).toContain('void executeRelaunch(resolved, true);');
+ expect(source).toContain('void executeRelaunch(resolved);');
expect(source).toContain('void executeRelaunch(theme);');
});
});
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.ts
index 60229ff4fd..51734c8fb5 100644
--- a/apps/desktop/src/main/__tests__/updateService.test.ts
+++ b/apps/desktop/src/main/__tests__/updateService.test.ts
@@ -320,7 +320,7 @@ describe('installation version repair scope', () => {
});
});
-describe('binary version checks after a user-requested update', () => {
+describe('binary version checks after an applied update', () => {
beforeEach(() => {
readAutoUpdateSettings.mockReturnValue({ autoRelaunchOnIdle: false });
download.mockImplementation(async ({ targetPath }: { targetPath: string }) => {
@@ -330,7 +330,7 @@ describe('binary version checks after a user-requested update', () => {
});
});
- it('writes the target-version marker only when the user actually applies the update', async () => {
+ it('writes the target-version marker only when the update is actually applied', async () => {
const service = await freshUpdateService('darwin');
const { consumeStartupBinaryUpdateMarker } = await import('../agent-binaries/startup-update');
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);
@@ -351,15 +351,19 @@ describe('binary version checks after a user-requested update', () => {
}
});
- it('does not write the marker for an automatic update relaunch', async () => {
+ it('writes the same marker for an automatic update relaunch', async () => {
const service = await freshUpdateService('darwin');
+ const { consumeStartupBinaryUpdateMarker } = await import('../agent-binaries/startup-update');
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);
service.initUpdateService();
try {
await service.checkForUpdate(updateManifest());
+ const markerPath = path.join(TEST_USER_DATA, 'agent-binary-update-once.json');
+ expect(fs.existsSync(markerPath)).toBe(false);
await expect(ipcHandlers.get('update-relaunch-auto')?.({}, 'dark')).resolves.toMatchObject({ accepted: true });
await vi.waitFor(() => { expect(spawnProcess).toHaveBeenCalledOnce(); });
- expect(fs.existsSync(path.join(TEST_USER_DATA, 'agent-binary-update-once.json'))).toBe(false);
+ expect(JSON.parse(fs.readFileSync(markerPath, 'utf8'))).toMatchObject({ version: '0.0.65' });
+ expect(consumeStartupBinaryUpdateMarker(TEST_USER_DATA, '0.0.65')).toBe(true);
} finally {
service.stopUpdateService();
exitSpy.mockRestore();
diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.ts
index 12f3e8ac2e..464e057867 100644
--- a/apps/desktop/src/main/updateService.ts
+++ b/apps/desktop/src/main/updateService.ts
@@ -1850,10 +1850,10 @@ function executeUpdateLinux(debPath: string, installation: LinuxUserInstallation
});
}
-async function executeRelaunch(theme: 'light' | 'dark', checkForBinaryUpdates = false): Promise<void> {
+async function executeRelaunch(theme: 'light' | 'dark'): Promise<void> {
if (isCindyPersonalRuntime()) return;
try {
- await executeRelaunchUnguarded(theme, checkForBinaryUpdates);
+ await executeRelaunchUnguarded(theme);
} catch (err) {
log.error('executeRelaunch() failed: %s', err instanceof Error ? err.stack ?? err.message : String(err));
try {
@@ -1873,7 +1873,7 @@ async function executeRelaunch(theme: 'light' | 'dark', checkForBinaryUpdates =
}
}
-async function executeRelaunchUnguarded(theme: 'light' | 'dark', checkForBinaryUpdates: boolean): Promise<void> {
+async function executeRelaunchUnguarded(theme: 'light' | 'dark'): Promise<void> {
if (isRelaunching) {
log.info('executeRelaunch() skipped — already in progress');
return;
@@ -1982,7 +1982,9 @@ async function executeRelaunchUnguarded(theme: 'light' | 'dark', checkForBinaryU
maskPath(readyFilePath), fs.statSync(readyFilePath).size,
);
- if (checkForBinaryUpdates && readyVersion) {
+ // Every applied app update — manual, idle or startup auto-relaunch — checks
+ // agent binaries once on the next launch; ordinary launches do not.
+ if (readyVersion) {
cancelStartupBinaryUpdateCheck = writeStartupBinaryUpdateMarker(app.getPath('userData'), readyVersion);
}
@@ -2039,7 +2041,7 @@ export function initUpdateService(): void {
// default and the .env'd-out look most users have.
const resolved = theme === 'light' || theme === 'dark' ? theme : 'dark';
resolvedRelaunchTheme = resolved;
- void executeRelaunch(resolved, true);
+ void executeRelaunch(resolved);
});
ipcMain.handle(
diff --git a/docs/desktop-startup-binary-updates.md b/docs/desktop-startup-binary-updates.md
index 62347298ba..c1566e95be 100644
--- a/docs/desktop-startup-binary-updates.md
+++ b/docs/desktop-startup-binary-updates.md
@@ -8,9 +8,10 @@
- 普通启动:向二进制预检查与准备流程传入 `checkForUpdates: false`。本地存在可用运行时
时返回其真实路径;有本地版本探针的运行时按真实版本选择候选,保留用户自更新结果。
-- 用户点击应用内热更重启:确认更新可以执行后,写入目标应用版本的一次性标记;新版本
- 启动时开启二进制版本检查,复用原有升级流程。
-- 仅下载应用更新、后台自动更新重启、普通重启:不写该标记。
+- 应用更新重启(用户点击重启、空闲自动重启、启动时自动应用更新):三者走同一个
+ 执行入口,确认更新可以执行后,写入目标应用版本的一次性标记;新版本启动时开启二进制
+ 版本检查,复用原有升级流程。自动更新的用户与手动更新的用户同样能拿到新版运行时。
+- 仅下载应用更新、普通重启:不写该标记。
- Pi 的可选资产规则不变:清单撤回资产或无法取得清单时,不因本地残留而重新启用。
- Linux 已验证的私有运行时同样可以在普通启动时复用;更新检查开启时继续执行现有
CDN 优先与运行时回退逻辑。
@@ -34,7 +35,7 @@
- `apps/desktop/src/main/agent-binaries/index.ts`:统一决定本次启动的检查参数,启动与恢复调用无需传开关。
- `apps/desktop/src/main/agent-binaries/`:本地复用与一次性标记;Linux 在下载前查找可用的受管、私有和系统运行时。
-- `apps/desktop/src/main/updateService.ts`:仅用户主动更新重启时写标记,执行失败时清理。
+- `apps/desktop/src/main/updateService.ts`:应用更新重启的统一执行入口写标记,执行失败时清理。
恢复每次启动检查,只需将公共入口的默认检查决定改为 `true`。移除整项功能
不需要迁移或删除用户已经安装的二进制。