Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): recheck idle sessions during rollback
DavidShena84d4d01adc2
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.tsindex 5397fbdfb6..47a5b4cbf7 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts@@ -1400,6 +1400,37 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {}});+ it('rechecks Main when the first snapshot is idle', async () => {+ const sid = 'rollback-idle-replaced-' + 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));+ let listActiveCalls = 0;+ const listActive = vi.fn(() => {+ listActiveCalls += 1;+ return listActiveCalls === 1+ ? Promise.resolve([{ sessionId: sid, agentKind: 'codex', isTurnRunning: false }])+ : Promise.resolve([{ sessionId: sid, agentKind: 'codex', isTurnRunning: true }]);+ });+ globalWindow.window = {+ electronAPI: { maker: { listActive } },+ } as typeof globalWindow.window;++ await reconcileSessionsAfterDataOwnerRollback();++ expect(listActive).toHaveBeenCalledTimes(2);+ expect(makerChatStore.getSnapshot(sid).agentStatus.isRunning).toBe(true);+ } finally {+ makerChatStore.purgeSession(sid);+ dataOwnerGenerationTesting.reset();+ globalWindow.window = previousWindow;+ }+ });+it('preserves idle background work found by the second Main reconciliation read', async () => {const sid = 'rollback-second-read-idle-' + Math.random().toString(36).slice(2, 8);const globalWindow = globalThis as typeof globalThis & {diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex fc60b19981..d16c88ad1c 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -9930,13 +9930,19 @@ 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);- let mainTurnRunning = liveTurns.get(id);- if (mainTurnRunning === true || !current || !sameActiveTurnBoundaryMarker(id, current, marker))+ const initialMainTurnRunning = liveTurns.get(id);+ if (+ initialMainTurnRunning === true ||+ !current ||+ !sameActiveTurnBoundaryMarker(id, current, marker)+ )continue;+ let mainTurnRunning: boolean | undefined = initialMainTurnRunning;// The first query can legitimately race a replacement turn created by- // another renderer. Re-read an absent handle immediately before- // finalization so a stale absence cannot close that new turn.- if (mainTurnRunning === undefined) {+ // another renderer. Re-read every non-running snapshot immediately+ // before finalization so a stale idle/absence result cannot close that+ // new turn.+ if (initialMainTurnRunning === false || initialMainTurnRunning === undefined) {const latest = await listActive();if (getDataOwnerGeneration() !== owner) return;if (!Array.isArray(latest) || !latest.every(isActiveSessionSnapshot)) return;@@ -9944,7 +9950,7 @@ export async function reconcileSessionsAfterDataOwnerRollback(): Promise<void> {if (latestSession) {mainTurnRunning = latestSession.isTurnRunning;}- if (mainTurnRunning === true) {+ if (latestSession?.isTurnRunning === true) {continue;}}