Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auth): preserve login from sibling startup timeout
CHEYANa9eeecfea310
diff --git a/apps/desktop/src/main/__tests__/authLoginFlowReset.contract.test.ts b/apps/desktop/src/main/__tests__/authLoginFlowReset.contract.test.tsindex c4e5bec186..76b9d68b8d 100644--- a/apps/desktop/src/main/__tests__/authLoginFlowReset.contract.test.ts+++ b/apps/desktop/src/main/__tests__/authLoginFlowReset.contract.test.ts@@ -909,6 +909,9 @@ describe('auth login-flow reset', () => {expect(guardedRecovery).toBeGreaterThan(-1);expect(guardedRecovery).toBeLessThan(timeoutRecovery);expect(initializeBody).toContain('pendingState: snapshotLoggedOutAuthState(true)');+ expect(initializeBody).toContain('timeoutStartEpoch: startupTimeoutEpoch');+ expect(initializeBody).toContain('currentEpoch: authStateEpoch');+ expect(initializeBody).toContain('currentState: snapshotAuthState()');expect(initializeBody).not.toContain('await ownerChangeShellGate.waitForSettled();\n return snapshotAuthState();');// The fallback must tell the recovery it is the startup-gate fallback, so the// epoch it raises is recorded at the moment it is raised (see below).diff --git a/apps/desktop/src/main/__tests__/authStartupGate.test.ts b/apps/desktop/src/main/__tests__/authStartupGate.test.tsindex 38cae7406f..6422eb0f09 100644--- a/apps/desktop/src/main/__tests__/authStartupGate.test.ts+++ b/apps/desktop/src/main/__tests__/authStartupGate.test.ts@@ -192,6 +192,9 @@ describe('ColdStartAuthFallbackRegistry', () => {const recover = vi.fn(async () => ({ mode: 'signed-out', ownerBoundaryPending: false }));const result = await resolveColdStartTimeoutRecovery({ownerTransitionPending: true,+ timeoutStartEpoch: 7,+ currentEpoch: 7,+ currentState: { mode: 'cloud', ownerBoundaryPending: false },pendingState,recover,});@@ -201,24 +204,44 @@ describe('ColdStartAuthFallbackRegistry', () => {it('recovers a signed-out owner when no owner transition is pending', async () => {const pendingState = { mode: 'signed-out', ownerBoundaryPending: true } as const;+ const currentState = { mode: 'cloud', ownerBoundaryPending: false } as const;const recoveredState = { mode: 'signed-out', ownerBoundaryPending: false } as const;const recover = vi.fn(async () => recoveredState);await expect(resolveColdStartTimeoutRecovery({ownerTransitionPending: false,+ timeoutStartEpoch: 7,+ currentEpoch: 7,+ currentState,pendingState,recover,})).resolves.toBe(recoveredState);expect(recover).toHaveBeenCalledOnce();});+ it('preserves an explicit login completed before a sibling startup timeout', async () => {+ const loggedInState = { mode: 'cloud', userId: 'new-owner' } as const;+ const recover = vi.fn(async () => ({ mode: 'signed-out' as const }));++ await expect(resolveColdStartTimeoutRecovery({+ ownerTransitionPending: false,+ timeoutStartEpoch: 7,+ currentEpoch: 8,+ currentState: loggedInState,+ pendingState: { mode: 'signed-out', ownerBoundaryPending: true },+ recover,+ })).resolves.toBe(loggedInState);++ expect(recover).not.toHaveBeenCalled();+ });+it('preserves a late successful refresh across consecutive renderer startup timeouts', async () => {vi.useFakeTimers();const registry = new ColdStartAuthFallbackRegistry();const flowEpoch = 7;let currentEpoch = flowEpoch;let committedUser: string | null = null;- let resolveRefresh!: (user: unknown) => void;- const refresh = new Promise<unknown>((resolve) => {+ let resolveRefresh!: (user: string) => void;+ const refresh = new Promise<string>((resolve) => {resolveRefresh = resolve;});const recover = () => {diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.tsindex 91c956aa60..ddb0fccd70 100644--- a/apps/desktop/src/main/authManager.ts+++ b/apps/desktop/src/main/authManager.ts@@ -4714,6 +4714,7 @@ export async function initialize(options: AuthInitializeOptions = {}): Promise<A// 黑洞 / captive-portal 网络护栏:限时等待,超时先以未登录返回解锁 splash,// 流程继续后台跑;迟到成功由流程内部广播登录态(renderer 自动跳回主界面)。const coldStartCompletion = coldStartAuthInFlight;+ const startupTimeoutEpoch = authStateEpoch;return awaitWithStartupTimeout(coldStartCompletion, {timeoutMs: COLD_START_AUTH_GATE_TIMEOUT_MS,onTimeout: async () => {@@ -4731,6 +4732,9 @@ export async function initialize(options: AuthInitializeOptions = {}): Promise<A// the transition's own commit/rollback broadcast publish the settled state.const recovery = await resolveColdStartTimeoutRecovery({ownerTransitionPending: ownerChangeShellGate.isPending(),+ timeoutStartEpoch: startupTimeoutEpoch,+ currentEpoch: authStateEpoch,+ currentState: snapshotAuthState(),pendingState: snapshotLoggedOutAuthState(true),recover: () =>recoverAccountFreeOwnerAtStartup('signed-out', 'cold-start-timeout-recovery', false, {diff --git a/apps/desktop/src/main/authStartupGate.ts b/apps/desktop/src/main/authStartupGate.tsindex dd62ac1076..0486db0ecd 100644--- a/apps/desktop/src/main/authStartupGate.ts+++ b/apps/desktop/src/main/authStartupGate.ts@@ -77,16 +77,23 @@ export async function awaitWithStartupTimeout<T>(}}-export async function resolveColdStartTimeoutRecovery<T>(input: {+export async function resolveColdStartTimeoutRecovery<TCurrent, TPending, TRecovered>(input: {ownerTransitionPending: boolean;- pendingState: T;- recover: () => Promise<T>;-}): Promise<T> {+ timeoutStartEpoch: number;+ currentEpoch: number;+ currentState: TCurrent;+ pendingState: TPending;+ recover: () => Promise<TRecovered>;+}): Promise<TCurrent | TPending | TRecovered> {// A pending owner transition owns the user-data boundary. Do not wait on its// teardown from the startup timeout callback and do not start a competing// account-free cleanup; return a fail-closed projection while the transition's// own commit/rollback broadcast will publish the settled state.if (input.ownerTransitionPending) return input.pendingState;+ // Sibling renderers share one refresh but own independent startup timers. A+ // user may complete login after one timeout exposes the login page and before+ // another timer fires; that later timeout must preserve the authenticated state.+ if (input.currentEpoch !== input.timeoutStartEpoch) return input.currentState;return input.recover();}