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(chat): 合并已落库调度失败的续跑资格决策

Dash5b50300ce163
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 5a1c6cf8fe..aff1da883d 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
@@ -11911,7 +11911,7 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
expect(mocks.touchUserSendInDb).toHaveBeenCalledWith('s-b', undefined);
});
- it('派发在持久化后被取消:scheduler 项不留 recovery(不可被人手动 Retry)', async () => {
+ it.each([false, true])('派发在持久化后被取消:scheduler 不留 recovery,仅撤回失败时可续跑(rewindFails=%s)', async (rewindFails) => {
// 项转 active-turn recovery 后唯一的出路是**用户点 Retry**,而 Retry 走克隆已受理
// turn 的路径,不再经过 onAcceptedQueuedMessage —— 没有 scheduler 回调也没有 run
// 跟踪。而这条 run 此刻已经顺延或落终态了,留着就等于让一条已收口的调度 prompt
@@ -11923,6 +11923,7 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
// 记录的同一个坑。存活探测判死这一半的语义不变(下方仍断言)。
const h = createHarness();
const sid = 'sched-recovery';
+ if (rewindFails) h.rewindPersistedUserMessageAfterClear.mockRejectedValueOnce(new Error('disk unavailable'));
h.sendToAgent.mockImplementationOnce(async (sessionId, _message, _createOpts, sendOpts) => {
await persistQueuedUserMessage(sessionId, sendOpts);
return sessionDispatchFailure('SEND/sched-recovery/send');
@@ -11931,6 +11932,7 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
await flush();
expect(latestProjection(h.projections).recovery).toBeNull();
+ expect(latestProjection(h.projections).errorCanContinue === true).toBe(rewindFails);
const bySchedule = (includeRecovery: boolean) =>
h.coordinator.hasQueuedItemWhere(
sid,
@@ -11961,6 +11963,7 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
expect(h.persistTerminalSendError).not.toHaveBeenCalled();
expect(latestProjection(h.projections).error).toBeNull();
expect(latestProjection(h.projections).recovery).toBeNull();
+ expect(latestProjection(h.projections).errorCanContinue).not.toBe(true);
expect(h.coordinator.hasQueuedItemWhere(sid, item => item.clientId === 'scheduled-row')).toBe(false);
},
);
@@ -11978,6 +11981,9 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
await flush();
expect(h.rewindPersistedUserMessageAfterClear).toHaveBeenCalledTimes(path === 'rollback-failed' ? 1 : 0);
expect(h.persistTerminalSendError).toHaveBeenCalled();
+ // #7119: a failed/unsafe rewind leaves a scheduled input in history;
+ // the real catch path must expose continuation. Interactive retry is separate.
+ expect(latestProjection(h.projections).errorCanContinue === true).toBe(path !== 'interactive');
},
);
@@ -12237,6 +12243,7 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
await flush();
expect(latestProjection(h.projections).recovery).toBeNull();
+ expect(latestProjection(h.projections).errorCanContinue).not.toBe(true);
releaseSend();
await flush();
});
@@ -12306,6 +12313,7 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
await flush();
expect(latestProjection(h.projections).recovery).toBeNull();
+ expect(latestProjection(h.projections).errorCanContinue).toBe(true);
expect(
h.coordinator.hasQueuedItemWhere(sid, (item) => item.clientId === 'c1', {
includeRecovery: true,
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 8d0534a136..e3cfa94d6e 100644
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@ -4023,13 +4023,13 @@ export class AgentInputCoordinator {
const schedulerItem = active.item && isSchedulerOriginItem(active.item);
const resumableCandidate = this.isResumableTurnErrorCandidate(sessionId, message, signals, active.item);
const scheduledQuota = isScheduledQuotaRecovery(active.item, message, signals);
+ setErrorProjectionSignals(state, signals);
const outcome = this.setActiveTurnRecovery(state, active.item, {
allowSchedulerAutoResume: Boolean(schedulerItem && resumableCandidate) || scheduledQuota,
+ persistedFailure: true,
});
if (outcome === 'dropped-scheduler') {
state.error = message ?? state.error;
- setErrorProjectionSignals(state, signals);
- this.releasePersistedScheduledErrorRecovery(state);
// **紧随的 done 必须被配对吃掉。**各 agent 的失败收尾都是 terminal error 后再补
// 一个 done;普通用户项靠下方"!active && recovery.kind==='active-turn'"那道守卫
// 挡住它,而 scheduler 项恰恰没有 recovery 可挡 —— done 会一路落到方法尾部的
@@ -4059,10 +4059,9 @@ export class AgentInputCoordinator {
clearErrorProjectionSignals(state);
} else {
state.error = message ?? state.error;
- setErrorProjectionSignals(state, signals);
// 限额失败保留 Retry 与等待;其它确定性错误仍交给 runner 收口。
if (schedulerItem && !scheduledQuota) {
- this.releasePersistedScheduledErrorRecovery(state);
+ this.setActiveTurnRecovery(state, active.item, { persistedFailure: true });
this.markPendingExternalTerminalDone(sessionId, state);
this.emit(sessionId);
this.scheduleDrainAfterExternalTurnSettles(
@@ -5339,7 +5338,9 @@ export class AgentInputCoordinator {
latest.stickyError = null;
// 同 handleSendNotDispatched:调度来源的 prompt 不留可被人手动 Retry 的 recovery
// (review #944 第九轮 P1;判据内建在 setActiveTurnRecovery)。
- const schedulerOrigin = this.setActiveTurnRecovery(latest, head) === 'dropped-scheduler';
+ const schedulerOrigin = this.setActiveTurnRecovery(latest, head, {
+ persistedFailure: !rewound,
+ }) === 'dropped-scheduler';
// 已落库的派发失败必须立刻放开边界。否则 coordinator 会一直占着 activeTurn,
// 下一轮被 dispatch-boundary-busy 挡住,界面上只剩用户气泡、没有红条、也不能重试。
latest.activeTurn = null;
@@ -5492,14 +5493,16 @@ export class AgentInputCoordinator {
// 调度来源的 prompt **不留 active-turn recovery**。它的 Retry 走的是普通用户 turn:
// 没有 scheduler 回调、没有 run 跟踪 —— 而这条 run 此刻已经顺延或落终态了,留着就等于
// 让一条已收口的调度 prompt 之后还能被人手动跑一次(review #944 第九轮 P1)。
- // 失败本身经 scheduler 自己的运行历史 + 通知呈现,不靠这里的重试入口。
+ // 未撤回的失败只授予隐藏续跑资格,不保留或重放已结束的 scheduler prompt。
// 注:isPromptTracked 用的 hasQueuedItemWhere 默认不含 recovery,所以摘掉它不会影响
// runner 的排队存活探测。
- const schedulerOrigin = this.setActiveTurnRecovery(latest, item) === 'dropped-scheduler';
const cancelledByUserBoundary =
latest.queueAbortPending &&
result.kind === 'session-dispatch' &&
result.reason === 'cancelled-before-dispatch';
+ const schedulerOrigin = this.setActiveTurnRecovery(latest, item, {
+ persistedFailure: !rewoundScheduler && !cancelledByUserBoundary,
+ }) === 'dropped-scheduler';
if (!cancelledByUserBoundary) this.notifyRejectedUserTurn(sessionId, item);
this.notifyUndispatchedUserTurn(
sessionId,
@@ -5979,7 +5982,9 @@ export class AgentInputCoordinator {
state.stickyError = null;
// 同 onTurnEvent / handleSendNotDispatched:scheduler 的 prompt 不留重试入口
// (判据内建在 setActiveTurnRecovery,第十八轮 P1)。
- const schedulerOrigin = this.setActiveTurnRecovery(state, item) === 'dropped-scheduler';
+ const schedulerOrigin = this.setActiveTurnRecovery(state, item, {
+ persistedFailure: true,
+ }) === 'dropped-scheduler';
this.notifyUndispatchedUserTurn(sessionId, item, 'failed');
log.warn(
schedulerOrigin
@@ -6541,19 +6546,13 @@ export class AgentInputCoordinator {
}));
}
- /** Only callers that have settled a persisted scheduler input may grant manual continuation.
- * Normal and deferred persistence settlement must share this release boundary. */
- private releasePersistedScheduledErrorRecovery(state: SessionInputState): void {
- state.recovery = null;
- state.errorCanContinue = true;
- }
-
/**
* **唯一的 active-turn recovery 出口。**任何终态路径想留「重试上一轮」入口都必须经这里,
* 不要再直接写 `state.recovery = { kind: 'active-turn', ... }`。
*
* Schedule 的瞬时错误与账号限额可保留 recovery,复用普通聊天的恢复路径;
- * 其余失败由 runner 收口。
+ * 其余失败由 runner 收口;仍在历史里的失败输入可单独授予隐藏续跑资格,
+ * 不保留或重放旧 scheduler prompt。
*
* @returns `kept` = 留下了;`dropped-scheduler` = 因 scheduler 来源被摘掉,此时队列少了
* 「用户点 clearError / Retry」这个唤醒源,调用方通常要补一次 scheduleDrain(Stop 那条
@@ -6564,14 +6563,18 @@ export class AgentInputCoordinator {
private setActiveTurnRecovery(
state: SessionInputState,
item: AgentInputQueuedMessage | null | undefined,
- opts?: { allowSchedulerAutoResume?: boolean },
+ opts?: { allowSchedulerAutoResume?: boolean; persistedFailure?: boolean },
): 'kept' | 'dropped-scheduler' | 'no-item' {
+ state.errorCanContinue = false;
if (!item) {
state.recovery = null;
return 'no-item';
}
if (isSchedulerOriginItem(item) && !opts?.allowSchedulerAutoResume) {
state.recovery = null;
+ // This is the sole granting boundary. Stop, rewound rows and controls
+ // never pass persistedFailure; dispatch errors and terminal settlement do.
+ state.errorCanContinue = opts?.persistedFailure === true;
return 'dropped-scheduler';
}
state.recovery = { kind: 'active-turn', item };
@@ -7121,7 +7124,7 @@ export class AgentInputCoordinator {
// 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.releasePersistedScheduledErrorRecovery(state);
+ this.setActiveTurnRecovery(state, state.recovery.item, { persistedFailure: true });
// 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);
@@ -7415,13 +7418,13 @@ export class AgentInputCoordinator {
const deferredPersistSuppressed = terminalEvent.resumableCandidate === true;
const schedulerItem = active.item && isSchedulerOriginItem(active.item);
const scheduledQuota = isScheduledQuotaRecovery(active.item, terminalEvent.message, terminalEvent.signals);
+ setErrorProjectionSignals(state, terminalEvent.signals);
const outcome = this.setActiveTurnRecovery(state, active.item, {
allowSchedulerAutoResume: Boolean(schedulerItem && deferredPersistSuppressed) || scheduledQuota,
+ persistedFailure: true,
});
if (outcome === 'dropped-scheduler') {
state.error = terminalEvent.message ?? state.error;
- setErrorProjectionSignals(state, terminalEvent.signals);
- this.releasePersistedScheduledErrorRecovery(state);
if (deferredPersistSuppressed) {
this.notifyResumableTurnErrorDiscarded(sessionId, {
surfaceError: true,
@@ -7462,7 +7465,6 @@ export class AgentInputCoordinator {
clearErrorProjectionSignals(state);
} else {
state.error = terminalEvent.message ?? state.error;
- setErrorProjectionSignals(state, terminalEvent.signals);
// 先登记换电脑,再移交候选期暂存的错误;否则 host 会先放出错误卡与 Worker 失败回报。
if (outcome === 'kept' && active.item && terminalEvent.supersededByUser !== true) {
this.holdForProviderGroupSwitch(
@@ -7478,7 +7480,7 @@ export class AgentInputCoordinator {
});
}
if (schedulerItem && !scheduledQuota) {
- this.releasePersistedScheduledErrorRecovery(state);
+ this.setActiveTurnRecovery(state, active.item, { persistedFailure: true });
this.markPendingExternalTerminalDone(sessionId, state);
this.emit(sessionId);
this.scheduleDrainAfterExternalTurnSettles(sessionId, 'scheduler-prompt-terminal-error');