Skip to content

Commit 6de23e2

Browse files
1stvampTrigger.dev RepoOps
authored andcommitted
feat(cli): show the runner's wait for its supervisor on the start timeline
The managed runner can now be told that it was held before starting until its supervisor was reachable. When `TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS` and `TRIGGER_SUPERVISOR_WAIT_MS` are set, the cold-start attempt adds a `supervisor_wait` event to the run's start timeline next to `create_attempt`, so that delay is visible on its own. The dashboard names the event and keeps it admin-only, like the other infrastructure start events. Nothing changes when the variables are unset. Mono-RevId: 1c5d263c7e102d230fa371577623ebf69bb935e5
1 parent 9e78fb0 commit 6de23e2

7 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎apps/webapp/app/utils/timelineSpanEvents.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ function getFriendlyNameForEvent(event: string, properties?: Record<string, any>
147147
case "pod_scheduled": {
148148
return "Pod scheduled";
149149
}
150+
case "supervisor_wait": {
151+
return "Waited for supervisor";
152+
}
150153
default: {
151154
return event;
152155
}
@@ -219,6 +222,9 @@ export function getAdminOnlyForEvent(event: string): boolean {
219222
case "pod_scheduled": {
220223
return true;
221224
}
225+
case "supervisor_wait": {
226+
return true;
227+
}
222228
default: {
223229
return true;
224230
}
@@ -245,6 +251,9 @@ export function getHelpTextForEvent(event: string): string | undefined {
245251
case "pod_scheduled": {
246252
return "The Kubernetes pod was scheduled to run";
247253
}
254+
case "supervisor_wait": {
255+
return "The runner waited until it could reach its supervisor";
256+
}
248257
case "Triggered": {
249258
return "The run was triggered";
250259
}

‎packages/cli-v3/src/entryPoints/managed/controller.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ export class ManagedRunController {
180180
return this.currentExecution?.runFriendlyId;
181181
}
182182

183+
private coldStartSupervisorWait() {
184+
const startedAt = this.env.TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS;
185+
const durationMs = this.env.TRIGGER_SUPERVISOR_WAIT_MS;
186+
return startedAt && durationMs !== undefined ? { startedAt, durationMs } : undefined;
187+
}
188+
183189
private get snapshotFriendlyId() {
184190
return this.currentExecution?.currentSnapshotFriendlyId;
185191
}
@@ -191,13 +197,15 @@ export class ManagedRunController {
191197
snapshotFriendlyId,
192198
dequeuedAt,
193199
podScheduledAt,
200+
supervisorWait,
194201
isWarmStart,
195202
previousRunId,
196203
}: {
197204
runFriendlyId: string;
198205
snapshotFriendlyId: string;
199206
dequeuedAt?: Date;
200207
podScheduledAt?: Date;
208+
supervisorWait?: { startedAt: Date; durationMs: number };
201209
isWarmStart?: boolean;
202210
previousRunId?: string;
203211
}) {
@@ -257,6 +265,7 @@ export class ManagedRunController {
257265
snapshotFriendlyId,
258266
dequeuedAt,
259267
podScheduledAt,
268+
supervisorWait,
260269
isWarmStart,
261270
});
262271
};
@@ -586,6 +595,7 @@ export class ManagedRunController {
586595
snapshotFriendlyId: this.env.TRIGGER_SNAPSHOT_ID,
587596
dequeuedAt: this.env.TRIGGER_DEQUEUED_AT_MS,
588597
podScheduledAt: this.env.TRIGGER_POD_SCHEDULED_AT_MS,
598+
supervisorWait: this.coldStartSupervisorWait(),
589599
}).finally(() => {});
590600
return;
591601
}

‎packages/cli-v3/src/entryPoints/managed/env.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ describe("RunnerEnv.gatherProcessEnv", () => {
2828
}
2929
);
3030
});
31+
32+
describe("RunnerEnv supervisor wait", () => {
33+
// Catches: RunnerEnv dropping the supervisor wait variables as undeclared keys.
34+
it("reads how long the runner was held for its supervisor", () => {
35+
const env = new RunnerEnv({
36+
...requiredEnv,
37+
TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS: "1762860000123",
38+
TRIGGER_SUPERVISOR_WAIT_MS: "328",
39+
});
40+
41+
expect(env.TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS).toEqual(new Date(1762860000123));
42+
expect(env.TRIGGER_SUPERVISOR_WAIT_MS).toBe(328);
43+
});
44+
});

