Skip to content

Commit 8fd09e3

Browse files
committed
check for env overrides in a few more places and add verbose logs
1 parent 55b835d commit 8fd09e3

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ export class ManagedRunController {
524524
});
525525
});
526526

527-
socket.on("disconnect", (reason, description) => {
527+
socket.on("disconnect", async (reason, description) => {
528528
const parseDescription = ():
529529
| {
530530
description: string;
@@ -547,6 +547,30 @@ export class ManagedRunController {
547547
};
548548
};
549549

550+
if (this.currentExecution) {
551+
const currentEnv = {
552+
workerInstanceName: this.env.TRIGGER_WORKER_INSTANCE_NAME,
553+
runnerId: this.env.TRIGGER_RUNNER_ID,
554+
supervisorApiUrl: this.env.TRIGGER_SUPERVISOR_API_URL,
555+
};
556+
557+
await this.currentExecution.processEnvOverrides("socket disconnected");
558+
559+
const newEnv = {
560+
workerInstanceName: this.env.TRIGGER_WORKER_INSTANCE_NAME,
561+
runnerId: this.env.TRIGGER_RUNNER_ID,
562+
supervisorApiUrl: this.env.TRIGGER_SUPERVISOR_API_URL,
563+
};
564+
565+
this.sendDebugLog({
566+
runId: this.runFriendlyId,
567+
message: "Socket disconnected from supervisor - processed env overrides",
568+
properties: { reason, ...parseDescription(), currentEnv, newEnv },
569+
});
570+
571+
return;
572+
}
573+
550574
this.sendDebugLog({
551575
runId: this.runFriendlyId,
552576
message: "Socket disconnected from supervisor",

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ export class RunExecution {
215215
this.snapshotPoller?.updateSnapshotId(snapshot.friendlyId);
216216
this.snapshotPoller?.resetCurrentInterval();
217217

218+
await this.processEnvOverrides("snapshot change");
219+
218220
switch (snapshot.executionStatus) {
219221
case "PENDING_CANCEL": {
220222
this.sendDebugLog("run was cancelled", snapshotMetadata);
@@ -780,7 +782,7 @@ export class RunExecution {
780782
await sleep(100);
781783

782784
// Process any env overrides
783-
await this.processEnvOverrides();
785+
await this.processEnvOverrides("restore");
784786

785787
const continuationResult = await this.httpClient.continueRunExecution(
786788
this.runFriendlyId,
@@ -798,21 +800,31 @@ export class RunExecution {
798800
/**
799801
* Processes env overrides from the metadata service. Generally called when we're resuming from a suspended state.
800802
*/
801-
private async processEnvOverrides() {
803+
async processEnvOverrides(reason?: string) {
802804
if (!this.env.TRIGGER_METADATA_URL) {
803-
this.sendDebugLog("no metadata url, skipping env overrides");
805+
this.sendDebugLog("no metadata url, skipping env overrides", { reason });
804806
return;
805807
}
806808

807809
const metadataClient = new MetadataClient(this.env.TRIGGER_METADATA_URL);
808810
const overrides = await metadataClient.getEnvOverrides();
809811

810812
if (!overrides) {
811-
this.sendDebugLog("no env overrides, skipping");
813+
this.sendDebugLog("no env overrides, skipping", { reason });
812814
return;
813815
}
814816

815-
this.sendDebugLog("processing env overrides", overrides);
817+
this.sendDebugLog(`processing env overrides: ${reason}`, {
818+
overrides,
819+
currentEnv: this.env.raw,
820+
});
821+
822+
if (this.env.TRIGGER_RUNNER_ID !== overrides.TRIGGER_RUNNER_ID) {
823+
this.sendDebugLog("runner ID changed -> run was restored from a checkpoint", {
824+
currentRunnerId: this.env.TRIGGER_RUNNER_ID,
825+
newRunnerId: overrides.TRIGGER_RUNNER_ID,
826+
});
827+
}
816828

817829
// Override the env with the new values
818830
this.env.override(overrides);

0 commit comments

Comments
 (0)