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): hold staged patches during relaunch eligibility

guyong87be19d93491
diff --git a/apps/desktop/src/main/__tests__/updateService.test.ts b/apps/desktop/src/main/__tests__/updateService.test.ts
index ceb44e11e6..82c68465f2 100644
--- a/apps/desktop/src/main/__tests__/updateService.test.ts
+++ b/apps/desktop/src/main/__tests__/updateService.test.ts
@@ -70,12 +70,33 @@ vi.mock('../auto-update-settings-store', () => ({
writeAutoRelaunchOnIdle: vi.fn(),
}));
+const tryEnableUncustomizedBeta = vi.fn(() => true);
+const readUpdateChannelSettings = vi.fn(() => ({
+ enableBeta: false,
+ orgDefaultEnableBeta: false,
+}));
+
vi.mock('../manifestService', () => ({
fetchManifest,
getBaseUrl,
isDev,
}));
+vi.mock('../updateChannelStore', () => ({
+ readUpdateChannelSettings,
+ readUpdateChannelSettingsState: () => ({
+ value: readUpdateChannelSettings(),
+ isCustomized: false,
+ customizedKeys: [],
+ defaults: { enableBeta: false, orgDefaultEnableBeta: false },
+ }),
+ resetUpdateChannelSettings: () => ({ enableBeta: false, orgDefaultEnableBeta: false }),
+ writeEnableBeta: vi.fn(),
+ tryEnableUncustomizedBeta,
+ isEnableBetaUserCustomized: () => false,
+ isBetaChannelEnabled: () => readUpdateChannelSettings().enableBeta === true,
+}));
+
vi.mock('../downloader/index', () => ({
download,
DownloadError: class DownloadError extends Error {
@@ -158,6 +179,13 @@ beforeEach(() => {
isDev.mockReset();
isDev.mockReturnValue(false);
download.mockReset();
+ tryEnableUncustomizedBeta.mockReset();
+ tryEnableUncustomizedBeta.mockReturnValue(true);
+ readUpdateChannelSettings.mockReset();
+ readUpdateChannelSettings.mockReturnValue({
+ enableBeta: false,
+ orgDefaultEnableBeta: false,
+ });
readAutoUpdateSettings.mockReset();
readAutoUpdateSettings.mockReturnValue({ autoRelaunchOnIdle: true });
logInfo.mockReset();
@@ -469,6 +497,29 @@ describe('startup update relaunch safety', () => {
service.stopUpdateService();
}
});
+
+ it('does not clear the staged patch while busyProbe is still pending', async () => {
+ const service = await bootWithStagedPatch({ enabled: true });
+ let releaseProbe: ((busy: boolean) => void) | undefined;
+ const probeStarted = new Promise<void>((resolveStarted) => {
+ service.setUpdateAutoRelaunchBusyProbe(
+ () =>
+ new Promise<boolean>((resolveProbe) => {
+ resolveStarted();
+ releaseProbe = resolveProbe;
+ }),
+ );
+ });
+ try {
+ await probeStarted;
+ expect(service.getUpdateStatus()).toBe('ready');
+ expect(service.enableUncustomizedBetaChannel()).toBe(true);
+ expect(service.getUpdateStatus()).toBe('ready');
+ } finally {
+ releaseProbe?.(true);
+ service.stopUpdateService();
+ }
+ });
});
describe('splash 启动下载 0% 显式广播', () => {
diff --git a/apps/desktop/src/main/updateService.ts b/apps/desktop/src/main/updateService.ts
index 68641ba29c..ff62094a61 100644
--- a/apps/desktop/src/main/updateService.ts
+++ b/apps/desktop/src/main/updateService.ts
@@ -153,6 +153,8 @@ let autoRelaunchPollTimer: ReturnType<typeof setInterval> | null = null;
let isRelaunching = false;
let lastErrorCode: string | undefined;
let autoRelaunchInProgress = false;
+/** 资格检查(含异步 busyProbe)进行中的次数。清补丁必须避开这个窗口。 */
+let autoRelaunchDecisionDepth = 0;
let lastAutoRelaunchBlockReason: AutoRelaunchBlockReason | null = null;
let lastBusyAtMs: number | null = null;
let lastResumeAtMs: number | null = null;
@@ -311,24 +313,36 @@ async function requestAutoRelaunch(
): Promise<AutoRelaunchRequestResult> {
// The startup/splash apply path uses the lighter gate (no idle/busy checks —
// nothing is in flight at launch); background triggers keep the full policy.
- const blockReason = useStartupPolicy
- ? await getStartupRelaunchBlockReason()
- : await getAutoRelaunchBlockReasonForCurrentState();
- if (blockReason) {
- if (blockReason !== lastAutoRelaunchBlockReason) {
- lastAutoRelaunchBlockReason = blockReason;
- if (readAutoUpdateSettings().autoRelaunchOnIdle && currentStatus === 'ready') {
- log.info('auto relaunch blocked (%s)', blockReason);
+ // 资格检查开始就抬深度:后台路径会 await busyProbe,这段空窗里 clearStagedPatch
+ // 若放行,随后 executeRelaunch 会走 no_ready_file。
+ autoRelaunchDecisionDepth += 1;
+ try {
+ const blockReason = useStartupPolicy
+ ? await getStartupRelaunchBlockReason()
+ : await getAutoRelaunchBlockReasonForCurrentState();
+ if (blockReason) {
+ if (blockReason !== lastAutoRelaunchBlockReason) {
+ lastAutoRelaunchBlockReason = blockReason;
+ if (readAutoUpdateSettings().autoRelaunchOnIdle && currentStatus === 'ready') {
+ log.info('auto relaunch blocked (%s)', blockReason);
+ }
}
+ return { accepted: false, blockReason };
}
- return { accepted: false, blockReason };
- }
- lastAutoRelaunchBlockReason = null;
- autoRelaunchInProgress = true;
- log.info('auto relaunch conditions met (%s), applying update v%s', reason, readyVersion ?? '<unknown>');
- executeRelaunch(theme);
- return { accepted: true };
+ if (!readyFilePath || !fs.existsSync(readyFilePath)) {
+ log.info('auto relaunch aborted — staged patch disappeared during eligibility check');
+ return { accepted: false, blockReason: 'not-ready' };
+ }
+
+ lastAutoRelaunchBlockReason = null;
+ autoRelaunchInProgress = true;
+ log.info('auto relaunch conditions met (%s), applying update v%s', reason, readyVersion ?? '<unknown>');
+ executeRelaunch(theme);
+ return { accepted: true };
+ } finally {
+ autoRelaunchDecisionDepth = Math.max(0, autoRelaunchDecisionDepth - 1);
+ }
}
async function evaluateAutoRelaunch(reason: string): Promise<void> {
@@ -560,7 +574,7 @@ function removePatchInfo(): void {
}
function isUpdateApplyInFlight(): boolean {
- return isRelaunching || autoRelaunchInProgress;
+ return isRelaunching || autoRelaunchInProgress || autoRelaunchDecisionDepth > 0;
}
/**