Skip to content

Commit 701374e

Browse files
d-csTrigger.dev RepoOps
authored andcommitted
feat(run-engine): route execution snapshots through a versioned residency resolver
No user-facing change. This adds an optional internal route field while the snapshot-store rollout remains inactive. Mono-RevId: 3da62651b5918e6873a83e0d30c2a05ad24b6542
1 parent 65c894b commit 701374e

89 files changed

Lines changed: 8836 additions & 179 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/supervisor/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,8 @@ class ManagedSupervisor {
661661
nextAttemptNumber: message.run.attemptNumber,
662662
snapshotId: message.snapshot.id,
663663
snapshotFriendlyId: message.snapshot.friendlyId,
664+
// Carry the run's storage route to the cold-start pod so its start request echoes it back.
665+
snapshotRoute: message.snapshotRoute,
664666
placementTags: message.placementTags,
665667
traceContext: message.run.traceContext,
666668
annotations: message.run.annotations,

apps/supervisor/src/workloadManager/compute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export class ComputeWorkloadManager implements WorkloadManager {
157157
TRIGGER_DEPLOYMENT_VERSION: opts.deploymentVersion,
158158
TRIGGER_RUN_ID: opts.runFriendlyId,
159159
TRIGGER_SNAPSHOT_ID: opts.snapshotFriendlyId,
160+
...(opts.snapshotRoute ? { TRIGGER_SNAPSHOT_ROUTE: JSON.stringify(opts.snapshotRoute) } : {}),
160161
TRIGGER_SUPERVISOR_API_PROTOCOL: this.opts.workloadApiProtocol,
161162
TRIGGER_SUPERVISOR_API_PORT: String(this.opts.workloadApiPort),
162163
TRIGGER_SUPERVISOR_API_DOMAIN: this.opts.workloadApiDomain ?? "",

apps/supervisor/src/workloadManager/docker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export class DockerWorkloadManager implements WorkloadManager {
7878
`TRIGGER_DEPLOYMENT_VERSION=${opts.deploymentVersion}`,
7979
`TRIGGER_RUN_ID=${opts.runFriendlyId}`,
8080
`TRIGGER_SNAPSHOT_ID=${opts.snapshotFriendlyId}`,
81+
...(opts.snapshotRoute
82+
? [`TRIGGER_SNAPSHOT_ROUTE=${JSON.stringify(opts.snapshotRoute)}`]
83+
: []),
8184
`TRIGGER_SUPERVISOR_API_PROTOCOL=${this.opts.workloadApiProtocol}`,
8285
`TRIGGER_SUPERVISOR_API_PORT=${this.opts.workloadApiPort}`,
8386
`TRIGGER_SUPERVISOR_API_DOMAIN=${this.opts.workloadApiDomain ?? getDockerHostDomain()}`,

apps/supervisor/src/workloadManager/kubernetes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ export class KubernetesWorkloadManager implements WorkloadManager {
215215
name: "TRIGGER_SNAPSHOT_ID",
216216
value: opts.snapshotFriendlyId,
217217
},
218+
...(opts.snapshotRoute
219+
? [
220+
{
221+
name: "TRIGGER_SNAPSHOT_ROUTE",
222+
value: JSON.stringify(opts.snapshotRoute),
223+
},
224+
]
225+
: []),
218226
{
219227
name: "TRIGGER_SUPERVISOR_API_PROTOCOL",
220228
value: this.opts.workloadApiProtocol,

apps/supervisor/src/workloadManager/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
MachinePreset,
44
PlacementTag,
55
RunAnnotations,
6+
SnapshotRouteWire,
67
} from "@trigger.dev/core/v3";
78

89
export interface WorkloadManagerOptions {
@@ -50,6 +51,8 @@ export interface WorkloadManagerCreateOptions {
5051
runFriendlyId: string;
5152
snapshotId: string;
5253
snapshotFriendlyId: string;
54+
// The run's storage route, materialized as the TRIGGER_SNAPSHOT_ROUTE env var for a cold start.
55+
snapshotRoute?: SnapshotRouteWire;
5356
// Trace context for OTel span emission (W3C format: { traceparent: "00-...", tracestate?: "..." })
5457
traceContext?: Record<string, unknown>;
5558
annotations?: RunAnnotations;

apps/webapp/app/routes/engine.v1.dev.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.attempts.start.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const { action } = createActionApiRoute(
4949
const engineResult = await engine.startRunAttempt({
5050
runId: RunId.toId(runFriendlyId),
5151
snapshotId: SnapshotId.toId(snapshotFriendlyId),
52+
isWarmStart: body.isWarmStart,
53+
snapshotRoute: body.snapshotRoute,
5254
});
5355

5456
const defaultMachinePreset = machinePresetFromName(defaultMachine);

apps/webapp/app/routes/engine.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.attempts.complete.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const action = createActionWorkerApiRoute(
2929
completion,
3030
runnerId,
3131
environmentId,
32+
snapshotRoute: body.snapshotRoute,
3233
});
3334

3435
return json({ result: completeResult });

apps/webapp/app/routes/engine.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.attempts.start.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const action = createActionWorkerApiRoute(
2828
isWarmStart: body.isWarmStart,
2929
runnerId,
3030
environmentId,
31+
snapshotRoute: body.snapshotRoute,
3132
});
3233

3334
return json(runExecutionData);

apps/webapp/app/routes/engine.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.continue.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { TypedResponse } from "@remix-run/server-runtime";
22
import { json } from "@remix-run/server-runtime";
3+
import { WorkerApiContinueRunExecutionQueryParams } from "@trigger.dev/core/v3/runEngineWorker";
4+
import type { SnapshotRouteWire } from "@trigger.dev/core/v3";
35
import type { WorkerApiContinueRunExecutionRequestBody } from "@trigger.dev/core/v3/workers";
46
import { z } from "zod";
57
import { logger } from "~/services/logger.server";
@@ -16,11 +18,38 @@ export const loader = createLoaderWorkerApiRoute(
1618
async ({
1719
authenticatedWorker,
1820
params,
21+
request,
1922
runnerId,
2023
environmentId,
2124
}): Promise<TypedResponse<WorkerApiContinueRunExecutionRequestBody>> => {
2225
const { runFriendlyId, snapshotFriendlyId } = params;
2326

27+
// Optional, mixed-version: older workers omit it. It's a GET, so it travels as a URL query
28+
// param (a JSON-encoded SnapshotRouteWire), not a body — see
29+
// WorkerApiContinueRunExecutionQueryParams.
30+
const rawSnapshotRoute = new URL(request.url).searchParams.get("snapshotRoute");
31+
let snapshotRoute: SnapshotRouteWire | undefined;
32+
if (rawSnapshotRoute) {
33+
try {
34+
const parsed = WorkerApiContinueRunExecutionQueryParams.shape.snapshotRoute.safeParse(
35+
JSON.parse(rawSnapshotRoute)
36+
);
37+
if (parsed.success) {
38+
snapshotRoute = parsed.data;
39+
} else {
40+
logger.warn("Continuing run execution: ignoring unparseable snapshotRoute query param", {
41+
runFriendlyId,
42+
snapshotFriendlyId,
43+
});
44+
}
45+
} catch {
46+
logger.warn("Continuing run execution: ignoring invalid snapshotRoute query param JSON", {
47+
runFriendlyId,
48+
snapshotFriendlyId,
49+
});
50+
}
51+
}
52+
2453
logger.debug("Continuing run execution", { runFriendlyId, snapshotFriendlyId });
2554

2655
try {
@@ -29,6 +58,7 @@ export const loader = createLoaderWorkerApiRoute(
2958
snapshotFriendlyId,
3059
runnerId,
3160
environmentId,
61+
snapshotRoute,
3262
});
3363

3464
return json(continuationResult);

apps/webapp/app/routes/engine.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.suspend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const action = createActionWorkerApiRoute(
4040
snapshotFriendlyId,
4141
checkpoint: body.checkpoint,
4242
runnerId,
43+
snapshotRoute: body.snapshotRoute,
4344
});
4445

4546
return json({ ok: true });

0 commit comments

Comments
 (0)