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 during timeout recovery
CHEYAN31f0ee8a4416
diff --git a/apps/desktop/src/main/__tests__/authStartupGate.test.ts b/apps/desktop/src/main/__tests__/authStartupGate.test.tsindex 1892598164..a8ba90771f 100644--- a/apps/desktop/src/main/__tests__/authStartupGate.test.ts+++ b/apps/desktop/src/main/__tests__/authStartupGate.test.ts@@ -193,6 +193,7 @@ describe('ColdStartAuthFallbackRegistry', () => {const result = await resolveColdStartTimeoutRecovery({ownerTransitionPending: true,authChangedSinceInitialize: false,+ loginCommitPending: false,isStartupFallbackEpoch: () => false,timeoutStartEpoch: 7,currentEpoch: 7,@@ -212,6 +213,7 @@ describe('ColdStartAuthFallbackRegistry', () => {await expect(resolveColdStartTimeoutRecovery({ownerTransitionPending: false,authChangedSinceInitialize: false,+ loginCommitPending: false,isStartupFallbackEpoch: () => false,timeoutStartEpoch: 7,currentEpoch: 7,@@ -222,6 +224,23 @@ describe('ColdStartAuthFallbackRegistry', () => {expect(recover).toHaveBeenCalledOnce();});+ it('returns a pending boundary while an explicit login transaction is committing', async () => {+ const pendingState = { mode: 'signed-out', ownerBoundaryPending: true } as const;+ const recover = vi.fn(async () => ({ mode: 'signed-out' as const }));+ await expect(resolveColdStartTimeoutRecovery({+ ownerTransitionPending: false,+ authChangedSinceInitialize: false,+ loginCommitPending: true,+ isStartupFallbackEpoch: () => false,+ timeoutStartEpoch: 7,+ currentEpoch: 8,+ currentState: { mode: 'cloud', userId: 'login-committing' },+ pendingState,+ recover,+ })).resolves.toEqual(pendingState);+ expect(recover).not.toHaveBeenCalled();+ });+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 }));@@ -229,6 +248,7 @@ describe('ColdStartAuthFallbackRegistry', () => {await expect(resolveColdStartTimeoutRecovery({ownerTransitionPending: false,authChangedSinceInitialize: false,+ loginCommitPending: false,isStartupFallbackEpoch: () => false,timeoutStartEpoch: 7,currentEpoch: 8,@@ -252,6 +272,7 @@ describe('ColdStartAuthFallbackRegistry', () => {await expect(resolveColdStartTimeoutRecovery({ownerTransitionPending: false,authChangedSinceInitialize: authStateEpoch !== initializeStartEpoch,+ loginCommitPending: false,isStartupFallbackEpoch: () => false,timeoutStartEpoch: initializeStartEpoch,currentEpoch: authStateEpoch,diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.tsindex ffd89c7f97..03a4fd72b5 100644--- a/apps/desktop/src/main/authManager.ts+++ b/apps/desktop/src/main/authManager.ts@@ -4733,6 +4733,7 @@ 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(),+ loginCommitPending: sealedLoginFlowCommitDepths.size > 0,authChangedSinceInitialize: authStateEpoch !== initializeStartEpoch,isStartupFallbackEpoch: (epoch) =>epoch > initializeStartEpoch &&diff --git a/apps/desktop/src/main/authStartupGate.ts b/apps/desktop/src/main/authStartupGate.tsindex 01ed1cd92a..db08b19e30 100644--- a/apps/desktop/src/main/authStartupGate.ts+++ b/apps/desktop/src/main/authStartupGate.ts@@ -80,6 +80,7 @@ export async function awaitWithStartupTimeout<T>(export async function resolveColdStartTimeoutRecovery<TCurrent, TPending, TRecovered>(input: {ownerTransitionPending: boolean;authChangedSinceInitialize: boolean;+ loginCommitPending: boolean;isStartupFallbackEpoch: (epoch: number) => boolean;timeoutStartEpoch: number;currentEpoch: number;@@ -87,11 +88,10 @@ export async function resolveColdStartTimeoutRecovery<TCurrent, TPending, TRecovpendingState: 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;+ // A pending owner transition owns the user-data boundary. A login also reserves+ // the auth epoch before its async vault/owner transaction commits. Neither may+ // race a timeout recovery; their own commit/rollback publishes the settled state.+ if (input.ownerTransitionPending || input.loginCommitPending) 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.