Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(scheduler): release recovery after automatic resume fails
xd-bobo85a1c247a9c4
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 0231193068..a62c465eb3 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@@ -12319,6 +12319,117 @@ describe('AgentInputCoordinator 中断自动续跑', () => {expect(h.onAutomaticEnqueue).not.toHaveBeenCalled();});+ it.each([true, false])('scheduler 放弃自动恢复后释放后续轮次,旧 done 已到达=%s', async (doneFirst) => {+ vi.useFakeTimers();+ const h = createHarness();+ const sid = 'abandoned-scheduler-recovery';+ const origin = { kind: 'scheduler', scheduleId: 'sch-1', scheduleName: '巡检', runId: 'run-1' } as const;+ h.setResumableTurnErrorTakeover(TAKEOVER_INFO);+ await failAfterDispatch(h, sid, makeItem('failed', 'failed heartbeat', { origin }));+ h.coordinator.enqueue(sid, makeItem('next', 'next heartbeat', {+ origin: { ...origin, runId: 'run-2' },+ }));+ await flush();+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);+ expect(h.coordinator.isAutoResumePending(sid)).toBe(true);+ if (doneFirst) h.coordinator.onTurnEvent(sid, 'done');++ h.coordinator.abandonAutoResume(sid, truncationMessage, TAKEOVER_INFO.sessionTotal);++ expect(h.coordinator.getProjection(sid)).toMatchObject({ error: truncationMessage, recovery: null });+ expect(h.coordinator.isAutoResumePending(sid)).toBe(false);+ expect(h.coordinator.hasQueuedItemWhere(sid, item => item.clientId === 'failed', {+ includeRecovery: true,+ })).toBe(false);+ await flush();+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);+ if (doneFirst) {+ // done 已被 recovery 消费,沿用终态配对的有界兜底,不等用户点重试。+ await vi.advanceTimersByTimeAsync(250);+ } else {+ h.coordinator.onTurnEvent(sid, 'done');+ expect(h.coordinator.getProjection(sid).error).toBe(truncationMessage);+ }+ await flush();+ expect(h.sendToAgent).toHaveBeenCalledTimes(2);+ expect(h.sendToAgent.mock.calls[1]?.[1]).toEqual({ type: 'user', content: 'next heartbeat' });+ expect(h.sendToAgent.mock.calls[1]?.[3]?.origin).toEqual({ ...origin, runId: 'run-2' });+ expect(h.onUiRetry).not.toHaveBeenCalled();+ });++ it('scheduler 自动恢复失败且没有排队项时,下一次触发不再被判忙', async () => {+ vi.useFakeTimers();+ const h = createHarness();+ const sid = 'scheduler-next-fire';+ const origin = { kind: 'scheduler', scheduleId: 'sch-1', scheduleName: '巡检', runId: 'run-1' } as const;+ await h.coordinator.ensureQueueRestored(sid);+ h.setResumableTurnErrorTakeover(TAKEOVER_INFO);+ await failAfterDispatch(h, sid, makeItem('failed', 'failed heartbeat', { origin }));+ h.coordinator.onTurnEvent(sid, 'done');+ h.coordinator.abandonAutoResume(sid, truncationMessage, TAKEOVER_INFO.sessionTotal);+ await vi.advanceTimersByTimeAsync(250);++ expect(h.coordinator.shouldQueueNewTurn(sid)).toBe(false);+ expect(h.coordinator.getProjection(sid).error).toBe(truncationMessage);+ h.coordinator.enqueue(sid, makeItem('next', 'next hourly run', {+ origin: { ...origin, runId: 'run-2' },+ }));+ await flush();+ expect(h.sendToAgent).toHaveBeenCalledTimes(2);+ expect(h.sendToAgent.mock.calls[1]?.[1]).toEqual({ type: 'user', content: 'next hourly run' });+ });++ it.each(['pause', 'interaction', 'running'] as const)(+ 'scheduler 恢复收尾不越过 %s 阻塞', async (gate) => {+ vi.useFakeTimers();+ const h = createHarness();+ const sid = 'scheduler-recovery-gate';+ const origin = { kind: 'scheduler', scheduleId: 'sch-1', scheduleName: '巡检', runId: 'run-1' } as const;+ h.setResumableTurnErrorTakeover(TAKEOVER_INFO);+ await failAfterDispatch(h, sid, makeItem('failed', 'failed heartbeat', { origin }));+ h.coordinator.onTurnEvent(sid, 'done');+ if (gate === 'pause') h.coordinator.setExecutionPaused(sid, true);+ if (gate === 'interaction') h.coordinator.setInteractionLock(sid, 'approval', true);+ if (gate === 'running') h.setRunning(true);+ h.coordinator.enqueue(sid, makeItem('next', 'next heartbeat', {+ origin: { ...origin, runId: 'run-2' },+ }));+ h.coordinator.abandonAutoResume(sid, truncationMessage, TAKEOVER_INFO.sessionTotal);+ await vi.advanceTimersByTimeAsync(1_000);++ expect(h.coordinator.getProjection(sid).recovery).toBeNull();+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);+ expect(h.coordinator.getProjection(sid).pendingQueue.map(item => item.clientId)).toEqual(['next']);+ if (gate === 'pause') h.coordinator.setExecutionPaused(sid, false);+ if (gate === 'interaction') h.coordinator.setInteractionLock(sid, 'approval', false);+ if (gate === 'running') {+ h.setRunning(false);+ h.coordinator.onTurnEvent(sid, 'done');+ }+ await flush();+ expect(h.sendToAgent).toHaveBeenCalledTimes(2);+ },+ );++ it('旧 attempt 放弃回调不能清掉新 scheduler 恢复状态', async () => {+ const h = createHarness();+ const sid = 'scheduler-recovery-owner';+ h.setResumableTurnErrorTakeover({ ...TAKEOVER_INFO, sessionTotal: 2 });+ const item = makeItem('new-failure', 'new heartbeat', {+ origin: { kind: 'scheduler', scheduleId: 'sch-1', scheduleName: '巡检', runId: 'run-2' },+ });+ await failAfterDispatch(h, sid, item);++ h.coordinator.abandonAutoResume(sid, 'old failure', 1);+ await flush();+ expect(h.coordinator.getProjection(sid)).toMatchObject({+ error: null,+ recovery: { kind: 'active-turn', item: { clientId: item.clientId } },+ autoResumePending: { sessionTotal: 2 },+ });+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);+ });+it('用户接管会撤销已经离队但尚未派发的 scheduler 自动续跑', async () => {const h = createHarness();const sid = 'cancel-pre-vendor-scheduler-auto-resume';diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex ba5fee2b72..ef58c8a226 100644--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@ -6784,6 +6784,22 @@ export class AgentInputCoordinator {state.error = message ?? null;clearErrorProjectionSignals(state);}+ if (+ state.activeTurn === null &&+ state.recovery?.kind === 'active-turn' &&+ isSchedulerOriginItem(state.recovery.item)+ ) {+ // Scheduler recovery only belongs to the live auto-resume attempt. Once+ // that attempt ends, the runner settles the failed run; keeping Retry+ // here would block every later fire (and replay outside run accounting).+ this.setActiveTurnRecovery(state, state.recovery.item);+ // Reuse normal scheduler failure settlement, including its bounded wait+ // for a paired done, so an old terminal cannot clear the next turn.+ this.markPendingExternalTerminalDone(sessionId, state);+ this.emit(sessionId);+ this.scheduleDrainAfterExternalTurnSettles(sessionId, 'scheduler-auto-resume-abandoned');+ return;+ }// cancelPreparedAutoResume 已为队列 / active 变化 emit;纯退避态仍需// 单独投影接管结束。没有任何接管状态时保持既有 no-op 语义。if (!cancelledPrepared && (hadPendingTakeover || surfacedMessage)) this.emit(sessionId);diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex 3e349caf22..15f8c645b8 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -152,6 +152,10 @@ harness + provider + model + effort + fastMode不覆盖用户的新选择。实现与回归见 `maker-ipc/botCandidateRecovery.ts`、`maker-ipc/__tests__/botCandidateRecovery.test.ts` 和 `sessionRuntimeFallbackIntent.test.ts`。跨 harness 路由已提交但新引擎启动失败时停止自动恢复并显示错误;不使用提交前的路由代次继续推进候选。+- 定时自动化的恢复只属于当前运行轮次;候选耗尽或自动恢复放弃后,该轮按失败收口并保留错误记录,+ 同时释放临时重试状态,后续已排队或到期的轮次沿用原调度继续执行,不自动重放失败轮次。+ 用户消息的手动重试、显式暂停、交互等待和仍在运行的执行边界不受影响。实现与回归见+ `maker-ipc/agent-input-coordinator.ts` 的 `abandonAutoResume` 和同目录 `__tests__/agent-input-coordinator.test.ts`。- 用户拒绝授权、工具业务失败、参数错误和已经产生副作用后的失败不得触发透明重放。- 同一轮最多按生效候选链各尝试一次;不得循环。用户显式配置的链不得追加目录候选。- 同 harness 可在安全边界切模型;跨 harness 必须走既有 agent-switch / 交接重建事务。