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(maker-shared): 非成功 done 的即时应用路径也给计划行补失败印记

Kafeifeif217889d8f9c
diff --git a/packages/maker-shared/src/__tests__/planCompletion.test.ts b/packages/maker-shared/src/__tests__/planCompletion.test.ts
index 0fabb0c9a5..abd03fc912 100644
--- a/packages/maker-shared/src/__tests__/planCompletion.test.ts
+++ b/packages/maker-shared/src/__tests__/planCompletion.test.ts
@@ -167,14 +167,29 @@ describe('applyCodexPlanSnapshotOnDone', () => {
)).toEqual({ messages, changed: false, toolUseId: null });
});
- it('does not seal a failed or interrupted turn', () => {
+ it('does not seal a failed or interrupted turn, but stamps it as failed', () => {
+ // interrupted / failed 的 done 不盖章(任务还活着,计划必须留在屏幕上),
+ // 但要立即在内存补 turnCompleted:false——main 的落库印记在 done 广播之后
+ // 才异步到达,没有这枚即时印记,全勾完的中断计划会先被旧数据兜底隐藏、
+ // 再被落库行广播复活闪回。
const message = planMessage('plan:stopped', [{ step: 'Inspect', status: 'in_progress' }]);
- const messages = [message];
+ const result = applyCodexPlanSnapshotOnDone([message], null, 'stopped', 'interrupted');
- expect(applyCodexPlanSnapshotOnDone(messages, null, 'stopped', 'interrupted')).toEqual({
- messages,
+ expect(result.changed).toBe(true);
+ expect(result.toolUseId).toBe('plan:stopped');
+ expect(result.messages[0]).toMatchObject({
+ turnCompleted: false,
+ // 不盖章,步骤状态不动。
+ toolInput: { explanation: 'keep', plan: [{ step: 'Inspect', status: 'in_progress' }] },
+ });
+ expect(result.messages[0]).not.toHaveProperty('terminalPlanSnapshot');
+
+ // 已有印记时是纯 no-op,不重启胶囊计时。
+ const stamped = { ...message, turnCompleted: false };
+ expect(applyCodexPlanSnapshotOnDone([stamped], null, 'stopped', 'interrupted')).toEqual({
+ messages: [stamped],
changed: false,
- toolUseId: null,
+ toolUseId: 'plan:stopped',
});
});
});
diff --git a/packages/maker-shared/src/messageRender.ts b/packages/maker-shared/src/messageRender.ts
index f966167691..348e39382e 100644
--- a/packages/maker-shared/src/messageRender.ts
+++ b/packages/maker-shared/src/messageRender.ts
@@ -597,7 +597,12 @@ export interface CodexPlanSnapshotApplyResult<
*
* Interrupted / failed turns, and any turn whose id does not match, seal
* nothing: the task is still alive and the user is usually about to steer it,
- * so the plan must stay on screen.
+ * so the plan must stay on screen. A matching non-successful terminal `done`
+ * does stamp `turnCompleted:false` on its plan row, immediately in memory —
+ * main's durable stamp (`persistCodexPlanOnDone`) lands asynchronously after
+ * this event is broadcast, and without the in-memory twin an all-done
+ * interrupted plan would be retired by the legacy fallback the moment
+ * streaming ends, then flash back when the durable row arrives.
*/
export function applyCodexPlanSnapshotOnDone<
TMessage extends MessageRenderSourceMessageLike,
@@ -610,7 +615,10 @@ export function applyCodexPlanSnapshotOnDone<
): CodexPlanSnapshotApplyResult<TMessage> {
const authoritativeSnapshot = Array.isArray(snapshot) ? snapshot : null;
const sealsTurn = terminalStatus === 'completed' && Boolean(turnId);
- if (!authoritativeSnapshot && !sealsTurn) {
+ // done 恒为终态:status 不是 completed(interrupted / failed)即失败终态。
+ const stampsFailed =
+ Boolean(turnId) && typeof terminalStatus === 'string' && terminalStatus !== 'completed';
+ if (!authoritativeSnapshot && !sealsTurn && !stampsFailed) {
return { messages, changed: false, toolUseId: null };
}
const expectedToolUseId = turnId ? `plan:${turnId}` : null;
@@ -632,7 +640,9 @@ export function applyCodexPlanSnapshotOnDone<
// Seal an already-sealed row again would be a no-op update that still
// restarts the capsule's grace timer, so treat it as unchanged.
const sealChanged = sealsTurn && message.terminalPlanSnapshot !== true;
- if (!planChanged && !sealChanged) {
+ const failChanged =
+ stampsFailed && message.terminalPlanSnapshot !== true && message.turnCompleted !== false;
+ if (!planChanged && !sealChanged && !failChanged) {
return { messages, changed: false, toolUseId };
}
@@ -647,6 +657,7 @@ export function applyCodexPlanSnapshotOnDone<
: {}),
}
: {}),
+ ...(failChanged ? { turnCompleted: false } : {}),
...(typeof planUpdatedAtMs === 'number' && Number.isFinite(planUpdatedAtMs)
? { planUpdatedAtMs }
: {}),