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): 开屏卡住诊断上报前把时长收进白名单范围

davidaabb922da8de
diff --git a/apps/desktop/src/renderer/components/log-support/__tests__/StartupLogSupport.test.tsx b/apps/desktop/src/renderer/components/log-support/__tests__/StartupLogSupport.test.tsx
index 543673cdb6..c4dcc3beab 100644
--- a/apps/desktop/src/renderer/components/log-support/__tests__/StartupLogSupport.test.tsx
+++ b/apps/desktop/src/renderer/components/log-support/__tests__/StartupLogSupport.test.tsx
@@ -36,6 +36,7 @@ vi.mock('@/contexts/LoginHandoffContext', () => ({ useLoginHandoff: () => mocks.
vi.mock('@/lib/toast', () => ({ toast: { error: mocks.error, success: mocks.success } }));
import { StartupLogSupport } from '../StartupLogSupport';
+import { parseStartupGateStallSnapshot } from '../../../../shared/startupGateStall';
beforeAll(async () => {
await i18next.use(initReactI18next).init({
@@ -344,4 +345,26 @@ describe('startup gate stall report', () => {
localDbGate: 'pending',
});
});
+
+ // 登录页停留(或休眠)跨过一天后再卡住:时长超出 main 的白名单上限会让整份快照被拒,
+ // 而每次加载只报一次,诊断就此丢失。
+ it('keeps a report from a day-long session within what main accepts', () => {
+ mocks.handoff.brandStageMounted = true;
+ mocks.handoff.startSignals.loginPanelMounted = true;
+ const view = render(<StartupLogSupport />);
+ act(() => vi.advanceTimersByTime(25 * 60 * 60 * 1000));
+
+ mocks.auth.canEnterApp = true;
+ mocks.db.coverHeld = true;
+ mocks.handoff.startSignals.loginPanelMounted = false;
+ view.rerender(<StartupLogSupport />);
+ act(() => vi.advanceTimersByTime(20_000));
+
+ expect(mocks.reportStartupGateStall).toHaveBeenCalledOnce();
+ const payload = mocks.reportStartupGateStall.mock.calls[0][0];
+ expect(parseStartupGateStallSnapshot(payload)).toMatchObject({
+ elapsedMs: 24 * 60 * 60 * 1000,
+ waitingMs: 20_000,
+ });
+ });
});
diff --git a/apps/desktop/src/renderer/components/log-support/useStartupGateStallReport.ts b/apps/desktop/src/renderer/components/log-support/useStartupGateStallReport.ts
index 7ea89c82a7..3029f4cd99 100644
--- a/apps/desktop/src/renderer/components/log-support/useStartupGateStallReport.ts
+++ b/apps/desktop/src/renderer/components/log-support/useStartupGateStallReport.ts
@@ -2,6 +2,7 @@ import { useEffect, useRef } from 'react';
import {
STARTUP_GATE_STALL_AFTER_MS,
+ clampStartupGateStallMs,
type StartupGateStallSnapshot,
} from '../../../shared/startupGateStall';
@@ -32,8 +33,8 @@ export function useStartupGateStallReport(waiting: boolean, state: StartupGateSt
const now = Date.now();
window.electronAPI?.reportStartupGateStall?.({
...stateRef.current,
- elapsedMs: now - loadedAtRef.current,
- waitingMs: now - waitingSince,
+ elapsedMs: clampStartupGateStallMs(now - loadedAtRef.current),
+ waitingMs: clampStartupGateStallMs(now - waitingSince),
documentVisible: document.visibilityState === 'visible',
});
}, STARTUP_GATE_STALL_AFTER_MS);
diff --git a/apps/desktop/src/shared/startupGateStall.ts b/apps/desktop/src/shared/startupGateStall.ts
index f377a0e2eb..9c134caffd 100644
--- a/apps/desktop/src/shared/startupGateStall.ts
+++ b/apps/desktop/src/shared/startupGateStall.ts
@@ -88,9 +88,17 @@ const FIELD_RULES: { readonly [K in keyof StartupGateStallSnapshot]: FieldRule }
loginPanelMounted: { kind: 'boolean' },
};
-/** 一天的毫秒数:上限只为拒绝畸形值,真实上报在阈值附近。 */
+/** 一天的毫秒数:上限只为拒绝畸形值。 */
const MAX_ELAPSED_MS = 24 * 60 * 60 * 1000;
+/**
+ * renderer 上报前把时长收进白名单范围:登录页停留或休眠跨过一天、系统时钟回拨时,
+ * 原值会被 main 整份拒绝,而每次加载只报一次,诊断就此丢失。
+ */
+export function clampStartupGateStallMs(ms: number): number {
+ return Math.min(MAX_ELAPSED_MS, Math.max(0, Math.round(ms)));
+}
+
/**
* IPC 入口校验:键集合必须与白名单完全一致,每个值都落在规则内,否则返回 null。
* 返回值按白名单重建,不复用入参对象。