Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auth): 接受注册器确认的冷启动刷新代际
CHEYAN6078b6671a83
diff --git a/apps/desktop/src/main/__tests__/authStartupGate.test.ts b/apps/desktop/src/main/__tests__/authStartupGate.test.tsindex 1e98461d1d..d4607697a0 100644--- a/apps/desktop/src/main/__tests__/authStartupGate.test.ts+++ b/apps/desktop/src/main/__tests__/authStartupGate.test.ts@@ -16,6 +16,7 @@ import {awaitLoginProvidersWithPreparingGate,awaitWithStartupTimeout,ColdStartAuthFallbackRegistry,+ commitColdStartRefreshIfCurrent,mapLoginProvidersLoadFailure,} from '../authStartupGate';@@ -212,7 +213,8 @@ describe('ColdStartAuthFallbackRegistry', () => {resolveRefresh('owner');const refreshedUser = await refresh;- const commit = registry.commitIfCurrent({+ const commit = commitColdStartRefreshIfCurrent({+ registry,flowEpoch,currentEpoch,commit: () => {@@ -221,7 +223,7 @@ describe('ColdStartAuthFallbackRegistry', () => {},});- expect(commit).toEqual({ committed: true, value: 'owner' });+ expect(commit).toEqual({ superseded: false, flowEpoch: 9, value: 'owner' });expect(committedUser).toBe('owner');});@@ -230,9 +232,13 @@ describe('ColdStartAuthFallbackRegistry', () => {registry.record(8, 9);const commit = vi.fn(() => 'stale-owner');- expect(registry.commitIfCurrent({ flowEpoch: 7, currentEpoch: 9, commit })).toEqual({- committed: false,+ const rejected = commitColdStartRefreshIfCurrent({+ registry,+ flowEpoch: 7,+ currentEpoch: 9,+ commit,});+ expect(rejected).toEqual({ superseded: true });expect(commit).not.toHaveBeenCalled();});diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.tsindex f67d58c3dc..de24b8d81b 100644--- a/apps/desktop/src/main/authManager.ts+++ b/apps/desktop/src/main/authManager.ts@@ -66,6 +66,7 @@ import {awaitWithStartupTimeout,mapLoginProvidersLoadFailure,ColdStartAuthFallbackRegistry,+ commitColdStartRefreshIfCurrent,} from './authStartupGate';import { syncCanaryFlagAfterAuth } from './canaryFlagSync';import {@@ -4769,22 +4770,21 @@ async function runColdStartRefreshFlow(*/let flowAuthEpoch = epochAtStart;const epochChanged = (point: string): boolean => {- const fallbackCommit = coldStartTimeoutFallbacks.commitIfCurrent({+ const resolution = commitColdStartRefreshIfCurrent({+ registry: coldStartTimeoutFallbacks,flowEpoch: flowAuthEpoch,currentEpoch: authStateEpoch,commit: () => undefined,});- if (!fallbackCommit.committed) {- // Either nothing moved, or the only move was our own fallback — adopt the- // current epoch as this flow's own. Assigning is a no-op in the former case.- flowAuthEpoch = authStateEpoch;+ if (!resolution.superseded) {+ // A committed result means the epoch is unchanged or every transition is+ // this flow's startup fallback. Adopt the committed epoch before post-login sync.+ flowAuthEpoch = resolution.flowEpoch;return false;}log.warn(`cold-start refresh flow superseded by manual auth change (${point}) — discarding late result`,);- // A real user auth change landed on top of the fallback: this flow's epoch is- // now stale for good, so stop exempting it.coldStartTimeoutFallbacks.clear();return true;};diff --git a/apps/desktop/src/main/authStartupGate.ts b/apps/desktop/src/main/authStartupGate.tsindex e129e0d627..f224403611 100644--- a/apps/desktop/src/main/authStartupGate.ts+++ b/apps/desktop/src/main/authStartupGate.ts@@ -129,6 +129,23 @@ export class ColdStartAuthFallbackRegistry {}}+export function commitColdStartRefreshIfCurrent<T>(input: {+ registry: ColdStartAuthFallbackRegistry;+ flowEpoch: number;+ currentEpoch: number;+ commit: () => T;+}):+ | { superseded: true }+ | { superseded: false; flowEpoch: number; value: T } {+ const result = input.registry.commitIfCurrent({+ flowEpoch: input.flowEpoch,+ currentEpoch: input.currentEpoch,+ commit: input.commit,+ });+ if (!result.committed) return { superseded: true };+ return { superseded: false, flowEpoch: input.currentEpoch, value: result.value };+}+/*** 登录准备态(「正在连接登录服务」)最多阻塞 UI 的时长。getProviders 走* CindyAuthClient 默认 15s AbortController,但黑洞 / captive-portal 下 Electron