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): keep prepared harness restarts on cached downloads

MagicLizi98f0a07408de
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.ts
index bdb85fcff6..a9b2aa54b1 100644
--- a/apps/desktop/src/main/__tests__/updateService.test.ts
+++ b/apps/desktop/src/main/__tests__/updateService.test.ts
@@ -730,6 +730,30 @@ describe('binary version checks after an applied update', () => {
} finally { service.stopUpdateService(); }
});
+ // Greptile #7435: prepare A, then publish B while confirmation is open. The
+ // prepared flow must not leave the legacy force-download marker. Tier: unit.
+ it('restarts a prepared harness without forcing a download of a superseding manifest', async () => {
+ const service = await freshUpdateService('darwin');
+ const { consumeStartupBinaryUpdateMarker } = await import('../agent-binaries/startup-update');
+ service.initUpdateService();
+ try {
+ await service.checkForUpdate(updateManifest());
+ expect(() => ipcHandlers.get('update-harness-relaunch')?.({ sender: { id: 1 } }, 'codex', '9.0.0')).toThrow('prepare the requested');
+ expect(appRelaunch).not.toHaveBeenCalled();
+ fetchManifest.mockResolvedValue({ ...updateManifest(), codexPackage: { version: '9.0.0', file: 'runtime.tar.gz', sha256: 'a'.repeat(64), size: 123 } });
+ await ipcHandlers.get('update-harness-prepare')?.({ sender: { id: 1 } }, 'codex', '9.0.0');
+ expect(() => ipcHandlers.get('update-harness-relaunch')?.({ sender: { id: 1 } }, 'codex', '9.1.0')).toThrow('prepare the requested');
+ fetchManifest.mockResolvedValue({ ...updateManifest(), codexPackage: { version: '9.1.0', file: 'runtime.tar.gz', sha256: 'b'.repeat(64), size: 123 } });
+ const checks = fetchManifest.mock.calls.length;
+ expect(ipcHandlers.get('update-harness-relaunch')?.({ sender: { id: 1 } }, 'codex', '9.0.0')).toEqual({ accepted: true });
+ expect(consumeStartupBinaryUpdateMarker(TEST_USER_DATA, appGetVersion())).toBe(false);
+ expect(fetchManifest).toHaveBeenCalledTimes(checks);
+ expect(service.getUpdateStatus()).toBe('ready');
+ expect(appRelaunch).toHaveBeenCalledExactlyOnceWith({ args: process.argv.slice(1) });
+ expect(appQuit).toHaveBeenCalledOnce();
+ } finally { service.stopUpdateService(); }
+ });
+
it('schedules a one-time refresh of only the confirmed harness before a graceful relaunch', async () => {
const service = await freshUpdateService('darwin');
const { consumeStartupBinaryUpdateMarker } = await import('../agent-binaries/startup-update');
diff --git a/apps/desktop/src/main/agent-binaries/__tests__/factory-startup-update.test.ts b/apps/desktop/src/main/agent-binaries/__tests__/factory-startup-update.test.ts
index 8a86e37613..988ab1e044 100644
--- a/apps/desktop/src/main/agent-binaries/__tests__/factory-startup-update.test.ts
+++ b/apps/desktop/src/main/agent-binaries/__tests__/factory-startup-update.test.ts
@@ -136,6 +136,17 @@ describe('background downloads handed to the existing installer', () => {
expect((await provisioner.prepare({ checkForUpdates: false })).binaryPath).not.toBe(oldPath);
});
+ it('keeps a usable old runtime without HTTP when the prefetched target is superseded before restart', async () => {
+ const oldPath = installLocal('1.0.0');
+ const provisioner = createBinaryProvisioner(config);
+ await expect(provisioner.prefetch({ manifest: { app: {} } as never })).resolves.toBe(true);
+ mocks.getVendorAsset.mockReturnValue({ ...asset, version: '4.0.0', sha256: 'd'.repeat(64) });
+ await expect(provisioner.prepare({ checkForUpdates: false })).resolves.toEqual({ ready: true, binaryPath: oldPath });
+ expect(mocks.download).not.toHaveBeenCalled();
+ expect(fs.readFileSync(oldPath, 'utf8')).toBe('local');
+ expect(fs.existsSync(path.join(mocks.userDataDir, config.installSubdir, '4.0.0', '.verified'))).toBe(false);
+ });
+
it('rejects a modified cache without a startup download or a false installed marker', async () => {
const oldPath = installLocal('1.0.0');
const provisioner = createBinaryProvisioner(config);
diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.ts
index e768c5d793..4aee39ce1c 100644
--- a/apps/desktop/src/main/updateService.ts
+++ b/apps/desktop/src/main/updateService.ts
@@ -2471,12 +2471,14 @@ export function initUpdateService(): void {
// About downloads before showing the restart confirmation. A failed preparation
// leaves both the application update state and the running harness untouched.
+ const preparedHarnessVersions = new Map<'claude-code' | 'codex', string>();
ipcMain.handle('update-harness-prepare', async (event, kind: unknown, expectedVersion: unknown) => {
assertTrustedAppRendererEvent(event);
if ((kind !== 'claude-code' && kind !== 'codex') || typeof expectedVersion !== 'string'
|| expectedVersion.length === 0 || expectedVersion.length > 128) {
throwIpcError('INVALID_PARAMS', 'kind and expectedVersion required');
}
+ preparedHarnessVersions.delete(kind);
const signal = AbortSignal.timeout(180_000);
const manifest = await fetchManifest(undefined, signal);
const asset = manifest && getVendorAsset(manifest, kind === 'claude-code' ? 'claudeCode' : 'codexPackage');
@@ -2486,21 +2488,28 @@ export function initUpdateService(): void {
if (!await prefetchAgentBinary(kind, { manifest, signal })) {
throwIpcError('INTERNAL', 'could not prepare harness update; retry later');
}
+ preparedHarnessVersions.set(kind, expectedVersion);
return { ready: true };
});
// About → Agent version update: keep the same graceful app relaunch lifecycle,
- // but ask the next startup to refresh managed harness binaries before they are
- // exposed to Maker. The marker is consumed once by agent-binaries/prepare and
- // is scoped to the harness the user confirmed; Pi has its own kernel manager.
- ipcMain.handle('update-harness-relaunch', (event, kind: unknown) => {
+ // with cache-only adoption for prepared targets. Only legacy kind-only callers
+ // retain a scoped repair marker: a newer manifest must not cause a prepared
+ // update to download again in Splash. Pi has its own kernel manager.
+ ipcMain.handle('update-harness-relaunch', (event, kind: unknown, preparedVersion?: unknown) => {
assertTrustedAppRendererEvent(event);
if (kind !== 'claude-code' && kind !== 'codex') {
throwIpcError('INVALID_PARAMS', 'kind required (claude-code | codex)');
}
- const cancelMarker = writeStartupBinaryUpdateMarker(app.getPath('userData'), app.getVersion(), [kind]);
- if (!cancelMarker) {
- throwIpcError('INTERNAL', 'failed to schedule harness update');
+ if (preparedVersion !== undefined) {
+ if (typeof preparedVersion !== 'string' || preparedHarnessVersions.get(kind) !== preparedVersion) {
+ throwIpcError('INVALID_PARAMS', 'prepare the requested harness version before restarting');
+ }
+ } else {
+ const cancelMarker = writeStartupBinaryUpdateMarker(app.getPath('userData'), app.getVersion(), [kind]);
+ if (!cancelMarker) {
+ throwIpcError('INTERNAL', 'failed to schedule harness update');
+ }
}
log.info(`harness update relaunch requested: ${kind}`);
app.relaunch({ args: process.argv.slice(1) });
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index de07e9fc90..4c67aa02ea 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -2877,9 +2877,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
/** Cache the confirmed target before the user chooses to interrupt work and restart. */
prepareHarnessUpdate: (kind: 'claude-code' | 'codex', version: string): Promise<{ ready: true }> =>
ipcRenderer.invoke('update-harness-prepare', kind, version),
- /** Restart once; the next startup refreshes only the confirmed managed harness first. */
- relaunchForHarnessUpdate: (kind: 'claude-code' | 'codex'): Promise<{ accepted: true }> =>
- ipcRenderer.invoke('update-harness-relaunch', kind),
+ /** Prepared targets adopt cache only; omitted version keeps the legacy repair flow. */
+ relaunchForHarnessUpdate: (kind: 'claude-code' | 'codex', preparedVersion?: string): Promise<{ accepted: true }> =>
+ ipcRenderer.invoke('update-harness-relaunch', kind, preparedVersion),
probeBetaChannel: (): Promise<{ available: boolean }> =>
ipcRenderer.invoke('update-channel-probe-beta'),
setUpdateRelaunchTheme: (theme: 'light' | 'dark'): void => {
diff --git a/apps/desktop/src/renderer/components/settings/AboutSection.tsx b/apps/desktop/src/renderer/components/settings/AboutSection.tsx
index f34a314055..dcb7b3738b 100644
--- a/apps/desktop/src/renderer/components/settings/AboutSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/AboutSection.tsx
@@ -295,7 +295,7 @@ function AgentVersionRow({
if (!canUpdate()) return;
try {
- await window.electronAPI.relaunchForHarnessUpdate(kind);
+ await window.electronAPI.relaunchForHarnessUpdate(kind, targetVersion);
} catch {
toast.error(t('settings.about.harnessUpdateFailed'));
}
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/AboutSection.binaryVersions.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/AboutSection.binaryVersions.test.tsx
index 7ea628bf98..56b99f2577 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/AboutSection.binaryVersions.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/AboutSection.binaryVersions.test.tsx
@@ -238,7 +238,7 @@ describe('AboutSection agent binary versions', () => {
expect(relaunchForHarnessUpdate).not.toHaveBeenCalled();
expect(prepareHarnessUpdate).toHaveBeenCalledExactlyOnceWith('codex', 'v1.1.0');
fireEvent.click(screen.getByRole('button', { name: 'settings.about.harnessUpdateConfirm Codex' }));
- await waitFor(() => expect(relaunchForHarnessUpdate).toHaveBeenCalledExactlyOnceWith('codex'));
+ await waitFor(() => expect(relaunchForHarnessUpdate).toHaveBeenCalledExactlyOnceWith('codex', 'v1.1.0'));
});
// Manual updates now prepare outside Splash. Keep restart confirmation after
@@ -292,7 +292,7 @@ describe('AboutSection agent binary versions', () => {
expect(relaunchForHarnessUpdate).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button', { name: 'settings.about.harnessUpdateConfirm Codex' }));
- await waitFor(() => expect(relaunchForHarnessUpdate).toHaveBeenCalledExactlyOnceWith('codex'));
+ await waitFor(() => expect(relaunchForHarnessUpdate).toHaveBeenCalledExactlyOnceWith('codex', '1.1.0'));
});
it('does not relaunch when the busy probe fails and the interruption warning is declined', async () => {
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index a124231eef..9bec4d5531 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -4008,8 +4008,8 @@ interface ElectronAPI {
relaunchForChannelChange: () => Promise<void>;
/** 下载并校验指定版本;完成前不重启、不切换当前引擎。 */
prepareHarnessUpdate: (kind: 'claude-code' | 'codex', version: string) => Promise<{ ready: true }>;
- /** 用户确认后重启,下一次启动只更新所确认的受管 Harness(Pi 由内核管理单独处理)。 */
- relaunchForHarnessUpdate: (kind: 'claude-code' | 'codex') => Promise<{ accepted: true }>;
+ /** 已准备的目标只消费缓存;省略版本保留旧入口的指定引擎修复(Pi 单独管理)。 */
+ relaunchForHarnessUpdate: (kind: 'claude-code' | 'codex', preparedVersion?: string) => Promise<{ accepted: true }>;
/** 打开 beta 前预检:探测 beta manifest 是否可达(HTTP 200)。 */
probeBetaChannel: () => Promise<{ available: boolean }>;
onUpdateChannelSettings: (
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 739282a8b8..d1f2dcbf86 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -678,10 +678,13 @@ all states use semantic colors in both Light and Dark.
Claude Code and Codex use the same row, trigger and menu (`HarnessVersionMenuRow`), with only
the Cindy-maintained version chain: update to the current channel's version (shown right-aligned,
disabled unless strictly newer), check again, and the last successful check time. A later failed
-online check keeps that last version in the menu but disables Update: restart re-checks the
-manifest and cannot install from a stale result. There is no upstream source, restore or
-release-notes entry. Updating keeps the existing confirm → busy warning → restart flow; the
-download happens in the normal startup Splash, not in the row.
+online check keeps that last version in the menu but disables Update. There is no upstream
+source, restore or release-notes entry. Updating first prepares the selected version in the
+shared background cache, showing download status in the row, then follows the existing
+confirm → busy warning → restart flow. Startup installs only a complete cache matching the
+current manifest; if that target has changed or the cache is unavailable, it keeps a usable
+old runtime and retries in the background. First-install and repair downloads retain their
+existing startup fallback.
### User-attached long images
diff --git a/docs/dev-rules/cindy-updater.md b/docs/dev-rules/cindy-updater.md
index 8ac70d5f75..eb71a7f43d 100644
--- a/docs/dev-rules/cindy-updater.md
+++ b/docs/dev-rules/cindy-updater.md
@@ -59,6 +59,9 @@ Linux 的可用系统/私有引擎也能消费缓存,缓存不可用时继续
设置中的 Claude Code/Codex 更新先调用本地 `update-harness-prepare`,复用后台缓存和锁,
完成后再确认重启及中断运行中的工作;失败可重试,离开设置后不弹出迟到的重启确认。
+新入口重启时携带准备成功的原始目标版本,由宿主复核,不再写强制联网的 scoped 标记;
+确认期间清单或缓存改变时,下次启动保留可用旧引擎,等待后台重试。旧的仅传 kind 的重启
+调用仍写 scoped 修复标记,兼容原入口。
Pi 的显式版本选择沿用原内核管理器,不由后台更新覆盖。没有搬迁既有引擎目录、凭证
或设置,也没有修改 Tauri 更新器;旧客户端忽略新的下载缓存。
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 5a2da4bdcf..eef02efd74 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -15,8 +15,9 @@ Profile 版本)。它是显式接受模型的意图;宿主重新校验模型
Desktop 新增本机 `update-harness-prepare` IPC(Claude Code/Codex、用户看到的目标版本),
只供可信应用顶层 renderer 在重启确认前准备下载,不暴露到 device-link allowlist。
-原 `update-harness-relaunch` 参数与回复保持兼容,旧设置入口与旧的一次性修复标记仍可
-更新。应用更新 IPC、手机与设备间 wire protocol 不变;后台归档只放新缓存目录,旧客户端
+原 `update-harness-relaunch` 追加可选 `preparedVersion`:宿主只接受本轮准备成功的目标,
+下次启动只消费缓存,避免确认期间清单变化又触发启动下载。省略参数的旧设置入口仍写
+原 scoped 修复标记,回复保持兼容。应用更新 IPC、手机与设备间 wire protocol 不变;后台归档只放新缓存目录,旧客户端
忽略它,不改变原安装目录、凭证、数据库或持久偏好。
## 任务链接保留所属电脑