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): preserve background tasks during owner rollback

DavidShene81342fcb37c
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
index 90561d1fe8..7d23016f77 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
@@ -1116,4 +1116,38 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
makerChatStore.purgeSession(sid);
}
});
+
+ it('rollback reconciliation preserves local wake work on an idle Main session', async () => {
+ const sid = 'rollback-idle-wake-' + Math.random().toString(36).slice(2, 8);
+ const globalWindow = globalThis as typeof globalThis & {
+ window?: { electronAPI?: unknown };
+ };
+ const previousWindow = globalWindow.window;
+ try {
+ setDataOwnerGeneration('account-a', 1);
+ makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, true));
+ applyTask(sid, { taskId: 'wake-1', status: 'running', taskType: 'local_agent' });
+ makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, false));
+ expect(makerChatStore.getSnapshot(sid).agentStatus.isRunning).toBe(false);
+
+ globalWindow.window = {
+ electronAPI: {
+ maker: {
+ listActive: vi.fn(async () => [
+ { sessionId: sid, agentKind: 'codex', isTurnRunning: false },
+ ]),
+ },
+ },
+ } as typeof globalWindow.window;
+
+ await reconcileSessionsAfterDataOwnerRollback();
+ const state = makerChatStore.getSnapshot(sid);
+ expect(state.agentStatus.isRunning).toBe(false);
+ expect(state.taskUpdates?.get('wake-1')?.status).toBe('running');
+ } finally {
+ makerChatStore.purgeSession(sid);
+ dataOwnerGenerationTesting.reset();
+ globalWindow.window = previousWindow;
+ }
+ });
});
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 78ac950a7c..ff77aa3268 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -9845,11 +9845,14 @@ export async function reconcileSessionsAfterDataOwnerRollback(): Promise<void> {
// A live-but-idle handle has already stopped its turn and must take the
// same finalizer path.
const current = sessions.get(id);
- if (
- liveTurns.get(id) === true ||
- !current ||
- !sameActiveTurnBoundaryMarker(current, marker)
- ) continue;
+ const mainTurnRunning = liveTurns.get(id);
+ if (mainTurnRunning === true || !current || !sameActiveTurnBoundaryMarker(current, marker))
+ continue;
+ // listActive keeps idle session handles that still own local wake work.
+ // isTurnRunning=false only says the foreground turn ended; do not
+ // close a live local_agent/local_workflow task while rolling back a
+ // rejected owner transition.
+ if (mainTurnRunning === false && hasBackgroundAgentWork(id, current)) continue;
bumpInteractionReconcileEpoch(id);
supersedeInputProjectionRequests(id, { supersedeOperations: true });
flushPendingTextDelta(id);