Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve newer Linux runtimes when adopting binary cache
MagicLizi65e785e4bbe1
diff --git a/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts b/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.tsindex adbf6fc202..59d4dbe1ff 100644--- a/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts+++ b/apps/desktop/src/main/agent-binaries/__tests__/startup-policy.test.ts@@ -8,7 +8,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi }import type { Manifest } from '../../manifestService';import { createPiRuntimeRecovery } from '../pi-runtime-recovery';import { writeStartupBinaryUpdateMarker } from '../startup-update';-import { newerStableVersion, PINNED_CODEX_VERSION } from './runtimeVersionFixtures';+import { newerStableVersion, PINNED_CLAUDE_VERSION, PINNED_CODEX_VERSION } from './runtimeVersionFixtures';const mocks = vi.hoisted(() => ({userDataDir: '',@@ -297,6 +297,31 @@ describe('explicit Pi selection on startup', () => {});describe('Linux local discovery before any update download', () => {+ // #7435: a completed cache must not silently downgrade a user-managed Claude.+ // Public prefetch -> prepare, one newer system CLI and one older archive. Unit.+ it('keeps a newer Linux system Claude when an older background download is complete', async () => {+ await reloadBinaries('linux');+ const target = newerStableVersion(PINNED_CLAUDE_VERSION);+ const current = newerStableVersion(target);+ const oldArchive = gzipSync(Buffer.from(target));+ const sha256 = createHash('sha256').update(oldArchive).digest('hex');+ mocks.remoteManifest = { app: { version: '2.0.0' }, claudeCode: {+ version: target, file: `claude-code/${target}/linux-x64/claude.gz`, sha256, size: oldArchive.length,+ } };+ const systemPath = writeExecutable(path.join(tempRoot, 'newer-system-claude'), `${current} (Claude Code)`);+ mocks.systemCommands.set('claude', systemPath);+ mocks.backgroundDownload.mockImplementation(async ({ targetPath }: { targetPath: string }) => {+ fs.writeFileSync(targetPath, oldArchive);+ return { path: targetPath, sha256, size: oldArchive.length };+ });+ await expect(binaries.prefetch('claude-code', { manifest: mocks.remoteManifest })).resolves.toBe(true);+ await expect(binaries.prepare('claude-code', quiet)).resolves.toMatchObject({ ready: true, path: systemPath });+ expect(binaries.getReadyBinaryPath('claude-code')).toBe(systemPath);+ expect(fs.readFileSync(systemPath, 'utf8')).toBe(`${current} (Claude Code)`);+ expect(mocks.download).not.toHaveBeenCalled();+ expect(fs.existsSync(path.join(mocks.userDataDir, 'claude-code', target, '.verified'))).toBe(false);+ });+it('keeps the previously used system Codex when a newer CDN release appears on the next startup', async () => {await reloadBinaries('linux');const systemPath = writeExecutable(path.join(tempRoot, 'system-codex'), 'codex-cli ' + PINNED_CODEX_VERSION);diff --git a/apps/desktop/src/main/agent-binaries/index.ts b/apps/desktop/src/main/agent-binaries/index.tsindex 8b64d38ee3..9f45caafef 100644--- a/apps/desktop/src/main/agent-binaries/index.ts+++ b/apps/desktop/src/main/agent-binaries/index.ts@@ -33,7 +33,7 @@ import fs from 'node:fs';import { app, BrowserWindow } from 'electron';import { createBinaryProvisioner } from './factory.js';-import { probeBinaryVersion } from './binary-version-probe.js';+import { isBinaryVersionNotOlder, normalizeBinaryVersion, probeBinaryVersion } from './binary-version-probe.js';import { findDevBinary } from './dev-fallback.js';import {findCachedLinuxRuntimeFallbackBinary,@@ -447,7 +447,16 @@ export async function prepare(if (localPath) {const manifest = getCachedManifest();const asset = manifest && getVendorAsset(manifest, cfg.manifestField);- if (!asset || !hasPreparedBinaryDownload(cfg.vendorKey, asset)) {+ let usePreparedDownload = false;+ if (asset && hasPreparedBinaryDownload(cfg.vendorKey, asset)) {+ const localVersion = await probeBinaryVersion(localPath, opts.signal);+ const targetVersion = normalizeBinaryVersion(asset.version);+ // As with managed installs, adopt only a provably newer target.+ // Failed/unknown probes keep the already usable system/private CLI.+ usePreparedDownload = Boolean(localVersion && targetVersion+ && !isBinaryVersionNotOlder(localVersion, targetVersion));+ }+ if (!usePreparedDownload) {lastReadyPath.set(kind, localPath);return { ready: true, path: localPath, downloaded: false };}diff --git a/docs/dev-rules/cindy-updater.md b/docs/dev-rules/cindy-updater.mdindex eb71a7f43d..397d5f2d33 100644--- a/docs/dev-rules/cindy-updater.md+++ b/docs/dev-rules/cindy-updater.md@@ -55,7 +55,8 @@ check → download → relaunch 状态机,且必须先经宿主确认卡;不下次启动仍由原安装器解压、校验安装与选定路径,优先消费已经校验的下载缓存。旧应用更新器留下的无范围一次性标记不再强制联网升级;缓存未准备好时复用本地可用版本。首次安装、本地版本不可用以及旧版设置入口留下的指定引擎修复标记保留原下载兜底。-Linux 的可用系统/私有引擎也能消费缓存,缓存不可用时继续使用原引擎。+Linux 的可用系统/私有引擎也能消费缓存;只有目标版本确定更新时才采用,缓存不可用、+实际本地版本不低于目标或无法比较时继续使用原引擎,不由后台缓存降级。设置中的 Claude Code/Codex 更新先调用本地 `update-harness-prepare`,复用后台缓存和锁,完成后再确认重启及中断运行中的工作;失败可重试,离开设置后不弹出迟到的重启确认。