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): attribute startup degradation to its stage

zqchrisb620d79dd9e9
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 6c1912bfd1..6bb3166062 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
@@ -5153,7 +5153,40 @@ describe('Pi package executable-code boundary', () => {
}
});
- it('marks startup timing degraded when snapshot limits quarantine a package', async () => {
+ it('keeps completed list and compatibility stages ok when manifest entries exceed the limit', async () => {
+ await createPackage({ oversizedManifest: true });
+ const store = await import('../pi-package-store.js');
+ await store.resolveManagedPiPackageResources({ startupTraceId: '0123456789abcdef' });
+ await store.listPiPackages(); // Drain optional cache persistence before cleanup.
+ const events = loggerRuntime.info.mock.calls
+ .filter(([message]) => message === 'pi startup stage')
+ .map(([, fields]) => fields as Record<string, unknown>);
+ expect(runtime.spawns.some(({ args }) => args.includes('--version'))).toBe(true);
+ expect(events.map(({ stage, status }) => ({ stage, status }))).toEqual([
+ { stage: 'package-list', status: 'ok' },
+ { stage: 'package-inspection', status: 'degraded' },
+ { stage: 'package-compatibility', status: 'ok' },
+ { stage: 'package-fingerprint', status: 'skipped' },
+ { stage: 'package-snapshot', status: 'skipped' },
+ ]);
+ });
+
+ it('marks only the list stage degraded when package listing fails before inspection', async () => {
+ runtime.exitCode = 1;
+ runtime.stderr = 'package listing failed';
+ const store = await import('../pi-package-store.js');
+ 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-list')?.status).toBe('degraded');
+ for (const event of events.filter((event) => event.stage !== 'package-list')) {
+ expect(event.status).toBe('skipped');
+ }
+ });
+
+ it('marks only snapshot timing degraded when snapshot limits quarantine a package', async () => {
await createSkillOnlyPackage('npm:startup-timing-limited');
const store = await import('../pi-package-store.js');
@@ -5163,10 +5196,14 @@ describe('Pi package executable-code boundary', () => {
startupTraceId: 'fedcba9876543210',
});
- const snapshotEvent = loggerRuntime.info.mock.calls
+ const events = loggerRuntime.info.mock.calls
.filter(([message]) => message === 'pi startup stage')
- .map(([, fields]) => fields as Record<string, unknown>)
- .find((fields) => fields.stage === 'package-snapshot');
+ .map(([, fields]) => fields as Record<string, unknown>);
+ expect(events).toHaveLength(5);
+ for (const event of events.filter((fields) => fields.stage !== 'package-snapshot')) {
+ expect(event.status).toBe('ok');
+ }
+ const snapshotEvent = events.find((fields) => fields.stage === 'package-snapshot');
expect(snapshotEvent).toMatchObject({
startupTraceId: 'fedcba9876543210',
status: 'degraded',
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 0859052285..3428be8578 100644
--- a/apps/desktop/src/main/maker-host/pi-package-store.ts
+++ b/apps/desktop/src/main/maker-host/pi-package-store.ts
@@ -441,7 +441,7 @@ interface PiPackageStartupTiming {
packageCount: number;
resourceCount: number;
skippedPackageCount: number;
- degraded: boolean;
+ degradedStages: Set<PiPackageStartupStage>;
}
function createPiPackageStartupTiming(startupTraceId: string | undefined): PiPackageStartupTiming | undefined {
@@ -452,7 +452,7 @@ function createPiPackageStartupTiming(startupTraceId: string | undefined): PiPac
packageCount: 0,
resourceCount: 0,
skippedPackageCount: 0,
- degraded: false,
+ degradedStages: new Set(),
};
}
@@ -473,6 +473,9 @@ async function measurePiPackageStartupStage<T>(
const startedAt = Date.now();
try {
return await operation();
+ } catch (error) {
+ timing?.degradedStages.add(stage);
+ throw error;
} finally {
recordPiPackageStartupDuration(timing, stage, startedAt);
}
@@ -486,7 +489,7 @@ function emitPiPackageStartupTiming(timing: PiPackageStartupTiming | undefined):
startupTraceId: timing.startupTraceId,
stage,
durationMs: durationMs ?? 0,
- status: durationMs === undefined ? 'skipped' : timing.degraded ? 'degraded' : 'ok',
+ status: durationMs === undefined ? 'skipped' : timing.degradedStages.has(stage) ? 'degraded' : 'ok',
packageCount: timing.packageCount,
resourceCount: timing.resourceCount,
skippedPackageCount: timing.skippedPackageCount,
@@ -1736,6 +1739,7 @@ async function extensionResourceView(
...(analysis.detectedApis.length > 0 ? { detectedApis: analysis.detectedApis } : {}),
};
} catch {
+ startupTiming?.degradedStages.add('package-compatibility');
return unknownExtensionResourceView(file);
} finally {
recordPiPackageStartupDuration(startupTiming, 'package-compatibility', startedAt);
@@ -1939,6 +1943,9 @@ async function inspectPackage(
? { currentVersion: truncateDisplayField(requirement.currentVersion, MAX_DISPLAY_VERSION_BYTES) }
: {}),
}));
+ } catch (error) {
+ startupTiming?.degradedStages.add('package-compatibility');
+ throw error;
} finally {
recordPiPackageStartupDuration(startupTiming, 'package-compatibility', compatibilityStartedAt);
}
@@ -1972,6 +1979,9 @@ async function inspectPackage(
? await extensionResourceView(root, file, startupTiming)
: unknownExtensionResourceView(file));
}
+ if (extensionResources.some((resource) => resource.compatibility === 'unknown')) {
+ startupTiming?.degradedStages.add('package-compatibility');
+ }
const resources: PiPackageResourceView[] = [
...extensionResources,
...skills.map((skill) => ({ kind: 'skill' as const, name: skill.name, compatibility: 'supported' as const })),
@@ -2224,6 +2234,10 @@ async function inspectAllPackagesUncached(
// process. Yield between packages so a long roster cannot monopolize it.
await new Promise<void>((resolve) => setImmediate(resolve));
}
+ if (inspected.some((pkg) => pkg.view.warning === 'inspection-failed'
+ || pkg.view.warning === 'inspection-limit' || Boolean(pkg.snapshotUnavailable))) {
+ options.startupTiming?.degradedStages.add('package-inspection');
+ }
recordPiPackageStartupDuration(options.startupTiming, 'package-inspection', inspectionStartedAt);
return inspected;
}
@@ -2506,7 +2520,6 @@ export async function resolveManagedPiPackageResources(
|| pkg.view.warning === 'inspection-limit'
|| Boolean(pkg.snapshotUnavailable)
)).length;
- startupTiming.degraded = startupTiming.skippedPackageCount > 0;
}
if (!snapshotRoot) {
// Native Pi owns loading. Cache only advisory inspection limits here;
@@ -2599,7 +2612,7 @@ export async function resolveManagedPiPackageResources(
}
if (changedSources.size > 0) {
if (startupTiming) {
- startupTiming.degraded = true;
+ startupTiming.degradedStages.add('package-snapshot');
startupTiming.skippedPackageCount = Math.max(
startupTiming.skippedPackageCount,
changedSources.size,
@@ -2682,7 +2695,7 @@ export async function resolveManagedPiPackageResources(
startupTiming.skippedPackageCount,
skippedThisStart.size,
);
- startupTiming.degraded ||= skippedThisStart.size > 0;
+ if (skippedThisStart.size > 0) startupTiming.degradedStages.add('package-snapshot');
}
const snapshotProjectionChanged = await persistSnapshotUnavailableProjection(
unavailableRoots,
@@ -2693,6 +2706,7 @@ export async function resolveManagedPiPackageResources(
}
return staged;
} catch (error) {
+ startupTiming?.degradedStages.add('package-snapshot');
await fs.rm(snapshotRoot, { recursive: true, force: true }).catch(() => undefined);
const warning = error instanceof PiPackageSnapshotLimitError
? 'inspection-limit'
@@ -2721,7 +2735,6 @@ export async function resolveManagedPiPackageResources(
if (!startupTiming) await mutationTail;
return await resolveResources();
} catch (error) {
- if (startupTiming) startupTiming.degraded = true;
log.warn('Pi package resources unavailable; starting without user packages', {
message: error instanceof Error ? error.message : String(error),
});