77 parsePacket ,
88 TaskRunErrorCodes ,
99} from "@trigger.dev/core/v3" ;
10- import { BatchId , RunId } from "@trigger.dev/core/v3/isomorphic" ;
10+ import { BatchId } from "@trigger.dev/core/v3/isomorphic" ;
1111import { type BatchTaskRun , Prisma } from "@trigger.dev/database" ;
1212import { Evt } from "evt" ;
1313import { z } from "zod" ;
@@ -28,6 +28,7 @@ import type { RunEngine } from "../../v3/runEngine.server";
2828import { ServiceValidationError , WithRunEngine } from "../../v3/services/baseService.server" ;
2929import { TriggerTaskService } from "../../v3/services/triggerTask.server" ;
3030import { startActiveSpan } from "../../v3/tracer.server" ;
31+ import { resolveBatchParentRun } from "./resolveBatchParentRun.server" ;
3132import { TriggerFailedTaskService } from "./triggerFailedTask.server" ;
3233
3334const PROCESSING_BATCH_SIZE = 50 ;
@@ -90,6 +91,13 @@ export class RunEngineBatchTriggerService extends WithRunEngine {
9091 "call()" ,
9192 environment ,
9293 async ( span ) => {
94+ const parentRunInternalId = await resolveBatchParentRun ( {
95+ runStore : this . _engine . runStore ,
96+ environmentId : environment . id ,
97+ parentRunId : body . parentRunId ,
98+ resumeParentOnCompletion : body . resumeParentOnCompletion ,
99+ } ) ;
100+
93101 const { friendlyId } = await mintBatchFriendlyId ( {
94102 environment : {
95103 organizationId : environment . organizationId ,
@@ -112,7 +120,8 @@ export class RunEngineBatchTriggerService extends WithRunEngine {
112120 payloadPacket ,
113121 environment ,
114122 body ,
115- options
123+ options ,
124+ parentRunInternalId
116125 ) ;
117126
118127 if ( ! batch ) {
@@ -165,7 +174,8 @@ export class RunEngineBatchTriggerService extends WithRunEngine {
165174 payloadPacket : IOPacket ,
166175 environment : AuthenticatedEnvironment ,
167176 body : BatchTriggerTaskV2RequestBody ,
168- options : BatchTriggerTaskServiceOptions = { }
177+ options : BatchTriggerTaskServiceOptions = { } ,
178+ parentRunInternalId ?: string
169179 ) {
170180 // BatchTaskRun.runtimeEnvironmentId no longer has an FK into RuntimeEnvironment;
171181 // validate env existence app-side (covers both create arms below).
@@ -187,9 +197,9 @@ export class RunEngineBatchTriggerService extends WithRunEngine {
187197
188198 this . onBatchTaskRunCreated . post ( batch ) ;
189199
190- if ( body . parentRunId && body . resumeParentOnCompletion ) {
200+ if ( parentRunInternalId ) {
191201 await this . _engine . blockRunWithCreatedBatch ( {
192- runId : RunId . fromFriendlyId ( body . parentRunId ) ,
202+ runId : parentRunInternalId ,
193203 batchId : batch . id ,
194204 environmentId : environment . id ,
195205 projectId : environment . projectId ,
@@ -278,9 +288,9 @@ export class RunEngineBatchTriggerService extends WithRunEngine {
278288
279289 this . onBatchTaskRunCreated . post ( batch ) ;
280290
281- if ( body . parentRunId && body . resumeParentOnCompletion ) {
291+ if ( parentRunInternalId ) {
282292 await this . _engine . blockRunWithCreatedBatch ( {
283- runId : RunId . fromFriendlyId ( body . parentRunId ) ,
293+ runId : parentRunInternalId ,
284294 batchId : batch . id ,
285295 environmentId : environment . id ,
286296 projectId : environment . projectId ,
0 commit comments