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: 重试和继续任务时保留排序时间

Cindye344af865a2f
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 459939145b..12748109d9 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
@@ -4695,11 +4695,15 @@ describe('AgentInputCoordinator send transaction', () => {
await flush();
expect(h.onUserEnqueue).not.toHaveBeenCalled();
expect(h.onUiRetry).toHaveBeenCalledWith(sid, 'q-continue', 'manual');
+ // 排序回归:恢复已有消息保留发送时间,但仍通知真人接手(unit)。
+ expect(mocks.touchUserSendInDb).not.toHaveBeenCalled();
+ expect(h.onUserAction).toHaveBeenCalledWith(sid);
// 普通消息照常上报。
h.coordinator.enqueue(sid, makeItem('q-normal', '顺手问个别的'));
await flush();
expect(h.onUserEnqueue).toHaveBeenCalledWith(sid);
+ expect(mocks.touchUserSendInDb).toHaveBeenCalledOnce();
});
it('previews a user enqueue to Agent Island before sendToAgent starts', async () => {
@@ -4842,6 +4846,8 @@ describe('AgentInputCoordinator send transaction', () => {
// queue-head 从不发 onUiRetry(与 retryLastError 语义一致)。
expect(h.onUiRetry).not.toHaveBeenCalled();
expect(h.previewQueuedUserTurn).not.toHaveBeenCalled();
+ expect(mocks.touchUserSendInDb).toHaveBeenCalledTimes(1);
+ expect(h.onUserAction).toHaveBeenCalledTimes(2);
});
it('queue-head retry never substitutes the continue prompt and redrains the original head', async () => {
@@ -4863,6 +4869,8 @@ describe('AgentInputCoordinator send transaction', () => {
// 队首消息从未送达 agent,续跑语义不成立 —— 必须原样重发。
expect(h.sendToAgent).toHaveBeenCalledTimes(2);
expect(h.sendToAgent.mock.calls[1]?.[1]).toEqual({ type: 'user', content: 'never dispatched' });
+ expect(mocks.touchUserSendInDb).toHaveBeenCalledTimes(1);
+ expect(h.onUserAction).toHaveBeenCalledTimes(2);
});
it('enqueue after a terminal error abandons the active-turn retry and dispatches the new message', async () => {
@@ -6610,8 +6618,8 @@ describe('AgentInputCoordinator stop and drain boundaries', () => {
projection = latestProjection(h.projections);
expect(h.sendToAgent).toHaveBeenCalledTimes(2);
expect(h.sendToAgent.mock.calls[1]?.[1]).toEqual({ type: 'user', content: 'first' });
- expect(mocks.touchUserSendInDb).toHaveBeenCalledOnce();
- expect(mocks.touchUserSendInDb).toHaveBeenCalledWith(sid, undefined);
+ expect(mocks.touchUserSendInDb).not.toHaveBeenCalled();
+ expect(h.onUserAction).toHaveBeenCalledTimes(2);
expect(projection.recovery).toBeNull();
expect(projection.error).toBeNull();
expect(projection.pendingQueue.map((item) => item.clientId)).toEqual(['q-2']);
@@ -13368,10 +13376,10 @@ describe('AgentInputCoordinator 中断自动续跑', () => {
});
});
- it('人工 retryLastError 不打 autoResume(否则会误跳过额度充值)', async () => {
+ it.each([false, true])('人工 retryLastError 保留排序时间与真人接手(已有产出=%s)', async (hasProgress) => {
const h = createHarness();
const sid = 'manual-retry-no-auto-flag';
- h.setHasAssistantProgressAfter(async () => true);
+ h.setHasAssistantProgressAfter(async () => hasProgress);
await failAfterDispatch(h, sid);
await h.coordinator.retryLastError(sid);
@@ -13379,7 +13387,8 @@ describe('AgentInputCoordinator 中断自动续跑', () => {
expect(h.sendToAgent).toHaveBeenCalledTimes(2);
expect(h.sendToAgent.mock.calls[1]?.[3]?.persistUserMessage?.autoResume).toBeUndefined();
- expect(mocks.touchUserSendInDb).toHaveBeenCalledTimes(2);
+ expect(mocks.touchUserSendInDb).toHaveBeenCalledTimes(1);
+ expect(h.onUserAction).toHaveBeenCalledTimes(2);
});
it('自动续跑再次失败后,人工 Retry 会清掉上一轮隐藏标记并重置真人额度', async () => {
@@ -13411,7 +13420,8 @@ describe('AgentInputCoordinator 中断自动续跑', () => {
const persist = h.sendToAgent.mock.calls[2]?.[3]?.persistUserMessage;
expect(persist?.autoResume).toBeUndefined();
expect(persist?.autoResumeInfo).toBeUndefined();
- expect(mocks.touchUserSendInDb).toHaveBeenCalledTimes(2);
+ expect(mocks.touchUserSendInDb).toHaveBeenCalledTimes(1);
+ expect(h.onUserAction).toHaveBeenCalledTimes(2);
});
it('零产出时自动克隆重发原文,并沿用 autoResume 计数守卫', async () => {
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 439e0b1ac6..bf59b872db 100644
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@ -1972,9 +1972,8 @@ export class AgentInputCoordinator {
sessionId,
clientId: abandonedClientId,
});
- // 手动「继续」是真人介入,与 retryLastError 同口径刷新 userSendAt(否则
- // 会话活跃信号 / 列表排序不会反映这次人工动作)。
- this.touchUserSend(sessionId, opts?.sendAtMs);
+ // 继续原消息仍是真人接手,但不是新消息,不推进列表排序时间。
+ this.deps.onUserAction?.(sessionId);
this.emit(sessionId);
this.scheduleDrain(sessionId, 'ui-continue-queue-head-unlock');
return this.getProjection(sessionId);
@@ -2020,7 +2019,8 @@ export class AgentInputCoordinator {
// 而静默顺延(PR #972 review P2)。侧栏排序的 bump 语义保留在派发时刻 ——
// runner 的 accepted 回调按直发路径同款调 touchUserSendInDb(ctx.firedAt)。
if (!automaticOrigin) {
- this.touchUserSend(sessionId, opts?.sendAtMs);
+ if (isUiContinuationItem(item)) this.deps.onUserAction?.(sessionId);
+ else this.touchUserSend(sessionId, opts?.sendAtMs);
}
// 视觉连续性: 当这条入队后立即可派发(agent 空闲、队列此前为空、无暂停/锁/恢复
// 阻塞)时, 跳过中间态 emit 并同步进入 drain —— drain 的同步前半段会先把队首
@@ -3132,7 +3132,7 @@ export class AgentInputCoordinator {
sessionId,
clientId: pausedQueueHeadRecoveryClientId,
});
- this.touchUserSend(sessionId);
+ this.deps.onUserAction?.(sessionId);
} else {
this.clearErrorUnlessQueueHeadBlocked(state);
}
@@ -3177,8 +3177,8 @@ export class AgentInputCoordinator {
* 首次 admission / 网络失败可以自动穿过,而持续无产出时仍会在上限处停下。
* - 已 accept 的 stall / idle / reconnect-stalled timeout:即使 DB 里没有
* assistant 行,也只发 CONTINUE,绝不克隆原文(本 turn 可能已经跑过工具)。
- * - 不 `touchUserSend`:那个时间戳的语义是「人最近发过消息」(会话列表 / 陈旧判定
- * 在读它),自动补发不该冒充人类动作。
+ * - 不通知 `onUserAction`:自动补发不算真人接手。人工与自动恢复都保留原消息的
+ * userSendAt,不因重试改变列表排序;真人接手与新消息发送分别记账。
*/
private async performRetryLastError(
sessionId: string,
@@ -3459,7 +3459,7 @@ export class AgentInputCoordinator {
attemptToken ?? undefined,
);
}
- if (!automatic) this.touchUserSend(sessionId);
+ if (!automatic) this.deps.onUserAction?.(sessionId);
this.emit(sessionId);
this.scheduleDrain(sessionId, 'retry');
this.scheduleExternalTurnRetryIfNeeded(sessionId, state, 'retry');