Skip to content

Commit 3d978d3

Browse files
committed
require suspendable state for checkpoints, fix snapshot processing queue
1 parent bb9ac50 commit 3d978d3

File tree

5 files changed

+526
-227
lines changed

5 files changed

+526
-227
lines changed

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

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -401,46 +401,64 @@ export class ManagedRunController {
401401
}) satisfies SupervisorSocket;
402402

403403
socket.on("run:notify", async ({ version, run }) => {
404+
// Generate a unique ID for the notification
405+
const notificationId = Math.random().toString(36).substring(2, 15);
406+
407+
// Use this to track the notification incl. any processing
408+
const notification = {
409+
id: notificationId,
410+
runId: run.friendlyId,
411+
version,
412+
};
413+
414+
// Lock this to the current run and snapshot IDs
415+
const controller = {
416+
runFriendlyId: this.runFriendlyId,
417+
snapshotFriendlyId: this.snapshotFriendlyId,
418+
};
419+
404420
this.sendDebugLog({
405421
runId: run.friendlyId,
406422
message: "run:notify received by runner",
407-
properties: { version, runId: run.friendlyId },
423+
properties: {
424+
notification,
425+
controller,
426+
},
408427
});
409428

410-
if (!this.runFriendlyId) {
429+
if (!controller.runFriendlyId) {
411430
this.sendDebugLog({
412431
runId: run.friendlyId,
413432
message: "run:notify: ignoring notification, no local run ID",
414433
properties: {
415-
currentRunId: this.runFriendlyId,
416-
currentSnapshotId: this.snapshotFriendlyId,
434+
notification,
435+
controller,
417436
},
418437
});
419438
return;
420439
}
421440

422-
if (run.friendlyId !== this.runFriendlyId) {
441+
if (run.friendlyId !== controller.runFriendlyId) {
423442
this.sendDebugLog({
424443
runId: run.friendlyId,
425444
message: "run:notify: ignoring notification for different run",
426445
properties: {
427-
currentRunId: this.runFriendlyId,
428-
currentSnapshotId: this.snapshotFriendlyId,
429-
notificationRunId: run.friendlyId,
446+
notification,
447+
controller,
430448
},
431449
});
432450
return;
433451
}
434452

435-
const latestSnapshot = await this.httpClient.getRunExecutionData(this.runFriendlyId);
453+
const latestSnapshot = await this.httpClient.getRunExecutionData(controller.runFriendlyId);
436454

437455
if (!latestSnapshot.success) {
438456
this.sendDebugLog({
439-
runId: this.runFriendlyId,
457+
runId: run.friendlyId,
440458
message: "run:notify: failed to get latest snapshot data",
441459
properties: {
442-
currentRunId: this.runFriendlyId,
443-
currentSnapshotId: this.snapshotFriendlyId,
460+
notification,
461+
controller,
444462
error: latestSnapshot.error,
445463
},
446464
});
@@ -451,19 +469,29 @@ export class ManagedRunController {
451469

452470
if (!this.currentExecution) {
453471
this.sendDebugLog({
454-
runId: runExecutionData.run.friendlyId,
455-
message: "handleSnapshotChange: no current execution",
472+
runId: run.friendlyId,
473+
message: "run:notify: no current execution",
474+
properties: {
475+
notification,
476+
controller,
477+
},
456478
});
457479
return;
458480
}
459481

460-
const [error] = await tryCatch(this.currentExecution.handleSnapshotChange(runExecutionData));
482+
const [error] = await tryCatch(
483+
this.currentExecution.enqueueSnapshotChangeAndWait(runExecutionData)
484+
);
461485

462486
if (error) {
463487
this.sendDebugLog({
464-
runId: runExecutionData.run.friendlyId,
465-
message: "handleSnapshotChange: unexpected error",
466-
properties: { error: error.message },
488+
runId: run.friendlyId,
489+
message: "run:notify: unexpected error",
490+
properties: {
491+
notification,
492+
controller,
493+
error: error.message,
494+
},
467495
});
468496
}
469497
});

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const Env = z.object({
3232
TRIGGER_MACHINE_MEMORY: z.string().default("0"),
3333
TRIGGER_RUNNER_ID: z.string(),
3434
TRIGGER_METADATA_URL: z.string().optional(),
35-
TRIGGER_PRE_SUSPEND_WAIT_MS: z.coerce.number().default(200),
3635

3736
// Timeline metrics
3837
TRIGGER_POD_SCHEDULED_AT_MS: DateEnv,
@@ -119,9 +118,6 @@ export class RunnerEnv {
119118
get TRIGGER_METADATA_URL() {
120119
return this.env.TRIGGER_METADATA_URL;
121120
}
122-
get TRIGGER_PRE_SUSPEND_WAIT_MS() {
123-
return this.env.TRIGGER_PRE_SUSPEND_WAIT_MS;
124-
}
125121
get TRIGGER_POD_SCHEDULED_AT_MS() {
126122
return this.env.TRIGGER_POD_SCHEDULED_AT_MS;
127123
}

0 commit comments

Comments
 (0)