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(desktop): reconcile rollback across renderers

DavidShen77ae999dd7bf
diff --git a/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx b/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx
index 1b88f4bd51..f1ccdafdb0 100644
--- a/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx
@@ -380,13 +380,13 @@ describe('AuthContext session cache boundaries', () => {
expect(mocks.cancelRemoteOptimisticSendsForDataOwnerBoundary).toHaveBeenLastCalledWith({
finalizeSessions: false,
});
- expect(mocks.reconcileSessionsAfterDataOwnerRollback).not.toHaveBeenCalled();
+ expect(mocks.reconcileSessionsAfterDataOwnerRollback).toHaveBeenCalledTimes(1);
await act(async () => {
rejectLogout(new Error('logout failed'));
await expect(logout).rejects.toThrow('logout failed');
});
- expect(mocks.reconcileSessionsAfterDataOwnerRollback).toHaveBeenCalledTimes(1);
+ expect(mocks.reconcileSessionsAfterDataOwnerRollback).toHaveBeenCalledTimes(2);
expect(getDataOwnerGeneration().dataOwnerId).toBe('account-a');
});
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
index 9d22184416..99ea835817 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
@@ -983,6 +983,7 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
it('rollback reconciliation finalizes only sessions absent from Main after teardown', async () => {
const sid = 'rollback-reconcile-' + Math.random().toString(36).slice(2, 8);
+ const remoteSid = 'remote-rollback-reconcile-' + Math.random().toString(36).slice(2, 8);
const globalWindow = globalThis as typeof globalThis & {
window?: { electronAPI?: unknown };
};
@@ -992,6 +993,8 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
setDataOwnerGeneration('account-a', 1);
makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, true));
applyTask(sid, { taskId: 't1', status: 'running', taskType: 'local_agent' });
+ makerChatStore.__applyStatusUpdateForTest(remoteSid, statusUpdate(remoteSid, true));
+ applyTask(remoteSid, { taskId: 'remote-t1', status: 'running', taskType: 'local_agent' });
globalWindow.window = {
electronAPI: { maker: { listActive: vi.fn(async () => []) } },
} as typeof globalWindow.window;
@@ -999,8 +1002,10 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
await reconcileSessionsAfterDataOwnerRollback();
expect(makerChatStore.getSnapshot(sid).agentStatus.isRunning).toBe(false);
expect(makerChatStore.getSnapshot(sid).taskUpdates?.get('t1')?.status).toBe('stopped');
+ expect(makerChatStore.getSnapshot(remoteSid).agentStatus.isRunning).toBe(true);
} finally {
makerChatStore.purgeSession(sid);
+ makerChatStore.purgeSession(remoteSid);
dataOwnerGenerationTesting.reset();
globalWindow.window = previousWindow;
}
diff --git a/apps/desktop/src/renderer/contexts/AuthContext.tsx b/apps/desktop/src/renderer/contexts/AuthContext.tsx
index d48f65fa2a..4b0b2f08cb 100644
--- a/apps/desktop/src/renderer/contexts/AuthContext.tsx
+++ b/apps/desktop/src/renderer/contexts/AuthContext.tsx
@@ -243,6 +243,8 @@ export function AuthProvider({
const initialOwnerHydration = !hasAppliedAuthStateRef.current && !pendingSignedOutProjection;
const ownerChanged =
!pendingSignedOutProjection && activeDataOwnerIdRef.current !== state.dataOwnerId;
+ const ownerRollbackProjection =
+ pendingOwnerProjectionRef.current && !pendingSignedOutProjection && !ownerChanged;
if (pendingSignedOutProjection) pendingOwnerProjectionRef.current = true;
// A same-owner push can arrive while an auth boundary is still waiting
// for IPC. The pre-commit fence temporarily publishes null, so letting
@@ -259,6 +261,10 @@ export function AuthProvider({
sessionsStore.reset();
clearWorkersCache();
}
+ // Any renderer may receive the rollback projection before the initiating
+ // IPC promise rejects. Reconcile without consuming the operation marker;
+ // listActive keeps a still-running old-owner turn resumable.
+ if (ownerRollbackProjection) void reconcileSessionsAfterDataOwnerRollback();
if (!pendingSignedOutProjection) {
activeDataOwnerIdRef.current = state.dataOwnerId;
activeDataOwnerGenerationRef.current = state.ownerGeneration;
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 583716c9c5..7056a483f0 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -9792,7 +9792,7 @@ export async function reconcileSessionsAfterDataOwnerRollback(): Promise<void> {
const owner = getDataOwnerGeneration();
if (owner.dataOwnerId === null) return;
const candidates = [...sessions].filter(([id, state]) =>
- !isRemoteSession(id) && hasActiveTurnStateForOwnerBoundary(state),
+ !isRemoteSessionSticky(id) && hasActiveTurnStateForOwnerBoundary(state),
);
if (candidates.length === 0) return;
try {