The best way to control Claude Code, Codex and more from any computer or phone
fix(server): backend children no longer count as desktop resources (#19645)
Jet committed
Oct 18, 2026 at 12:13 UTC
cd6b8b71183c00e3e7698cf0c27b7f4aea696c11
2 files changed
+66
-1
apps/server/src/resourceTelemetry/Model.test.ts
+62
@@ -174,6 +174,68 @@ describe("resource telemetry process model", () => {
174
expect(result.groups.electron.processCount).toBe(2);
175
});
176
177
+ it("keeps backend descendants out of desktop totals when Electron launches the server", () => {
178
+ const samples = [
179
+ processSample({ pid: 300, ppid: 1, startTimeMs: 1_000, cpuPercent: 2 }),
180
+ processSample({ pid: SERVER_PID, ppid: 300, startTimeMs: 2_000, cpuPercent: 5 }),
181
+ processSample({ pid: 200, ppid: SERVER_PID, startTimeMs: 3_000, cpuPercent: 400 }),
182
+ processSample({ pid: 201, ppid: 200, startTimeMs: 4_000, cpuPercent: 100 }),
183
+ processSample({ pid: 301, ppid: 300, startTimeMs: 3_000, cpuPercent: 3 }),
184
+ processSample({ pid: 900, ppid: SERVER_PID, startTimeMs: 3_000, cpuPercent: 1 }),
185
+ ];
186
+ const desktop = desktopSnapshot(BASE_TIME_MS, [
187
+ electronMetric({ pid: 300, creationTimeMs: 1_000, type: "Browser" }),
188
+ ]);
189
+ const first = merge({
190
+ sidecarPid: 900,
191
+ native: nativeSnapshot(BASE_TIME_MS, samples),
192
+ desktop,
193
+ });
194
+ const result = merge({
195
+ sidecarPid: 900,
196
+ previous: first,
197
+ native: nativeSnapshot(
198
+ BASE_TIME_MS + 1_000,
199
+ samples.map((sample) => ({
200
+ ...sample,
201
+ cpuTimeMs: sample.cpuPercent * 10,
202
+ ioReadBytes: sample.cpuPercent * 100,
203
+ ioWriteBytes: sample.cpuPercent * 200,
204
+ })),
205
+ 2,
206
+ ),
207
+ desktop,
208
+ });
209
+
210
+ expect(result.processes.find((process) => process.identity.pid === 200)?.category).toBe(
211
+ "server-child",
212
+ );
213
+ expect(result.processes.find((process) => process.identity.pid === 201)?.category).toBe(
214
+ "server-child",
215
+ );
216
+ expect(result.groups.backend).toMatchObject({
217
+ processCount: 3,
218
+ currentCpuPercent: 505,
219
+ cpuTimeMs: 5_050,
220
+ currentRssBytes: 3_072,
221
+ ioReadBytes: 50_500,
222
+ ioWriteBytes: 101_000,
223
+ processStarts: 3,
224
+ });
225
+ expect(result.groups.electron).toMatchObject({
226
+ processCount: 2,
227
+ currentCpuPercent: 5,
228
+ cpuTimeMs: 50,
229
+ currentRssBytes: 2_048,
230
+ ioReadBytes: 500,
231
+ ioWriteBytes: 1_000,
232
+ processStarts: 2,
233
+ });
234
+ expect(result.groups.monitor.processCount).toBe(1);
235
+ expect(result.groups.allT3.currentCpuPercent).toBe(511);
236
+ expect(result.groups.allT3.currentRssBytes).toBe(6_144);
237
+ });
238
+
239
it("ignores stale Electron metrics after PID reuse", () => {
240
const result = merge({
241
native: nativeSnapshot(BASE_TIME_MS, [
apps/server/src/resourceTelemetry/Model.ts
+4
-1
@@ -191,11 +191,14 @@ function isElectronDescendant(
191
pid: number,
192
processesByPid: ReadonlyMap<number, ResourceMonitorProcessSample>,
193
electronPids: ReadonlySet<number>,
194
+ serverPid: number,
195
): boolean {
196
const visited = new Set<number>();
197
let currentPid = pid;
198
while (!visited.has(currentPid)) {
199
visited.add(currentPid);
200
+ // The backend's children belong to the backend even when Electron launched it.
201
+ if (currentPid === serverPid) return false;
202
if (electronPids.has(currentPid)) return true;
203
const current = processesByPid.get(currentPid);
204
if (!current || current.ppid <= 0 || current.ppid === currentPid) return false;
@@ -507,7 +510,7 @@ export function mergeProcesses(input: MergeProcessesInput): MergeProcessesResult
510
? "electron-main"
511
: electronMetric
512
? electronCategory(electronMetric)
510
- : isElectronDescendant(process.pid, processesByPid, electronPids)
513
+ : isElectronDescendant(process.pid, processesByPid, electronPids, input.serverPid)
514
? inferredElectronCategory(process)
515
: "server-child";
516
const firstSeenAt = previous?.process.firstSeenAt ?? DateTime.makeUnsafe(sampledAtMs);