@@ -15,7 +15,11 @@ import {
1515 TaskRunInternalError ,
1616} from "@trigger.dev/core/v3" ;
1717import { TaskRunError } from "@trigger.dev/core/v3/schemas" ;
18- import { RunId , WaitpointId } from "@trigger.dev/core/v3/isomorphic" ;
18+ import {
19+ parseNaturalLanguageDurationInMs ,
20+ RunId ,
21+ WaitpointId ,
22+ } from "@trigger.dev/core/v3/isomorphic" ;
1923import {
2024 Prisma ,
2125 PrismaClient ,
@@ -552,6 +556,9 @@ export class RunEngine {
552556
553557 const status = delayUntil ? "DELAYED" : "PENDING" ;
554558
559+ // Apply defaultMaxTtl: use as default when no TTL is provided, clamp when larger
560+ const resolvedTtl = this . #resolveMaxTtl( ttl ) ;
561+
555562 //create run
556563 let taskRun : TaskRun & { associatedWaitpoint : Waitpoint | null } ;
557564 const taskRunId = RunId . fromFriendlyId ( friendlyId ) ;
@@ -595,7 +602,7 @@ export class RunEngine {
595602 taskEventStore,
596603 priorityMs,
597604 queueTimestamp : queueTimestamp ?? delayUntil ?? new Date ( ) ,
598- ttl,
605+ ttl : resolvedTtl ,
599606 tags :
600607 tags . length === 0
601608 ? undefined
@@ -2265,6 +2272,33 @@ export class RunEngine {
22652272 }
22662273 }
22672274
2275+ /**
2276+ * Applies `defaultMaxTtl` to a run's TTL:
2277+ * - No max configured → pass through as-is.
2278+ * - No TTL on the run → use the max as the default.
2279+ * - Both exist → clamp to the smaller value.
2280+ */
2281+ #resolveMaxTtl( ttl : string | undefined ) : string | undefined {
2282+ const maxTtl = this . options . defaultMaxTtl ;
2283+
2284+ if ( ! maxTtl ) {
2285+ return ttl ;
2286+ }
2287+
2288+ if ( ! ttl ) {
2289+ return maxTtl ;
2290+ }
2291+
2292+ const ttlMs = parseNaturalLanguageDurationInMs ( ttl ) ;
2293+ const maxTtlMs = parseNaturalLanguageDurationInMs ( maxTtl ) ;
2294+
2295+ if ( ttlMs === undefined || maxTtlMs === undefined ) {
2296+ return ttl ;
2297+ }
2298+
2299+ return ttlMs <= maxTtlMs ? ttl : maxTtl ;
2300+ }
2301+
22682302 async #concurrencySweeperCallback(
22692303 runIds : string [ ] ,
22702304 completedAtOffsetMs : number = 1000 * 60 * 10
0 commit comments