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): keep staged patches until a channel write commits

guyong17560d67e4bd
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.ts
index b35f6dd5d1..d8535ecc41 100644
--- a/apps/desktop/src/main/__tests__/updateService.test.ts
+++ b/apps/desktop/src/main/__tests__/updateService.test.ts
@@ -835,9 +835,23 @@ describe('startup update relaunch safety', () => {
await vi.waitFor(() => {
expect(releaseWrite).toBeTypeOf('function');
});
- expect(fs.existsSync(path.join(TEST_USER_DATA, 'updates', 'patch-info.json'))).toBe(false);
+ expect(fs.existsSync(path.join(TEST_USER_DATA, 'updates', 'patch-info.json'))).toBe(true);
releaseWrite?.();
await writePromise;
+ expect(fs.existsSync(path.join(TEST_USER_DATA, 'updates', 'patch-info.json'))).toBe(false);
+ } finally {
+ service.stopUpdateService();
+ }
+ });
+
+ it('keeps the staged patch when an org-default write is rejected', async () => {
+ const service = await bootWithStagedPatch({ enabled: false });
+ tryEnableUncustomizedBetaAtomic.mockResolvedValue(false);
+ try {
+ expect(fs.existsSync(path.join(TEST_USER_DATA, 'updates', 'patch-info.json'))).toBe(true);
+ await expect(service.enableUncustomizedBetaChannel()).resolves.toBe(false);
+ expect(service.getUpdateStatus()).toBe('ready');
+ expect(fs.existsSync(path.join(TEST_USER_DATA, 'updates', 'patch-info.json'))).toBe(true);
} finally {
service.stopUpdateService();
}
diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.ts
index 541cb40dc2..21c4ac6633 100644
--- a/apps/desktop/src/main/updateService.ts
+++ b/apps/desktop/src/main/updateService.ts
@@ -638,6 +638,11 @@ function rememberDeferredStagedPatch(): void {
};
}
+/** 先拦住 apply,不删 zip / patch-info。写入没成功时还能继续用这份补丁。 */
+function holdStagedPatchForPendingChannelChange(): void {
+ rememberDeferredStagedPatch();
+}
+
function isCurrentPatchNewerThanDeferred(
stale: { path?: string; epoch?: number },
): boolean {
@@ -1438,18 +1443,25 @@ export function initUpdateService(): void {
throwIpcError('INVALID_PARAMS', 'enableBeta required (boolean)');
}
const wasBeta = readUpdateChannelSettings().enableBeta;
- // 先作废旧补丁再等落盘:writeEnableBeta 可能卡住跨进程锁,这段空窗里
- // busyProbe 若返回,资格检查仍会看到旧渠道+旧 zip 并提交 apply。
+ // 先拦住 apply 再等落盘:writeEnableBeta 可能卡住跨进程锁。
+ // 真正写成之后再删 zip;写入失败则放开 hold,旧补丁还能用。
if (wasBeta !== next) {
observedEnableBeta = next;
- clearStagedPatch();
+ holdStagedPatchForPendingChannelChange();
}
try {
await writeEnableBeta(next);
} catch (err) {
+ if (wasBeta !== next) {
+ observedEnableBeta = wasBeta;
+ deferredStagedPatch = undefined;
+ }
log.error('writeEnableBeta failed:', err);
throwIpcError('INTERNAL', 'failed to write update channel settings');
}
+ if (wasBeta !== next) {
+ clearStagedPatch();
+ }
return channelSettingsWire();
});
@@ -1458,14 +1470,21 @@ export function initUpdateService(): void {
const wasBeta = readUpdateChannelSettings().enableBeta;
if (wasBeta) {
observedEnableBeta = false;
- clearStagedPatch();
+ holdStagedPatchForPendingChannelChange();
}
try {
await resetUpdateChannelSettings();
} catch (err) {
+ if (wasBeta) {
+ observedEnableBeta = wasBeta;
+ deferredStagedPatch = undefined;
+ }
log.error('resetUpdateChannelSettings failed:', err);
throwIpcError('INTERNAL', 'failed to reset update channel settings');
}
+ if (wasBeta) {
+ clearStagedPatch();
+ }
return channelSettingsWire();
});
@@ -1658,15 +1677,19 @@ export async function enableUncustomizedBetaChannel(
shouldWrite: () => boolean = () => true,
): Promise<boolean> {
const wasBeta = readUpdateChannelSettings().enableBeta;
- // 先作废旧补丁再等落盘,避免原子写等待期间自动重启把旧渠道包装上去。
- // 没真正写成开之前,不要把 observedEnableBeta 提前改成 true。
+ // 先拦住 apply 再等落盘。身份守卫拒绝或写入失败时,旧补丁还得能用。
if (!wasBeta) {
- clearStagedPatch();
+ holdStagedPatchForPendingChannelChange();
}
const wrote = await tryEnableUncustomizedBetaAtomic(shouldWrite);
if (wrote && !wasBeta) {
observedEnableBeta = true;
+ clearStagedPatch();
broadcastChannelSettings();
+ return wrote;
+ }
+ if (!wasBeta) {
+ deferredStagedPatch = undefined;
}
return wrote;
}
diff --git a/apps/desktop/src/renderer/components/settings/BetaChannelCell.tsx b/apps/desktop/src/renderer/components/settings/BetaChannelCell.tsx
index 99e59dfc73..9ea1da7fa2 100644
--- a/apps/desktop/src/renderer/components/settings/BetaChannelCell.tsx
+++ b/apps/desktop/src/renderer/components/settings/BetaChannelCell.tsx
@@ -17,6 +17,7 @@ import { cn } from '@/lib/utils';
import { toast } from '@/lib/toast';
import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
import { useBetaChannelSettings } from '@/hooks/useBetaChannelSettings';
+import { mapIpcErrorToI18nKey } from '@/utils/ipcError';
export function BetaChannelCell() {
const { t } = useTranslation();
@@ -71,9 +72,7 @@ export function BetaChannelCell() {
}
} catch (err) {
toast.error(
- err instanceof Error
- ? err.message
- : t('settings.betaChannel.toast.toggleFailed'),
+ t(mapIpcErrorToI18nKey(err, { fallback: 'settings.betaChannel.toast.toggleFailed' })),
);
} finally {
setPending(false);
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index fb36c20c5e..ec59d47d10 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -12,7 +12,8 @@
"REMOTE_PROVIDER_UPDATING": "Provider credentials are being updated — retry in a moment",
"REMOTE_PROVIDER_UNSUPPORTED": "This provider is not supported in SSH remote sessions — pick another source",
"REMOTE_NATIVE_OAUTH_UNAVAILABLE": "Claude.ai subscription is not connected — connect it first or pick a gateway model",
- "DEVICE_LINK_DEVICE_UNRESPONSIVE": "The target device is not responding. Check the remote device and try again."
+ "DEVICE_LINK_DEVICE_UNRESPONSIVE": "The target device is not responding. Check the remote device and try again.",
+ "INTERNAL": "Operation failed. Please try again later."
},
"providerError": {
"AUTH_INVALID": "Invalid or expired API key (401). Check the key and try again",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 20fa236f5a..fc19dd8916 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -12,7 +12,8 @@
"REMOTE_PROVIDER_UPDATING": "プロバイダーの認証情報を更新中です。しばらくしてから再試行してください",
"REMOTE_PROVIDER_UNSUPPORTED": "このプロバイダーは SSH リモートセッションに対応していません。別のソースを選択してください",
"REMOTE_NATIVE_OAUTH_UNAVAILABLE": "Claude.ai サブスクリプションが未接続です。先に接続するか、ゲートウェイモデルを選択してください",
- "DEVICE_LINK_DEVICE_UNRESPONSIVE": "対象デバイスが応答していません。リモートデバイスを確認して再試行してください。"
+ "DEVICE_LINK_DEVICE_UNRESPONSIVE": "対象デバイスが応答していません。リモートデバイスを確認して再試行してください。",
+ "INTERNAL": "操作に失敗しました。しばらくしてから再試行してください。"
},
"providerError": {
"AUTH_INVALID": "API キーが無効か期限切れです(401)。キーを確認して再試行してください",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 509ced144a..5275fa1911 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -12,7 +12,8 @@
"REMOTE_PROVIDER_UPDATING": "제공자 자격 증명을 업데이트하는 중입니다. 잠시 후 다시 시도하세요",
"REMOTE_PROVIDER_UNSUPPORTED": "이 제공자는 SSH 원격 세션을 지원하지 않습니다. 다른 소스를 선택하세요",
"REMOTE_NATIVE_OAUTH_UNAVAILABLE": "Claude.ai 구독이 연결되지 않았습니다. 먼저 연결하거나 게이트웨이 모델을 선택하세요",
- "DEVICE_LINK_DEVICE_UNRESPONSIVE": "대상 장치가 응답하지 않습니다. 원격 장치를 확인한 후 다시 시도하세요."
+ "DEVICE_LINK_DEVICE_UNRESPONSIVE": "대상 장치가 응답하지 않습니다. 원격 장치를 확인한 후 다시 시도하세요.",
+ "INTERNAL": "작업에 실패했습니다. 잠시 후 다시 시도하세요."
},
"providerError": {
"AUTH_INVALID": "API 키가 유효하지 않거나 만료되었습니다(401). 키를 확인한 후 다시 시도하세요",
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 1870007117..bfaa421e3c 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9,6 +9,7 @@
"REMOTE_PROVIDER_UNSUPPORTED": "该供应商不支持 SSH 远程会话,请更换来源",
"REMOTE_NATIVE_OAUTH_UNAVAILABLE": "未连接 Claude.ai 订阅,请先连接或选择网关模型",
"DEVICE_LINK_DEVICE_UNRESPONSIVE": "目标设备长时间无响应,请检查远程设备后重试",
+ "INTERNAL": "操作失败,请稍后重试。",
"REMOTE_WORKDIR_INVALID": "远程项目目录无效,请重新选择项目目录。",
"REMOTE_WORKDIR_NOT_FOUND": "远程项目目录不存在,请重新选择项目目录。",
"REMOTE_WORKDIR_NOT_DIRECTORY": "远程项目路径不是文件夹,请重新选择项目目录。",
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 11cd79adf7..6e1abf181f 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9,6 +9,7 @@
"REMOTE_PROVIDER_UNSUPPORTED": "該供應商不支援 SSH 遠端會話,請更換來源",
"REMOTE_NATIVE_OAUTH_UNAVAILABLE": "未連線 Claude.ai 訂閱,請先連線或選擇閘道器模型",
"DEVICE_LINK_DEVICE_UNRESPONSIVE": "目標裝置長時間無響應,請檢查遠端裝置後重試",
+ "INTERNAL": "操作失敗,請稍後重試。",
"REMOTE_WORKDIR_INVALID": "遠端專案目錄無效,請重新選擇專案目錄。",
"REMOTE_WORKDIR_NOT_FOUND": "遠端專案目錄不存在,請重新選擇專案目錄。",
"REMOTE_WORKDIR_NOT_DIRECTORY": "遠端專案路徑不是資料夾,請重新選擇專案目錄。",