Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 收口切账号时的运行任务状态 #4766
DavidShen49d45076153f
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.tsindex e5979a99f7..ef9a881b45 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts@@ -77,6 +77,7 @@ vi.mock('@/lib/makerTransport', () => ({}));import {+ cancelRemoteOptimisticSendsForDataOwnerBoundary,EMPTY_SESSION_STATE,handleStreamEvent,makerChatStore,@@ -935,6 +936,32 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {}});+ it('account teardown reuses the Stop/closed finalizer and does not revive on A→B→A', () => {+ const sid = `account-boundary-${Math.random().toString(36).slice(2, 8)}`;+ try {+ makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, true));+ applyTask(sid, { taskId: 't1', status: 'running', taskType: 'local_agent' });+ expect(makerChatStore.getSnapshot(sid).agentStatus.startedAt).toBeTruthy();++ // AuthContext invokes this synchronously when the outgoing owner enters+ // teardown; the old stamped status=closed push is no longer required.+ cancelRemoteOptimisticSendsForDataOwnerBoundary();+ let state = makerChatStore.getSnapshot(sid);+ expect(state.agentStatus.isRunning).toBe(false);+ expect(state.agentStatus.startedAt).toBeNull();+ expect(state.taskUpdates?.get('t1')?.status).toBe('stopped');++ // Re-entering account A must observe the stopped snapshot, with no+ // automatic continuation caused by the boundary cleanup.+ cancelRemoteOptimisticSendsForDataOwnerBoundary();+ state = makerChatStore.getSnapshot(sid);+ expect(state.agentStatus.isRunning).toBe(false);+ expect(state.agentStatus.startedAt).toBeNull();+ } finally {+ makerChatStore.purgeSession(sid);+ }+ });+it('session closed 兜底(finalizeStuckRemoteTurn → forceFinalize):running 任务全收口、桥接清零', () => {const sid = `remote-closed-${Math.random().toString(36).slice(2, 8)}`;try {diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 8bf544ca8f..3584098720 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -2021,6 +2021,11 @@ function clearRemoteOptimisticSendsForSession(sessionId: string): void {*/export function cancelRemoteOptimisticSendsForDataOwnerBoundary(): void {invalidateLiveIngressForDataOwnerBoundary();+ // Account teardown intentionally stops the outgoing runtime. Its closed+ // status push carries the old owner stamp and is therefore dropped by the+ // owner fence; apply the same finalization used by the Stop/closed path+ // synchronously before publishing the next owner.+ finalizeSessionsForDataOwnerBoundary();// Invalidate standalone projection reads/operations before restoring drafts// or publishing the next owner. Their promises may settle independently of// the optimistic outbox and must not write old-owner state into the new slice.@@ -2114,6 +2119,48 @@ export function cancelRemoteOptimisticSendsForDataOwnerBoundary(): void {}}+/**+ * Finalize every cached session when its data owner is being torn down.+ * This is the owner-boundary equivalent of accepting `status=closed`: keep+ * the session history in memory, but stop the turn clock, streaming flags,+ * interactions, and running background tasks so a later owner re-entry+ * cannot revive the outgoing task snapshot.+ */+function finalizeSessionsForDataOwnerBoundary(): void {+ for (const sessionId of sessions.keys()) {+ const state = sessions.get(sessionId);+ if (!state || !hasActiveTurnStateForOwnerBoundary(state)) continue;+ bumpInteractionReconcileEpoch(sessionId);+ supersedeInputProjectionRequests(sessionId, { supersedeOperations: true });+ flushPendingTextDelta(sessionId);+ setState(sessionId, forceFinalizeOnSessionClosed);+ }+}++function hasActiveTurnStateForOwnerBoundary(state: SessionChatState): boolean {+ return (+ state.agentStatus.isRunning ||+ state.agentStatus.startedAt !== null ||+ state.streamingClientId !== null ||+ state.isStreaming ||+ state.messages.some((message) => message.isStreaming) ||+ state.pendingPermission !== null ||+ state.pendingAskUser !== null ||+ state.pendingPluginSetup !== null ||+ state.pendingPluginSetupQueue.length > 0 ||+ state.pendingPlanReview !== null ||+ state.pendingIssueConfirm !== null ||+ state.pendingRenameSessionsConfirm !== null ||+ state.pendingGhostGrantConfirm !== null ||+ state.pendingRemoteDesktopConfirmation !== null ||+ state.pendingRemoteDesktopConfirmationQueue.length > 0 ||+ state.queueAbortPending ||+ state.continuationTurnClientId !== null ||+ state.pendingTaskWake > 0 ||+ [...(state.taskUpdates?.values() ?? [])].some((task) => task.status === 'running')+ );+}+/** Clear deferred live ingress work before AuthContext publishes a new owner. */export function invalidateLiveIngressForDataOwnerBoundary(): void {clearTextDeltaFlushTimer();