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(desktop): 终态章的未来时刻按缺失处理,防跨设备时钟偏差拉长退场

Kafeifei1e84e5bfdf72
diff --git a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx
index f876060ab8..92dcf78fad 100644
--- a/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/PinnedPlanPanel.tsx
@@ -76,8 +76,15 @@ export function PinnedPlanPanel({
Boolean(insertion) && (insertion?.sealed === true || (allDone && !codexPlanAlive));
const completedAtMs =
insertion?.sealedAtMs ?? insertion?.updatedAtMs ?? Date.parse(insertion?.createdAt ?? '');
+ // 章的时刻来自执行端时钟;device-link 被控场景下本机时钟可能与其偏差任意大。
+ // "未来"的时刻不可信(执行端偏快会让胶囊多挂整个偏差时长)——按缺失处理,
+ // 落进下方 fallback 通道:按身份一次性记"本地看到章的此刻 + 2 秒",不随渲染
+ // 滑动。过去的时刻照用(重载/新窗口不重数 2 秒;执行端偏慢最多提前收起,
+ // 无害)。
const persistedCompletionDeadlineMs =
- retired && Number.isFinite(completedAtMs) ? completedAtMs + COMPLETED_PLAN_VISIBLE_MS : null;
+ retired && Number.isFinite(completedAtMs) && completedAtMs <= Date.now()
+ ? completedAtMs + COMPLETED_PLAN_VISIBLE_MS
+ : null;
const [fallbackCompletionVisibility, setFallbackCompletionVisibility] = useState<{
identity: string;
deadlineMs: number;
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.tsx
index 8395e9ee98..59174246f2 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,29 @@ describe('PinnedPlanPanel terminal seal', () => {
};
}
+ it('clamps a future terminal seal timestamp to the local clock (device-link skew)', () => {
+ // 章的时刻来自执行端时钟。被控场景下执行端偏快时,sealedAtMs 在本机看是
+ // "未来"——不钳制的话胶囊会多挂整个偏差时长;钳到本地此刻后仍是标准 2 秒。
+ const sealedInFuture: ChatMessage = {
+ ...planMessage('in_progress', T0),
+ terminalPlanSnapshot: true,
+ terminalPlanAtMs: T0 + 10 * 60_000, // 执行端快 10 分钟
+ };
+
+ render(
+ <PinnedPlanPanel
+ sessionId="skewed-seal"
+ messages={[sealedInFuture]}
+ animated={false}
+ width={400}
+ />,
+ );
+
+ expect(screen.queryByTestId('plan-pill')).not.toBeNull();
+ act(() => vi.advanceTimersByTime(2_000));
+ expect(screen.queryByTestId('plan-pill')).toBeNull();
+ });
+
it('starts the grace period at the terminal seal, not when the plan was created', () => {
// 真实复现:计划先展示了 4 秒,agent 才回答完成。若拿 createdAt 算 2 秒,
// 章一到就已过期,用户会看到泡泡在收尾瞬间直接消失。