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): 统一失败续跑资格的落库与清理边界

Dashbe03b4527b3a
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 29b09aab37..5a1c6cf8fe 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
@@ -12138,11 +12138,13 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
expect(h.sendToAgent).toHaveBeenCalledTimes(2);
});
- it('终态 error 撞在持久化中途:落库后结算时 scheduler 项也不留 recovery', async () => {
+ it.each([false, true])('终态 error 撞在持久化中途:落库后 scheduler 仍可人工继续,候选=%s', async (candidate) => {
// 第五条终态路径。终态 error 在 active.persisting 期间到达 → 被暂存成
// pendingTerminalEvent,落库完成后由 settlePendingTerminalEventAfterPersist 结算 ——
// 那里原来无条件造 active-turn recovery,漏了 scheduler 排除(第二十轮 P1)。
const h = createHarness();
+ h.setResumableTurnErrorCandidate(() => candidate);
+ h.setResumableTurnErrorTakeover(null);
const sid = 'sched-error-during-persist';
let releasePersist!: () => void;
mocks.createMessage.mockImplementationOnce(
@@ -12161,10 +12163,12 @@ describe('AgentInputCoordinator scheduler 排队心跳(review 反馈回归)', ()
// 落库还挂着,此刻终态 error 到达 → 走 persisting 分支暂存
h.coordinator.onTurnEvent(sid, 'error', 'upstream died mid-persist');
await flush();
+ expect(latestProjection(h.projections).errorCanContinue).not.toBe(true);
releasePersist();
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 68b2b5e4f9..8d0534a136 100644
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@ -4029,7 +4029,7 @@ export class AgentInputCoordinator {
if (outcome === 'dropped-scheduler') {
state.error = message ?? state.error;
setErrorProjectionSignals(state, signals);
- state.errorCanContinue = true;
+ this.releasePersistedScheduledErrorRecovery(state);
// **紧随的 done 必须被配对吃掉。**各 agent 的失败收尾都是 terminal error 后再补
// 一个 done;普通用户项靠下方"!active && recovery.kind==='active-turn'"那道守卫
// 挡住它,而 scheduler 项恰恰没有 recovery 可挡 —— done 会一路落到方法尾部的
@@ -4062,8 +4062,7 @@ export class AgentInputCoordinator {
setErrorProjectionSignals(state, signals);
// 限额失败保留 Retry 与等待;其它确定性错误仍交给 runner 收口。
if (schedulerItem && !scheduledQuota) {
- state.recovery = null;
- state.errorCanContinue = true;
+ this.releasePersistedScheduledErrorRecovery(state);
this.markPendingExternalTerminalDone(sessionId, state);
this.emit(sessionId);
this.scheduleDrainAfterExternalTurnSettles(
@@ -6542,6 +6541,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', ... }`。
@@ -7115,8 +7121,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.setActiveTurnRecovery(state, state.recovery.item);
- state.errorCanContinue = true;
+ this.releasePersistedScheduledErrorRecovery(state);
// 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);
@@ -7416,6 +7421,7 @@ export class AgentInputCoordinator {
if (outcome === 'dropped-scheduler') {
state.error = terminalEvent.message ?? state.error;
setErrorProjectionSignals(state, terminalEvent.signals);
+ this.releasePersistedScheduledErrorRecovery(state);
if (deferredPersistSuppressed) {
this.notifyResumableTurnErrorDiscarded(sessionId, {
surfaceError: true,
@@ -7472,7 +7478,7 @@ export class AgentInputCoordinator {
});
}
if (schedulerItem && !scheduledQuota) {
- state.recovery = null;
+ this.releasePersistedScheduledErrorRecovery(state);
this.markPendingExternalTerminalDone(sessionId, state);
this.emit(sessionId);
this.scheduleDrainAfterExternalTurnSettles(sessionId, 'scheduler-prompt-terminal-error');
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
index cbae256a7d..6fe02ed03e 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
@@ -539,6 +539,37 @@ describe('makerChatStore text delta batching', () => {
unsubscribe();
});
+ // #7119 round 2: projection eligibility belongs to one error episode. Real
+ // status/event/persist ingress must revoke it without another projection,
+ // while a duplicate terminal or paired done for the same error preserves it.
+ it.each(['turn-start', 'replacement', 'recoverable', 'persisted', 'clear'] as const)(
+ 'revokes continuation eligibility at the %s boundary without a projection', async (boundary) => {
+ onInputProjection?.(projection(SESSION_ID, { error: 'capacity', errorCanContinue: true }));
+ const terminal = (message: string, persistId?: string, errorStatus?: number) => onEvent?.({
+ sessionId: SESSION_ID, persistId,
+ event: { type: 'error', source: 'claude-code', data: { isTerminal: true, message, errorStatus } },
+ });
+ terminal('capacity', 'eligible-error', 503);
+ onEvent?.({ sessionId: SESSION_ID, event: { type: 'done', source: 'claude-code', data: {} } });
+ expect(makerChatStore.getLightSnapshot(SESSION_ID).errorCanContinue).toBe(true);
+ if (boundary === 'turn-start') {
+ emitStatus({ status: 'Running', isRunning: true });
+ terminal('capacity');
+ } else if (boundary === 'replacement') {
+ terminal('different error', 'different-id');
+ } else if (boundary === 'recoverable') {
+ onEvent?.({ sessionId: SESSION_ID,
+ event: { type: 'error', source: 'claude-code', data: { isTerminal: false, message: 'retrying' } } });
+ } else if (boundary === 'persisted') {
+ onErrorPersisted?.({ sessionId: SESSION_ID, persistId: 'eligible-error' });
+ } else {
+ makerChatStore.clearError(SESSION_ID);
+ await flushPromises();
+ }
+ expect(makerChatStore.getLightSnapshot(SESSION_ID).errorCanContinue).toBe(false);
+ },
+ );
+
it.each(['local', 'remote'])('retains IM completion provenance through %s ingress and resets it for App turns', (source) => {
if (source === 'remote') remoteProjectsStore.pinSessionOrigin('device-1', SESSION_ID);
const emit = (event: unknown) => {
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index fd9b4c2138..481a2ac8b1 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -4495,11 +4495,20 @@ function getOrCreateState(sessionId: string): SessionChatState {
function setState(
sessionId: string,
updater: (prev: SessionChatState) => SessionChatState,
- opts: { deferNotification?: boolean } = {},
+ opts: { deferNotification?: boolean; fromInputProjection?: boolean } = {},
): void {
const prev = getOrCreateState(sessionId);
- const next = updater(prev);
+ let next = updater(prev);
if (next === prev) return;
+ // Only an input projection can confirm eligibility. Every other transition
+ // may retain it solely for an unchanged live error (e.g. its paired done).
+ // Clearing/replacing the error therefore revokes it at one shared boundary,
+ // including direct turns and deferred persistence without another projection.
+ if (next.errorCanContinue && (!next.error || (!opts.fromInputProjection
+ && (!prev.errorCanContinue || !prev.error
+ || !liveErrorTextMatchesRow(next.error, prev.error, next.errorReason ?? undefined))))) {
+ next = { ...next, errorCanContinue: false };
+ }
if (prev.error !== next.error) {
_liveErrorEpoch.set(sessionId, (_liveErrorEpoch.get(sessionId) ?? 0) + 1);
}
@@ -5039,7 +5048,7 @@ function applyInputProjection(
inputRecovery: projection.recovery ?? null,
...(authRetryProjectionError ? { _authRetryPersistOnProjectionError: undefined } : {}),
};
- });
+ }, { fromInputProjection: true });
if (deferredPersistFromProjection.payload) {
persistTurnErrorDeferredTracked(
projection.sessionId,