‎packages/cli-v3/src/entryPoints/managed/env.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const Env = z.object({
4545
// Timeline metrics
4646
TRIGGER_POD_SCHEDULED_AT_MS: DateEnv,
4747
TRIGGER_DEQUEUED_AT_MS: DateEnv,
48+
// Set when the runner was held until its supervisor was reachable
49+
TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS: DateEnv.optional(),
50+
TRIGGER_SUPERVISOR_WAIT_MS: z.coerce.number().optional(),
4851

4952
// May be overridden
5053
TRIGGER_RUN_ID: z.string().optional(), // This is set for cold starts and restores
@@ -140,6 +143,12 @@ export class RunnerEnv {
140143
get TRIGGER_DEQUEUED_AT_MS() {
141144
return this.env.TRIGGER_DEQUEUED_AT_MS;
142145
}
146+
get TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS() {
147+
return this.env.TRIGGER_SUPERVISOR_WAIT_STARTED_AT_MS;
148+
}
149+
get TRIGGER_SUPERVISOR_WAIT_MS() {
150+
return this.env.TRIGGER_SUPERVISOR_WAIT_MS;
151+
}
143152

144153
// Overridable values
145154
get TRIGGER_RUN_ID() {

‎packages/cli-v3/src/entryPoints/managed/execution.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type RunExecutionRunOptions = {
5555
snapshotFriendlyId: string;
5656
dequeuedAt?: Date;
5757
podScheduledAt?: Date;
58+
supervisorWait?: { startedAt: Date; durationMs: number };
5859
isWarmStart?: boolean;
5960
};
6061

@@ -69,6 +70,7 @@ export class RunExecution {
6970

7071
private dequeuedAt?: Date;
7172
private podScheduledAt?: Date;
73+
private supervisorWait?: { startedAt: Date; durationMs: number };
7274
private readonly workerManifest: WorkerManifest;
7375
private readonly env: RunnerEnv;
7476
private readonly httpClient: WorkloadHttpClient;
@@ -457,6 +459,10 @@ export class RunExecution {
457459
attemptCreatedAt: attemptStartedAt,
458460
dequeuedAt: this.dequeuedAt?.getTime(),
459461
podScheduledAt: this.podScheduledAt?.getTime(),
462+
supervisorWait: this.supervisorWait && {
463+
startedAt: this.supervisorWait.startedAt.getTime(),
464+
durationMs: this.supervisorWait.durationMs,
465+
},
460466
});
461467

462468
this.sendDebugLog("started attempt", {
@@ -493,6 +499,7 @@ export class RunExecution {
493499

494500
this.dequeuedAt = runOpts.dequeuedAt;
495501
this.podScheduledAt = runOpts.podScheduledAt;
502+
this.supervisorWait = runOpts.supervisorWait;
496503

497504
// Create and start services
498505
this.snapshotPoller = new RunExecutionSnapshotPoller({
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vitest";
2+
import { measureExecutionMetrics } from "./executionMetrics.js";
3+
4+
describe("measureExecutionMetrics", () => {
5+
// Catches: the supervisor wait passed to the runner never reaching the start timeline.
6+
it("adds the supervisor wait to the start timeline", () => {
7+
const metrics = measureExecutionMetrics({
8+
attemptCreatedAt: Date.now(),
9+
supervisorWait: { startedAt: 1_762_860_000_123, durationMs: 328 },
10+
});
11+
12+
expect(metrics).toContainEqual({
13+
name: "start",
14+
event: "supervisor_wait",
15+
timestamp: 1_762_860_000_123,
16+
duration: 328,
17+
});
18+
});
19+
});

‎packages/cli-v3/src/entryPoints/managed/executionMetrics.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ export function measureExecutionMetrics({
44
attemptCreatedAt,
55
dequeuedAt,
66
podScheduledAt,
7+
supervisorWait,
78
}: {
89
attemptCreatedAt: number;
910
dequeuedAt?: number;
1011
podScheduledAt?: number;
12+
supervisorWait?: { startedAt: number; durationMs: number };
1113
}): TaskRunExecutionMetrics {
1214
const metrics: TaskRunExecutionMetrics = [
1315
{
@@ -36,5 +38,14 @@ export function measureExecutionMetrics({
3638
});
3739
}
3840

41+
if (supervisorWait) {
42+
metrics.push({
43+
name: "start",
44+
event: "supervisor_wait",
45+
timestamp: supervisorWait.startedAt,
46+
duration: supervisorWait.durationMs,
47+
});
48+
}
49+
3950
return metrics;
4051
}

0 commit comments

Comments
 (0)