fix: preserve runtime rss fallback when process table misses roots

This commit is contained in:
777genius 2026-05-30 15:16:03 +03:00
parent f0797e2c12
commit 58dfac8377
2 changed files with 14 additions and 16 deletions

View file

@ -26033,7 +26033,6 @@ export class TeamProvisioningService {
const childrenByParent = this.buildRuntimeProcessChildrenByParent(normalizedProcessRows);
const rowByPid = new Map(normalizedProcessRows.map((row) => [row.pid, row]));
const missingRootPids: number[] = [];
let hasMatchedRootPid = false;
for (const rootPid of uniqueRoots) {
const pids: number[] = [];
let truncated = false;
@ -26047,7 +26046,6 @@ export class TeamProvisioningService {
usageTreesByRootPid.set(rootPid, { pids: [], truncated: false });
continue;
}
hasMatchedRootPid = true;
const rootProcessSource = rootProcessRow?.runtimeTelemetrySource;
const addPid = (pid: number): boolean => {
if (pids.includes(pid)) {
@ -26106,15 +26104,13 @@ export class TeamProvisioningService {
usageTreesByRootPid.set(rootPid, { pids, truncated });
}
if (hasMatchedRootPid) {
for (const rootPid of missingRootPids) {
if (scheduledPids.size >= TeamProvisioningService.MAX_RUNTIME_USAGE_PIDS_PER_SNAPSHOT) {
usageTreesByRootPid.set(rootPid, { pids: [], truncated: true });
continue;
}
scheduledPids.add(rootPid);
usageTreesByRootPid.set(rootPid, { pids: [rootPid], truncated: false });
for (const rootPid of missingRootPids) {
if (scheduledPids.size >= TeamProvisioningService.MAX_RUNTIME_USAGE_PIDS_PER_SNAPSHOT) {
usageTreesByRootPid.set(rootPid, { pids: [], truncated: true });
continue;
}
scheduledPids.add(rootPid);
usageTreesByRootPid.set(rootPid, { pids: [rootPid], truncated: false });
}
return usageTreesByRootPid;

View file

@ -3657,7 +3657,7 @@ describe('TeamProvisioningService', () => {
});
});
it('does not fall back to pidusage for root pids missing from an available process table', async () => {
it('falls back to pidusage for root pids missing from an otherwise available process table', async () => {
const svc = new TeamProvisioningService();
(svc as any).configReader = {
getConfig: vi.fn(async () => ({
@ -3705,20 +3705,22 @@ describe('TeamProvisioningService', () => {
rssBytes: 12_000_000,
},
]);
vi.mocked(pidusage).mockResolvedValueOnce({
'111': createPidusageStat(111, 123_000_000),
'222': createPidusageStat(222, 456_000_000),
});
const snapshot = await svc.getTeamAgentRuntimeSnapshot('runtime-team');
expect(pidusage).not.toHaveBeenCalled();
expect(pidusage).toHaveBeenCalledWith([111, 222], EXPECTED_RUNTIME_PIDUSAGE_OPTIONS);
expect(snapshot.members['team-lead']).toMatchObject({
pid: 111,
rssBytes: 123_000_000,
});
expect(snapshot.members['team-lead'].cpuPercent).toBeUndefined();
expect(snapshot.members['team-lead'].rssBytes).toBeUndefined();
expect(snapshot.members.alice).toMatchObject({
pid: 222,
rssBytes: 456_000_000,
});
expect(snapshot.members.alice.cpuPercent).toBeUndefined();
expect(snapshot.members.alice.rssBytes).toBeUndefined();
});
it('captures CPU and memory history on runtime snapshots', async () => {