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 all background tasks on rollback

DavidShend2e14111e849
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
index 7d23016f77..2963a213b0 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts
@@ -1150,4 +1150,35 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {
globalWindow.window = previousWindow;
}
});
+
+ it('rollback reconciliation preserves non-wake background work on an idle Main session', async () => {
+ const sid = 'rollback-idle-bash-' + 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: 'bash-1', status: 'running', taskType: 'local_bash' });
+ makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, false));
+
+ globalWindow.window = {
+ electronAPI: {
+ maker: {
+ listActive: vi.fn(async () => [
+ { sessionId: sid, agentKind: 'codex', isTurnRunning: false },
+ ]),
+ },
+ },
+ } as typeof globalWindow.window;
+
+ await reconcileSessionsAfterDataOwnerRollback();
+ expect(makerChatStore.getSnapshot(sid).taskUpdates?.get('bash-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 ff77aa3268..23f9b4ce47 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -5211,6 +5211,17 @@ function hasBackgroundAgentWork(sessionId: string, state: SessionChatState): boo
return !isRemoteSessionSticky(sessionId) && !state.remoteHostId;
}
+/**
+ * Any task that is still live while Main retains the session handle must
+ * survive a rejected owner transition. This is deliberately broader than
+ * hasBackgroundAgentWork: local_bash and other non-wake tasks do not keep the
+ * foreground turn running, but stopping their renderer projection during a
+ * rollback would still hide work that Main never stopped.
+ */
+function hasRunningBackgroundTask(state: SessionChatState): boolean {
+ return [...(state.taskUpdates?.values() ?? [])].some((task) => task.status === 'running');
+}
+
/**
* 把 taskUpdates 里 running 任务标为 stopped。
* - scope='all'(session closed 兜底):事件流已断,所有 provider / 类型的
@@ -9848,11 +9859,11 @@ export async function reconcileSessionsAfterDataOwnerRollback(): Promise<void> {
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;
+ // listActive keeps idle session handles that still own background work.
+ // isTurnRunning=false only says the foreground turn ended; do not close
+ // any task Main may still be running while rolling back a rejected owner
+ // transition (wake and non-wake tasks alike).
+ if (mainTurnRunning === false && hasRunningBackgroundTask(current)) continue;
bumpInteractionReconcileEpoch(id);
supersedeInputProjectionRequests(id, { supersedeOperations: true });
flushPendingTextDelta(id);