Skip to content

Exit the process if status is finished and not in the middle of completing #2378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/cli-v3/src/entryPoints/managed/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export class RunExecution {
private isShuttingDown = false;
private shutdownReason?: string;

private isCompletingRun = false;

private supervisorSocket: SupervisorSocket;
private notifier?: RunNotifier;
private metadataClient?: MetadataClient;
Expand Down Expand Up @@ -292,7 +294,13 @@ export class RunExecution {
case "FINISHED": {
this.sendDebugLog("run is finished", snapshotMetadata);

// This can sometimes be called before the handleCompletionResult, so we don't need to do anything here
// We are finishing the run in handleCompletionResult, so we don't need to do anything here
if (this.isCompletingRun) {
this.sendDebugLog("run is finished but we're completing it, skipping", snapshotMetadata);
return;
}

await this.exitTaskRunProcessWithoutFailingRun({ flush: true, reason: "re-queued" });
return;
}
case "QUEUED_EXECUTING":
Expand Down Expand Up @@ -377,6 +385,9 @@ export class RunExecution {
throw new Error("Cannot start attempt: missing run or snapshot manager");
}

// Reset this for the new attempt
this.isCompletingRun = false;

this.sendDebugLog("starting attempt", { isWarmStart: String(isWarmStart) });

const attemptStartedAt = Date.now();
Expand Down Expand Up @@ -655,6 +666,8 @@ export class RunExecution {
throw new Error("cannot complete run: missing run or snapshot manager");
}

this.isCompletingRun = true;

const completionResult = await this.httpClient.completeRunAttempt(
this.runFriendlyId,
this.snapshotManager.snapshotId,
Expand Down