@devries-cameron20 / t3code-1 / commits / da46db6ea3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

test(telemetry): keep fixture PIDs from colliding with the test worker (#21446)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Victor Vogel committed Oct 21, 2026 at 16:11 UTC da46db6ea3008f9575657a025d0b57e12d3c9272
2 files changed +50 -33
apps/server/src/diagnostics/ProcessDiagnostics.test.ts
+21 -14
@@ -15,6 +15,11 @@ import * as ResourceAttribution from "../resourceTelemetry/ResourceAttribution.t
15 import * as ResourceTelemetry from "../resourceTelemetry/ResourceTelemetry.ts";
16 import * as ProcessDiagnostics from "./ProcessDiagnostics.ts";
17
18 +// ProcessDiagnostics treats process.pid as the server, so the fixture PID is an
19 +// offset from it. A fixed PID collides whenever the test worker is assigned it.
20 +const SERVER_PID = process.pid;
21 +const CHILD_PID = SERVER_PID + 1;
22 +
23 function makeNativeSnapshot(
24 processes: ResourceMonitorSnapshotEvent["processes"],
25 ): ResourceMonitorSnapshotEvent {
@@ -71,7 +76,7 @@ describe("ProcessDiagnostics", () => {
76 const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
77 Effect.flatMap((processDiagnostics) =>
78 processDiagnostics.signal({
74 - pid: 4_242,
79 + pid: CHILD_PID,
80 startTimeMs: 2_000,
81 signal: "SIGINT",
82 }),
@@ -80,10 +85,12 @@ describe("ProcessDiagnostics", () => {
85 );
86
87 expect(result).toEqual({
83 - pid: 4242,
88 + pid: CHILD_PID,
89 signal: "SIGINT",
90 signaled: false,
86 - message: Option.some("Process 4242 no longer matches the selected process identity."),
91 + message: Option.some(
92 + `Process ${CHILD_PID} no longer matches the selected process identity.`,
93 + ),
94 });
95 }),
96 );
@@ -92,8 +99,8 @@ describe("ProcessDiagnostics", () => {
99 Effect.gen(function* () {
100 const snapshot = makeNativeSnapshot([
101 {
95 - pid: 4_242,
96 - ppid: process.pid,
102 + pid: CHILD_PID,
103 + ppid: SERVER_PID,
104 startTimeMs: 2_000,
105 runTimeMs: 4_000,
106 name: "agent",
@@ -134,7 +141,7 @@ describe("ProcessDiagnostics", () => {
141 const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
142 Effect.flatMap((processDiagnostics) =>
143 processDiagnostics.signal({
137 - pid: 4_242,
144 + pid: CHILD_PID,
145 startTimeMs: 2_000,
146 signal: "SIGINT",
147 }),
@@ -143,11 +150,11 @@ describe("ProcessDiagnostics", () => {
150 );
151
152 expect(result).toEqual({
146 - pid: 4_242,
153 + pid: CHILD_PID,
154 signal: "SIGINT",
155 signaled: false,
156 message: Option.some(
150 - "Could not refresh process 4242; refusing to signal a stale identity.",
157 + `Could not refresh process ${CHILD_PID}; refusing to signal a stale identity.`,
158 ),
159 });
160 }),
@@ -160,7 +167,7 @@ describe("ProcessDiagnostics", () => {
167 );
168 const snapshot = makeNativeSnapshot([
169 {
163 - pid: 4_242,
170 + pid: CHILD_PID,
171 ppid: 1,
172 startTimeMs: 2_000,
173 runTimeMs: 4_000,
@@ -182,7 +189,7 @@ describe("ProcessDiagnostics", () => {
189 type: "desktopTelemetry",
190 sequence: 1,
191 sampledAtUnixMs,
185 - electronPid: 4_242,
192 + electronPid: CHILD_PID,
193 power: {
194 source: "electron-main",
195 idle: "false",
@@ -198,7 +205,7 @@ describe("ProcessDiagnostics", () => {
205 speedLimitPercent: Option.none(),
206 electronProcesses: [
207 {
201 - pid: 4_242,
208 + pid: CHILD_PID,
209 creationTimeMs: 2_000,
210 type: "Browser",
211 name: "electron",
@@ -214,7 +221,7 @@ describe("ProcessDiagnostics", () => {
221 const result = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
222 Effect.flatMap((processDiagnostics) =>
223 processDiagnostics.signal({
217 - pid: 4_242,
224 + pid: CHILD_PID,
225 startTimeMs: 2_000,
226 signal: "SIGKILL",
227 }),
@@ -223,10 +230,10 @@ describe("ProcessDiagnostics", () => {
230 );
231
232 expect(result).toEqual({
226 - pid: 4_242,
233 + pid: CHILD_PID,
234 signal: "SIGKILL",
235 signaled: false,
229 - message: Option.some("Process 4242 is not a signalable T3 backend descendant."),
236 + message: Option.some(`Process ${CHILD_PID} is not a signalable T3 backend descendant.`),
237 });
238
239 const diagnostics = yield* Effect.service(ProcessDiagnostics.ProcessDiagnostics).pipe(
apps/server/src/resourceTelemetry/ResourceTelemetry.test.ts
+29 -19
@@ -19,6 +19,14 @@ import * as NativeTelemetryClient from "./NativeTelemetryClient.ts";
19 import * as ResourceAttribution from "./ResourceAttribution.ts";
20 import * as ResourceTelemetry from "./ResourceTelemetry.ts";
21
22 +// ResourceTelemetry classifies process.pid as the server, so fixture PIDs are
23 +// offsets from it. Fixed PIDs collide whenever the test worker is assigned one.
24 +const SERVER_PID = process.pid;
25 +const CODEX_PID = SERVER_PID + 1;
26 +const SHORT_LIVED_CHILD_PID = SERVER_PID + 2;
27 +const ELECTRON_PID = SERVER_PID + 3;
28 +const MONITOR_PID = SERVER_PID + 4;
29 +
30 function processSample(
31 input: Partial<ResourceMonitorProcessSample> &
32 Pick<ResourceMonitorProcessSample, "pid" | "ppid" | "startTimeMs">,
@@ -48,14 +56,14 @@ function nativeSnapshot(input: {
56 }): ResourceMonitorSnapshotEvent {
57 const processes = [
58 processSample({
51 - pid: process.pid,
59 + pid: SERVER_PID,
60 ppid: 1,
61 startTimeMs: 100,
62 cpuTimeMs: input.sequence * 10,
63 }),
64 processSample({
57 - pid: 4_242,
58 - ppid: process.pid,
65 + pid: CODEX_PID,
66 + ppid: SERVER_PID,
67 startTimeMs: 200,
68 name: "codex",
69 command: "codex app-server",
@@ -63,7 +71,7 @@ function nativeSnapshot(input: {
71 ioWriteBytes: input.childWriteBytes,
72 }),
73 processSample({
66 - pid: 5_000,
74 + pid: ELECTRON_PID,
75 ppid: 1,
76 startTimeMs: 300,
77 name: "electron",
@@ -71,8 +79,8 @@ function nativeSnapshot(input: {
79 cpuTimeMs: input.sequence * 20,
80 }),
81 processSample({
74 - pid: 9_000,
75 - ppid: process.pid,
82 + pid: MONITOR_PID,
83 + ppid: SERVER_PID,
84 startTimeMs: 400,
85 name: "t3-resource-monitor",
86 command: "t3-resource-monitor",
@@ -109,7 +117,7 @@ function desktopSnapshot(sampledAtUnixMs: number): DesktopHostTelemetrySnapshot
117 type: "desktopTelemetry",
118 sequence: 1,
119 sampledAtUnixMs,
112 - electronPid: 5_000,
120 + electronPid: ELECTRON_PID,
121 power: {
122 source: "electron-main",
123 idle: "false",
@@ -125,7 +133,7 @@ function desktopSnapshot(sampledAtUnixMs: number): DesktopHostTelemetrySnapshot
133 speedLimitPercent: Option.some(90),
134 electronProcesses: [
135 {
128 - pid: 5_000,
136 + pid: ELECTRON_PID,
137 creationTimeMs: 300,
138 type: "Browser",
139 name: "electron",
@@ -152,17 +160,17 @@ describe("ResourceTelemetry", () => {
160 childWriteBytes: index * 100,
161 });
162 const processes = sample.processes
155 - .filter((entry) => entry.pid === process.pid || entry.pid === 4_242)
163 + .filter((entry) => entry.pid === SERVER_PID || entry.pid === CODEX_PID)
164 .map((entry) =>
157 - entry.pid === 4_242
165 + entry.pid === CODEX_PID
166 ? { ...entry, startTimeMs: index }
167 : { ...entry, ioWriteBytes: index * 100 },
168 );
169 if (index === 0 || index === 2) {
170 processes.push(
171 processSample({
164 - pid: 4_243,
165 - ppid: process.pid,
172 + pid: SHORT_LIVED_CHILD_PID,
173 + ppid: SERVER_PID,
174 startTimeMs: 500,
175 cpuTimeMs: index === 0 ? 100 : 350,
176 ioWriteBytes: index === 0 ? 1_000 : 5_000,
@@ -190,18 +198,20 @@ describe("ResourceTelemetry", () => {
198
199 expect(history.topProcesses).toHaveLength(sampleCount + 2);
200 expect(
193 - history.topProcesses.find((entry) => entry.identity.pid === process.pid),
201 + history.topProcesses.find((entry) => entry.identity.pid === SERVER_PID),
202 ).toMatchObject({
203 sampleCount,
204 cpuTimeMs: (sampleCount - 1) * 10,
205 ioWriteBytes: (sampleCount - 1) * 100,
206 });
199 - const children = history.topProcesses.filter((entry) => entry.identity.pid === 4_242);
207 + const children = history.topProcesses.filter((entry) => entry.identity.pid === CODEX_PID);
208 expect(children).toHaveLength(sampleCount);
209 for (const child of children) {
210 expect(child).toMatchObject({ sampleCount: 1, cpuTimeMs: 0, ioWriteBytes: 0 });
211 }
204 - expect(history.topProcesses.find((entry) => entry.identity.pid === 4_243)).toMatchObject({
212 + expect(
213 + history.topProcesses.find((entry) => entry.identity.pid === SHORT_LIVED_CHILD_PID),
214 + ).toMatchObject({
215 sampleCount: 2,
216 cpuTimeMs: 250,
217 ioWriteBytes: 4_000,
@@ -224,7 +234,7 @@ describe("ResourceTelemetry", () => {
234 sampledAtUnixMs,
235 childCpuTimeMs: 100,
236 childWriteBytes: 1_000,
227 - externalProcesses: [{ pid: 5_000, startTimeMs: 300 }],
237 + externalProcesses: [{ pid: ELECTRON_PID, startTimeMs: 300 }],
238 });
239 const desktop = {
240 ...desktopSnapshot(sampledAtUnixMs),
@@ -253,9 +263,9 @@ describe("ResourceTelemetry", () => {
263 return yield* telemetry.refresh;
264 }).pipe(Effect.provide(layerTelemetry));
265
256 - expect(snapshot.processes.find((entry) => entry.identity.pid === 5_000)?.category).toBe(
257 - "electron-main",
258 - );
266 + expect(
267 + snapshot.processes.find((entry) => entry.identity.pid === ELECTRON_PID)?.category,
268 + ).toBe("electron-main");
269 expect(snapshot.groups.electron.processStarts).toBe(1);
270 expect(snapshot.groups.backend.processStarts).toBe(3);
271 }),