Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(agent): 重启恢复统一移除旧定时运行归属
Dash2e51cdce98ca
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.tsindex e525d4598a..5a6a594ae1 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts@@ -14241,25 +14241,55 @@ describe('AgentInputCoordinator 中断自动续跑', () => {});describe('usage-limit wait (ordinary tasks)', () => {- it('restores a scheduled quota failure after restart without replaying the dead run context', async () => {+ // Standard regression: both recovery shapes must shed the dead FireContext before+ // auto/manual/cancelled-wait dispatch, or a later ordinary error loses manual Retry.+ it.each(+ (['active-turn', 'queue-head'] as const).flatMap(kind =>+ (['auto', 'manual', 'cancel'] as const).map(action => ({ kind, action }))),+ )('restores scheduled $kind quota recovery via $action without replaying the dead run context', async ({ kind, action }) => {const original = createHarness(); const sid = 'restarted-quota';+ if (kind === 'queue-head') {+ original.sendToAgent.mockRejectedValueOnce(new ProviderGroupUsageLimitError({ resetAtMs: 5_000_000 }));+ }original.coordinator.enqueue(sid, makeItem('input', 'work', {origin: { kind: 'scheduler', scheduleId: 'sch', scheduleName: 'Check', runId: 'old-run' },}));await flush(); original.setRunning(false);- original.coordinator.onTurnEvent(sid, 'error', 'weekly limit', LIMIT_SIGNALS);+ if (kind === 'active-turn') original.coordinator.onTurnEvent(sid, 'error', 'weekly limit', LIMIT_SIGNALS);const token = original.onUsageLimitedTurnError.mock.calls.at(-1)?.[3] as number;const snapshot = original.coordinator.snapshotUsageLimitRecovery(sid, token)!;+ expect(snapshot.kind).toBe(kind);const restarted = createHarness();restarted.setHasAssistantProgressAfter(async () => true);+ // Also cover restoration when the same queued input is already in memory.+ if (kind === 'queue-head' && action === 'cancel') {+ restarted.coordinator.setInteractionLock(sid, 'restore-test', true);+ restarted.coordinator.enqueue(sid, snapshot.item);+ await flush();+ }const restored = restarted.coordinator.restoreUsageLimitRecovery(sid, snapshot, restarted.coordinator.getGeneration(sid))!;- expect(restarted.coordinator.getProjection(sid).error).toBe('weekly limit');+ restarted.coordinator.setInteractionLock(sid, 'restore-test', false);+ // The saved record still owns schedule deduplication until it is consumed.+ expect(snapshot.item.origin).toMatchObject({ runId: 'old-run' });+ expect(restarted.coordinator.getProjection(sid).error).toBe(snapshot.error);expect(restarted.coordinator.armUsageLimitWait(sid, restored, 9_000_000)).toBe(true);- await restarted.coordinator.continueAfterUsageLimitReset(sid, restored, INFO); await flush();+ if (action === 'auto') await restarted.coordinator.continueAfterUsageLimitReset(sid, restored, INFO);+ else {+ if (action === 'cancel') restarted.coordinator.cancelUsageLimitWait(sid, restored);+ await restarted.coordinator.retryLastError(sid);+ }+ await flush();expect(restarted.sendToAgent).toHaveBeenCalledOnce();- expect(restarted.sendToAgent.mock.calls[0][1]).toMatchObject({ content: CONTINUE_AFTER_ERROR_PROMPT });- expect(restarted.sendToAgent.mock.calls[0][3].origin).toBeUndefined();+ expect(restarted.sendToAgent.mock.calls[0][1]).toMatchObject({ content: kind === 'active-turn' ? CONTINUE_AFTER_ERROR_PROMPT : 'work' });expect(await restarted.coordinator.continueAfterUsageLimitReset(sid, restored, INFO)).toBe('superseded');+ restarted.setRunning(false);+ restarted.coordinator.onTurnEvent(sid, 'error', 'ordinary failure', { sdkError: 'authentication_failed' });+ restarted.coordinator.onTurnEvent(sid, 'done');+ await flush();+ expect(restarted.coordinator.getProjection(sid).recovery?.kind).toBe('active-turn');+ await restarted.coordinator.retryLastError(sid); await flush();+ expect(restarted.sendToAgent).toHaveBeenCalledTimes(2);+ expect(restarted.sendToAgent.mock.calls[0][3].origin).toBeUndefined();});it('does not restore across clear, and unloads runtime waiting for a later owner activation', async () => {diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex 6c05001b67..fb48e33fc0 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -3403,7 +3403,7 @@ export class AgentInputCoordinator {}// Manual retry is a user takeover. The old scheduler waiter settles as// failed; its FireContext must not be inherited by the user's new turn.- if ((!automatic || this.restoredUsageLimitRecoveries.has(recovery)) && isSchedulerOriginItem(item)) item.origin = undefined;+ if (!automatic && isSchedulerOriginItem(item)) item.origin = undefined;if (usageWait && state.queuePausedByRestore) this.restoredUsageLimitRetryItems.add(item);state.pendingQueue.unshift(item);this.prependPendingCompactWaitClientId(state, item.clientId);@@ -6912,9 +6912,15 @@ export class AgentInputCoordinator {const state = this.getState(sessionId);if (state.generation !== generation || state.activeTurn || state.recovery || state.error || this.isExecutionPaused(sessionId) ||state.pendingQueue.some(item => item.clientId !== snapshot.item.clientId)) return null;- const item = sanitizeQueuedMessageForPersistence(snapshot.item);+ const queued = snapshot.kind === 'queue-head'+ ? state.pendingQueue.find(item => item.clientId === snapshot.item.clientId) : undefined;+ const item = { ...sanitizeQueuedMessageForPersistence(queued ?? snapshot.item) };+ // Restore task input, never the expired scheduler run. Do this once for both+ // recovery shapes, including a matching queue item already restored in memory.+ if (isSchedulerOriginItem(item)) item.origin = undefined;if (snapshot.kind === 'queue-head') {- if (!state.pendingQueue.some(queued => queued.clientId === item.clientId)) state.pendingQueue.unshift(item);+ if (queued) state.pendingQueue[state.pendingQueue.indexOf(queued)] = item;+ else state.pendingQueue.unshift(item);state.recovery = { kind: 'queue-head', clientId: item.clientId };} else state.recovery = { kind: 'active-turn', item };state.error = snapshot.error;@@ -6943,9 +6949,6 @@ export class AgentInputCoordinator {const state = this.getState(sessionId);if (state.usageLimitWait && (token === undefined || state.usageLimitWait.token === token)) {state.usageLimitWait = null;- if (state.recovery?.kind === 'active-turn' && this.restoredUsageLimitRecoveries.has(state.recovery)) {- state.recovery = { ...state.recovery, item: { ...state.recovery.item, origin: undefined } };- }this.emit(sessionId);}return this.getProjection(sessionId);