@@ -41,7 +41,12 @@ import { runStatusFromError, ServiceValidationError } from "../errors.js";
41
41
import { sendNotificationToWorker } from "../eventBus.js" ;
42
42
import { getMachinePreset , machinePresetFromName } from "../machinePresets.js" ;
43
43
import { retryOutcomeFromCompletion } from "../retrying.js" ;
44
- import { isExecuting , isInitialState } from "../statuses.js" ;
44
+ import {
45
+ isExecuting ,
46
+ isFinishedOrPendingFinished ,
47
+ isInitialState ,
48
+ isPendingExecuting ,
49
+ } from "../statuses.js" ;
45
50
import { RunEngineOptions } from "../types.js" ;
46
51
import { BatchSystem } from "./batchSystem.js" ;
47
52
import { DelayedRunSystem } from "./delayedRunSystem.js" ;
@@ -345,8 +350,8 @@ export class RunAttemptSystem {
345
350
span . setAttribute ( "taskRunId" , taskRun . id ) ;
346
351
span . setAttribute ( "taskRunFriendlyId" , taskRun . friendlyId ) ;
347
352
348
- if ( taskRun . status === "CANCELED" ) {
349
- throw new ServiceValidationError ( "Task run is cancelled " , 400 ) ;
353
+ if ( isFinishedOrPendingFinished ( latestSnapshot . executionStatus ) ) {
354
+ throw new ServiceValidationError ( "Task run is already finished " , 400 ) ;
350
355
}
351
356
352
357
if ( ! taskRun . lockedById ) {
@@ -1321,7 +1326,10 @@ export class RunAttemptSystem {
1321
1326
} ) ;
1322
1327
1323
1328
//if executing, we need to message the worker to cancel the run and put it into `PENDING_CANCEL` status
1324
- if ( isExecuting ( latestSnapshot . executionStatus ) ) {
1329
+ if (
1330
+ isExecuting ( latestSnapshot . executionStatus ) ||
1331
+ isPendingExecuting ( latestSnapshot . executionStatus )
1332
+ ) {
1325
1333
const newSnapshot = await this . executionSnapshotSystem . createExecutionSnapshot ( prisma , {
1326
1334
run,
1327
1335
snapshot : {
0 commit comments