Skip to content

Commit 0a2c090

Browse files
committed
On TaskRunProcess, set max old space and deduplicate the flags with priority order
1 parent 408a42d commit 0a2c090

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/cli-v3/src/executions/taskRunProcess.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ChildProcess, fork } from "node:child_process";
1919
import { chalkError, chalkGrey, chalkRun, prettyPrintDate } from "../utilities/cliOutput.js";
2020

2121
import { execOptionsForRuntime, execPathForRuntime } from "@trigger.dev/core/v3/build";
22+
import { nodeOptionsWithMaxOldSpaceSize } from "@trigger.dev/core/v3/machines";
2223
import { InferSocketMessageSchema } from "@trigger.dev/core/v3/zodSocket";
2324
import { logger } from "../utilities/logger.js";
2425
import {
@@ -117,14 +118,16 @@ export class TaskRunProcess {
117118
}
118119

119120
async initialize() {
120-
const { env: $env, workerManifest, cwd, messageId } = this.options;
121+
const { env: $env, workerManifest, cwd, messageId, payload } = this.options;
122+
123+
const maxOldSpaceSize = nodeOptionsWithMaxOldSpaceSize(undefined, payload.execution.machine);
121124

122125
const fullEnv = {
123126
...(this.isTest ? { TRIGGER_LOG_LEVEL: "debug" } : {}),
124127
...$env,
125128
OTEL_IMPORT_HOOK_INCLUDES: workerManifest.otelImportHook?.include?.join(","),
126129
// TODO: this will probably need to use something different for bun (maybe --preload?)
127-
NODE_OPTIONS: execOptionsForRuntime(workerManifest.runtime, workerManifest),
130+
NODE_OPTIONS: execOptionsForRuntime(workerManifest.runtime, workerManifest, maxOldSpaceSize),
128131
PATH: process.env.PATH,
129132
TRIGGER_PROCESS_FORK_START_TIME: String(Date.now()),
130133
};

packages/core/src/v3/build/runtime.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { join } from "node:path";
22
import { pathToFileURL } from "url";
33
import { BuildRuntime } from "../schemas/build.js";
4+
import { dedupFlags } from "./flags.js";
45

56
export const DEFAULT_RUNTIME = "node" satisfies BuildRuntime;
67

@@ -41,7 +42,11 @@ export type ExecOptions = {
4142
customConditions?: string[];
4243
};
4344

44-
export function execOptionsForRuntime(runtime: BuildRuntime, options: ExecOptions): string {
45+
export function execOptionsForRuntime(
46+
runtime: BuildRuntime,
47+
options: ExecOptions,
48+
additionalNodeOptions?: string
49+
): string {
4550
switch (runtime) {
4651
case "node":
4752
case "node-22": {
@@ -51,15 +56,19 @@ export function execOptionsForRuntime(runtime: BuildRuntime, options: ExecOption
5156

5257
const conditions = options.customConditions?.map((condition) => `--conditions=${condition}`);
5358

54-
return [
59+
//later flags will win (after the dedupe)
60+
const flags = [
61+
process.env.NODE_OPTIONS,
62+
additionalNodeOptions,
5563
importEntryPoint,
5664
conditions,
57-
process.env.NODE_OPTIONS,
5865
nodeRuntimeNeedsGlobalWebCryptoFlag() ? "--experimental-global-webcrypto" : undefined,
5966
]
6067
.filter(Boolean)
6168
.flat()
6269
.join(" ");
70+
71+
return dedupFlags(flags);
6372
}
6473
case "bun": {
6574
return "";

packages/core/src/v3/schemas/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export const TaskRunExecution = z.object({
308308
organization: TaskRunExecutionOrganization,
309309
project: TaskRunExecutionProject,
310310
batch: TaskRunExecutionBatch.optional(),
311-
machine: MachinePreset.optional(),
311+
machine: MachinePreset,
312312
});
313313

314314
export type TaskRunExecution = z.infer<typeof TaskRunExecution>;

0 commit comments

Comments
 (0)