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(pi): mark unexecuted startup stages as skipped

zqchris3b82ac59a186
diff --git a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts
index 0b53ee77aa..b2b02cb69a 100644
--- a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts
@@ -5071,6 +5071,40 @@ describe('Pi package executable-code boundary', () => {
expect(serialized).not.toContain(snapshotRoot);
});
+ it('distinguishes skipped startup stages from work completed within the same millisecond', async () => {
+ await createSkillOnlyPackage('npm:startup-timing-native');
+ const store = await import('../pi-package-store.js');
+ const clock = vi.spyOn(Date, 'now').mockReturnValue(Date.now());
+ try {
+ await store.resolveManagedPiPackageResources({ startupTraceId: '0123456789abcdef' });
+ const events = loggerRuntime.info.mock.calls
+ .filter(([message]) => message === 'pi startup stage')
+ .map(([, fields]) => fields as Record<string, unknown>);
+ expect(events).toHaveLength(5);
+ expect(events.find((event) => event.stage === 'package-snapshot')).toMatchObject({
+ status: 'skipped', durationMs: 0, packageCount: 1, resourceCount: 1,
+ });
+ for (const event of events.filter((event) => event.stage !== 'package-snapshot')) {
+ expect(event).toMatchObject({ status: 'ok', durationMs: 0 });
+ }
+
+ loggerRuntime.info.mockClear();
+ await store.resolveManagedPiPackageResources({ startupTraceId: 'fedcba9876543210' });
+ const cachedEvents = loggerRuntime.info.mock.calls
+ .filter(([message]) => message === 'pi startup stage')
+ .map(([, fields]) => fields as Record<string, unknown>);
+ expect(cachedEvents).toHaveLength(5);
+ for (const event of cachedEvents) {
+ expect(event).toMatchObject({
+ startupTraceId: 'fedcba9876543210', status: 'skipped', durationMs: 0,
+ packageCount: 1, resourceCount: 1,
+ });
+ }
+ } finally {
+ clock.mockRestore();
+ }
+ });
+
it('marks startup timing degraded when snapshot limits quarantine a package', async () => {
await createSkillOnlyPackage('npm:startup-timing-limited');
const store = await import('../pi-package-store.js');
diff --git a/apps/desktop/src/main/maker-host/pi-package-store.ts b/apps/desktop/src/main/maker-host/pi-package-store.ts
index 1f96d4645f..972299f7b7 100644
--- a/apps/desktop/src/main/maker-host/pi-package-store.ts
+++ b/apps/desktop/src/main/maker-host/pi-package-store.ts
@@ -436,7 +436,7 @@ type PiPackageStartupStage = typeof PI_PACKAGE_STARTUP_STAGES[number];
interface PiPackageStartupTiming {
startupTraceId: string;
- durationsMs: Record<PiPackageStartupStage, number>;
+ durationsMs: Partial<Record<PiPackageStartupStage, number>>;
packageCount: number;
resourceCount: number;
skippedPackageCount: number;
@@ -447,13 +447,7 @@ function createPiPackageStartupTiming(startupTraceId: string | undefined): PiPac
if (!startupTraceId || !/^[a-f0-9]{16}$/.test(startupTraceId)) return undefined;
return {
startupTraceId,
- durationsMs: {
- 'package-list': 0,
- 'package-inspection': 0,
- 'package-compatibility': 0,
- 'package-fingerprint': 0,
- 'package-snapshot': 0,
- },
+ durationsMs: {},
packageCount: 0,
resourceCount: 0,
skippedPackageCount: 0,
@@ -467,7 +461,7 @@ function recordPiPackageStartupDuration(
startedAt: number,
): void {
if (!timing) return;
- timing.durationsMs[stage] += Math.max(0, Date.now() - startedAt);
+ timing.durationsMs[stage] = (timing.durationsMs[stage] ?? 0) + Math.max(0, Date.now() - startedAt);
}
async function measurePiPackageStartupStage<T>(
@@ -486,11 +480,12 @@ async function measurePiPackageStartupStage<T>(
function emitPiPackageStartupTiming(timing: PiPackageStartupTiming | undefined): void {
if (!timing) return;
for (const stage of PI_PACKAGE_STARTUP_STAGES) {
+ const durationMs = timing.durationsMs[stage];
log.info('pi startup stage', {
startupTraceId: timing.startupTraceId,
stage,
- durationMs: timing.durationsMs[stage],
- status: timing.degraded ? 'degraded' : 'ok',
+ durationMs: durationMs ?? 0,
+ status: durationMs === undefined ? 'skipped' : timing.degraded ? 'degraded' : 'ok',
packageCount: timing.packageCount,
resourceCount: timing.resourceCount,
skippedPackageCount: timing.skippedPackageCount,