Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop,maker-shared): cancelled 落失败印记;退场期限单调不减防慢时钟掐断
Kafeifei8518d63570e7
diff --git a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsxindex 92dcf78fad..327bbdddd7 100644--- a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx+++ b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx@@ -19,7 +19,7 @@* 这时候按"全勾完"抢跑退场,会在章晚到(>2s)时先消失再被章复活闪回 2 秒。*/-import { useEffect, useMemo, useState } from 'react';+import { useEffect, useMemo, useRef, useState } from 'react';import { findLatestMessageTodoInsertion } from '@cindy/maker-shared/message-render';import { TodoListCard } from '@/components/chat/TodoListCard';@@ -90,11 +90,28 @@ export function PinnedPlanPanel({deadlineMs: number;} | null>(null);const completionIdentity = insertion ? `${sessionId ?? 'unknown'}:${insertion.key}` : null;- const completionDeadlineMs =- persistedCompletionDeadlineMs ??- (retired && fallbackCompletionVisibility?.identity === completionIdentity+ const fallbackDeadlineMs =+ retired && fallbackCompletionVisibility?.identity === completionIdentity? fallbackCompletionVisibility.deadlineMs- : null);+ : null;+ // 执行端偏慢的另一半:实时 done 先按本地时刻(updatedAtMs/createdAt)起了+ // 2 秒缓冲,随后到达的落库行带"过去"的执行端 sealedAtMs,重算出的期限已+ // 过期——直接替换会把进行中的缓冲瞬间掐断。规则:同一身份的期限单调不减+ // (render 间用 ref 记地板),后算出的更早期限只能取 max,不能倒退。重载/+ // 新窗口是全新组件,地板为空,过期的章照旧立即隐藏(不重数 2 秒)。+ const rawDeadlineMs =+ persistedCompletionDeadlineMs !== null && fallbackDeadlineMs !== null+ ? Math.max(persistedCompletionDeadlineMs, fallbackDeadlineMs)+ : (persistedCompletionDeadlineMs ?? fallbackDeadlineMs);+ const deadlineFloorRef = useRef<{ identity: string; deadlineMs: number } | null>(null);+ let completionDeadlineMs = rawDeadlineMs;+ if (completionDeadlineMs !== null && completionIdentity) {+ const floor = deadlineFloorRef.current;+ if (floor && floor.identity === completionIdentity) {+ completionDeadlineMs = Math.max(completionDeadlineMs, floor.deadlineMs);+ }+ deadlineFloorRef.current = { identity: completionIdentity, deadlineMs: completionDeadlineMs };+ }const completedPlanExpired = Boolean(completionDeadlineMs !== null && completionDeadlineMs <= Date.now(),);diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsxindex 59174246f2..ed8f308238 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/PinnedPlanPanel.test.tsx@@ -314,6 +314,45 @@ describe('PinnedPlanPanel terminal seal', () => {};}+ it('does not cut short a running grace when a past-clock sealed row arrives', () => {+ // 执行端偏慢:本地已按实时 done 起了 2 秒缓冲,随后到达的落库行带过去的+ // 章时刻(算出的期限已过期)。取较晚者——缓冲不被远端时钟掐断。+ const view = render(+ <PinnedPlanPanel+ sessionId="slow-clock"+ messages={[{ ...planMessage('in_progress', T0), terminalPlanSnapshot: true }]}+ animated={false}+ width={400}+ />,+ );+ // 无 sealedAtMs → fallback 通道在本地起 2 秒缓冲。+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();+ act(() => vi.advanceTimersByTime(500));++ // 持久化行到达:执行端时钟慢 10 分钟,章时刻在本地视角早已过期。+ view.rerender(+ <PinnedPlanPanel+ sessionId="slow-clock"+ messages={[+ {+ ...planMessage('in_progress', T0),+ terminalPlanSnapshot: true,+ terminalPlanAtMs: T0 - 10 * 60_000,+ },+ ]}+ animated={false}+ width={400}+ />,+ );++ // 本地缓冲还剩 1.5 秒:不得瞬间消失。+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();+ act(() => vi.advanceTimersByTime(1_499));+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();+ act(() => vi.advanceTimersByTime(1));+ expect(screen.queryByTestId('plan-pill')).toBeNull();+ });+it('clamps a future terminal seal timestamp to the local clock (device-link skew)', () => {// 章的时刻来自执行端时钟。被控场景下执行端偏快时,sealedAtMs 在本机看是// "未来"——不钳制的话胶囊会多挂整个偏差时长;钳到本地此刻后仍是标准 2 秒。diff --git a/packages/maker-shared/src/__tests__/planCompletion.test.ts b/packages/maker-shared/src/__tests__/planCompletion.test.tsindex bc457899a6..b413fc1227 100644--- a/packages/maker-shared/src/__tests__/planCompletion.test.ts+++ b/packages/maker-shared/src/__tests__/planCompletion.test.ts@@ -175,9 +175,20 @@ describe('applyCodexPlanSnapshotOnDone', () => {const message = planMessage('plan:raced', [{ step: 'Inspect', status: 'in_progress' }]);const messages = [message];- expect(- applyCodexPlanSnapshotOnDone(messages, null, 'raced', 'completed', undefined, true),- ).toEqual({ messages, changed: false, toolUseId: null });+ const result = applyCodexPlanSnapshotOnDone(+ messages,+ null,+ 'raced',+ 'completed',+ undefined,+ true,+ );+ // 不盖成功章,但要立即落失败印记(turnCompleted:false)——只拦盖章的话,+ // 全勾完的取消计划会被旧数据兜底即时隐藏,再被 main 落库行复活闪回。+ expect(result.changed).toBe(true);+ expect(result.toolUseId).toBe('plan:raced');+ expect(result.messages[0]).toMatchObject({ turnCompleted: false });+ expect(result.messages[0]).not.toMatchObject({ terminalPlanSnapshot: true });});it('does not seal a failed or interrupted turn, but stamps it as failed', () => {diff --git a/packages/maker-shared/src/messageRender.ts b/packages/maker-shared/src/messageRender.tsindex 5ac579e568..a99d33a20b 100644--- a/packages/maker-shared/src/messageRender.ts+++ b/packages/maker-shared/src/messageRender.ts@@ -634,9 +634,13 @@ export function applyCodexPlanSnapshotOnDone<// 只看 status 会先盖章退场,随后 main 持久化 turnCompleted:false 的 DB 行// 广播到达,计划复活——即时 UI 与落库分叉。const sealsTurn = terminalStatus === 'completed' && cancelled !== true && Boolean(turnId);- // done 恒为终态:status 不是 completed(interrupted / failed)即失败终态。+ // done 恒为终态:status 非 completed(interrupted / failed),或 cancelled 覆盖+ // 了 completed,均为失败终态——后者只拦盖章不落失败印记的话,全勾完的取消+ // 计划会被旧数据兜底即时隐藏,再被 main 的 turnCompleted:false 落库行复活。const stampsFailed =- Boolean(turnId) && typeof terminalStatus === 'string' && terminalStatus !== 'completed';+ Boolean(turnId) &&+ ((typeof terminalStatus === 'string' && terminalStatus !== 'completed') ||+ (cancelled === true && terminalStatus === 'completed'));if (!authoritativeSnapshot && !sealsTurn && !stampsFailed) {return { messages, changed: false, toolUseId: null };}