Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve owner on failed boundary rollback
DavidShen2b269effd3ce
diff --git a/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx b/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsxindex c63da625af..a719fd2f4a 100644--- a/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx+++ b/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx@@ -273,6 +273,35 @@ describe('AuthContext session cache boundaries', () => {});});+ it('does not finalize when a failed boundary rolls back from a pending signed-out push', async () => {+ let rejectLogout!: (error: Error) => void;+ mocks.service.logout.mockReturnValueOnce(+ new Promise<void>((_resolve, reject) => {+ rejectLogout = reject;+ }),+ );+ const view = renderHook(() => useAuth(), { wrapper });+ await waitFor(() => expect(view.result.current.dataOwnerId).toBe('account-a'));+ mocks.cancelRemoteOptimisticSendsForDataOwnerBoundary.mockClear();++ let logout!: Promise<void>;+ act(() => {+ logout = view.result.current.logout();+ });++ act(() => mocks.emitAuth({ ...authState(null), ownerGeneration: 1 }));+ act(() => mocks.emitAuth({ ...authState('account-a'), ownerGeneration: 1 }));+ expect(mocks.cancelRemoteOptimisticSendsForDataOwnerBoundary).toHaveBeenLastCalledWith({+ finalizeSessions: false,+ });++ await act(async () => {+ rejectLogout(new Error('logout failed'));+ await expect(logout).rejects.toThrow('logout failed');+ });+ expect(view.result.current.dataOwnerId).toBe('account-a');+ });+it('keeps a newer pushed owner when an older auth boundary later rejects', async () => {let rejectLogout!: (error: Error) => void;mocks.service.logout.mockReturnValueOnce(diff --git a/apps/desktop/src/renderer/contexts/AuthContext.tsx b/apps/desktop/src/renderer/contexts/AuthContext.tsxindex 631a976652..baf456e8ee 100644--- a/apps/desktop/src/renderer/contexts/AuthContext.tsx+++ b/apps/desktop/src/renderer/contexts/AuthContext.tsx@@ -213,7 +213,18 @@ export function AuthProvider({const applyIncomingState = useCallback((state: AuthState) => {- const ownerChanged = activeDataOwnerIdRef.current !== state.dataOwnerId;+ // Main briefly projects signed-out while an owner transition is pending.+ // It keeps the old owner generation, so retain the authoritative owner+ // refs until the commit or rollback arrives; otherwise the rollback is+ // mistaken for a new owner and finalizes the task that should resume.+ const pendingSignedOutProjection =+ state.dataOwnerId === null+ && state.mode === 'signed-out'+ && !state.canEnterApp+ && activeDataOwnerIdRef.current !== null+ && state.ownerGeneration === activeDataOwnerGenerationRef.current;+ const ownerChanged =+ !pendingSignedOutProjection && activeDataOwnerIdRef.current !== state.dataOwnerId;// A same-owner push can arrive while an auth boundary is still waiting// for IPC. The pre-commit fence temporarily publishes null, so letting// that push use the default finalizer would stop the current owner's@@ -228,8 +239,10 @@ export function AuthProvider({sessionsStore.reset();clearWorkersCache();}- activeDataOwnerIdRef.current = state.dataOwnerId;- activeDataOwnerGenerationRef.current = state.ownerGeneration;+ if (!pendingSignedOutProjection) {+ activeDataOwnerIdRef.current = state.dataOwnerId;+ activeDataOwnerGenerationRef.current = state.ownerGeneration;+ }setDataOwnerGenerationState(state.ownerGeneration);setNewMakerDraftOwner(state.dataOwnerId);setProviderModelMemoryOwner(state.dataOwnerId);@@ -276,7 +289,7 @@ export function AuthProvider({applyIncomingUser(state.user);}} else {- activeUserIdRef.current = null;+ if (!pendingSignedOutProjection) activeUserIdRef.current = null;setUser(null);// Both signed-out and local sessions have no Cindy user. Clear any// in-progress SSO/OTP step so returning to /login always starts fresh.