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): 继续暂停队列时解锁队首恢复

Pelican0126886d1b4c6795
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.ts
index fdbcc6c2be..712f10bc88 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
@@ -4410,6 +4410,61 @@ describe('AgentInputCoordinator stop and drain boundaries', () => {
expect(h.abortSession).not.toHaveBeenCalled();
});
+ it('resumes a paused queue-head recovery from the original head without reordering the tail', async () => {
+ const h = createHarness();
+ const sid = 'resume-paused-queue-head-recovery';
+ const first = makeItem('q-1', 'first');
+ const second = makeItem('q-2', 'second', {
+ origin: { kind: 'orca', senderLabel: 'worker-1' },
+ });
+
+ h.sendToAgent.mockResolvedValueOnce(hostSendFailure('SEND_FAILED', 'boom'));
+ h.coordinator.enqueue(sid, first);
+ await flush();
+
+ h.coordinator.enqueue(sid, second);
+ await flush();
+
+ // A mechanical duplicate resume must not retry an unpaused recovery. Only
+ // the visible paused-queue Continue action owns the recovery transition.
+ h.coordinator.resume(sid);
+ await flush();
+ let projection = latestProjection(h.projections);
+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);
+ expect(projection.recovery).toEqual({ kind: 'queue-head', clientId: 'q-1' });
+
+ projection = h.coordinator.pausePendingQueueForRewind(sid);
+ expect(projection).toMatchObject({
+ queuePaused: true,
+ recovery: { kind: 'queue-head', clientId: 'q-1' },
+ });
+ expect(projection.pendingQueue.map((item) => item.clientId)).toEqual(['q-1', 'q-2']);
+
+ // A stale recovery must never retry through a different queue head.
+ h.coordinator.move(sid, 'q-2', 0);
+ h.coordinator.resume(sid);
+ await flush();
+ projection = latestProjection(h.projections);
+ expect(h.sendToAgent).toHaveBeenCalledTimes(1);
+ expect(projection.recovery).toEqual({ kind: 'queue-head', clientId: 'q-1' });
+ expect(projection.pendingQueue.map((item) => item.clientId)).toEqual(['q-2', 'q-1']);
+
+ h.coordinator.move(sid, 'q-1', 0);
+ projection = h.coordinator.pausePendingQueueForRewind(sid);
+ expect(projection.pendingQueue.map((item) => item.clientId)).toEqual(['q-1', 'q-2']);
+
+ h.sendToAgent.mockResolvedValueOnce(sendSuccess());
+ h.coordinator.resume(sid);
+ await flush();
+
+ projection = latestProjection(h.projections);
+ expect(h.sendToAgent).toHaveBeenCalledTimes(2);
+ expect(h.sendToAgent.mock.calls[1]?.[1]).toEqual({ type: 'user', content: 'first' });
+ expect(projection.recovery).toBeNull();
+ expect(projection.error).toBeNull();
+ expect(projection.pendingQueue.map((item) => item.clientId)).toEqual(['q-2']);
+ });
+
it('keeps the queue paused after Stop and drains after Continue plus Claude abort boundary', async () => {
const h = createHarness();
const sid = 'stop-claude';
diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
index c64e66069e..6eaa1bcc27 100644
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@ -1373,8 +1373,8 @@ export class AgentInputCoordinator {
// - UI 续跑(「继续」按钮,sendUiTrigger):等价 retryLastError——清 recovery
// 重发队首 A(原样重发是既有 retryLastError 对 queue-head 的语义),合成
// continue 项不入队,避免 A 与 continue 双发。
- // 自动来源(scheduler / orca)与 resume(继续队列)维持既有「不清」语义:
- // 自动化项不代表用户表态,resume 是机械放行,显式点重试/删除仍是唯一出路。
+ // 自动来源(scheduler / orca)不代表用户表态,维持「不清」语义。暂停队列的
+ // Continue 则由 resume 原子清除与当前队首匹配的 recovery 后重发原消息。
if (state.recovery?.kind === 'queue-head' && !automaticOrigin) {
const abandonedClientId = state.recovery.clientId;
if (isUiContinuationItem(item)) {
@@ -2099,9 +2099,26 @@ export class AgentInputCoordinator {
resume(sessionId: string): AgentInputProjection {
const state = this.getState(sessionId);
+ const recovery = state.recovery;
+ const pausedQueueHeadRecoveryClientId =
+ state.queuePaused &&
+ recovery?.kind === 'queue-head' &&
+ state.pendingQueue[0]?.clientId === recovery.clientId
+ ? recovery.clientId
+ : null;
state.queuePaused = false;
state.queuePausedByRestore = false;
- this.clearErrorUnlessQueueHeadBlocked(state);
+ if (pausedQueueHeadRecoveryClientId !== null) {
+ state.error = null;
+ state.stickyError = null;
+ state.recovery = null;
+ log.info('paused queue resume resets queue-head recovery', {
+ sessionId,
+ clientId: pausedQueueHeadRecoveryClientId,
+ });
+ } else {
+ this.clearErrorUnlessQueueHeadBlocked(state);
+ }
this.emit(sessionId);
this.scheduleDrain(sessionId, 'resume');
this.scheduleExternalTurnRetryIfNeeded(sessionId, state, 'resume');