Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/fix-sentry-oom-2920.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/cli-v3": patch
---

Fix Sentry OOM: Allow disabling `source-map-support` via `TRIGGER_SOURCE_MAPS=false`. Also supports `node` for native source maps. (#2920)
8 changes: 2 additions & 6 deletions packages/cli-v3/src/entryPoints/dev-index-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ import {
} from "@trigger.dev/core/v3/workers";
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
import { readFile } from "node:fs/promises";
import sourceMapSupport from "source-map-support";
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
import { registerResources } from "../indexing/registerResources.js";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";

sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
installSourceMapSupport();

process.on("uncaughtException", function (error, origin) {
if (error instanceof Error) {
Expand Down
33 changes: 12 additions & 21 deletions packages/cli-v3/src/entryPoints/dev-run-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,9 @@ import {
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
import { readFile } from "node:fs/promises";
import { setInterval, setTimeout } from "node:timers/promises";
import sourceMapSupport from "source-map-support";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { VERSION } from "../version.js";
import { promiseWithResolvers } from "@trigger.dev/core/utils";

sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
import { installSourceMapSupport } from "../utilities/sourceMaps.js";

installSourceMapSupport();
Comment on lines +66 to +68

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Missing imports in dev-run-worker.ts cause runtime errors

The PR removed import statements for env, normalizeImportPath, VERSION, and promiseWithResolvers from dev-run-worker.ts, but these symbols are still used in the code, causing undefined reference errors at runtime.

Click to expand

Missing imports and their usages:

  1. env (from std-env) - used at lines 180, 197, 201:

    const manifestContents = await readFile(env.TRIGGER_WORKER_MANIFEST_PATH!, "utf-8");
    url: env.TRIGGER_OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318",
    diagLogLevel: (env.TRIGGER_OTEL_LOG_LEVEL as TracingDiagnosticLogLevel) ?? "none",
  2. normalizeImportPath (from ../utilities/normalizeImportPath.js) - used at lines 169, 457, 465:

    const configModule = await import(normalizeImportPath(configPath));
    await import(normalizeImportPath(workerManifest.initEntryPoint));
    await import(normalizeImportPath(taskManifest.entryPoint));
  3. VERSION (from ../version.js) - used at lines 206, 207:

    const otelTracer: Tracer = tracingSDK.getTracer("trigger-dev-worker", VERSION);
    const otelLogger: Logger = tracingSDK.getLogger("trigger-dev-worker", VERSION);
  4. promiseWithResolvers (from @trigger.dev/core/utils) - used at line 637:

    const { promise, resolve } = promiseWithResolvers<void>();

Impact:

The dev worker will crash immediately when it tries to access these undefined symbols, preventing any task execution in development environments.

Recommendation: Add back the missing imports:

import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { VERSION } from "../version.js";
import { promiseWithResolvers } from "@trigger.dev/core/utils";
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


process.on("uncaughtException", function (error, origin) {
logError("Uncaught exception", { error, origin });
Expand Down Expand Up @@ -109,9 +101,8 @@ process.on("uncaughtException", function (error, origin) {
}
});

process.title = `trigger-dev-run-worker (${
getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"
})`;
process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"
})`;
Comment on lines +104 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n packages/cli-v3/src/entryPoints/dev-run-worker.ts | sed -n '100,110p'

Repository: triggerdotdev/trigger.dev

Length of output: 453


Remove the newline and indentation from the process.title template literal.

The template literal on lines 104-105 preserves the newline and two spaces before }), which will be included literally in the process title string, resulting in an unintended multiline title. Keep the closing brace on the same line as the template expression.

🔧 Suggested fix
-process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"
-  })`;
+process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"})`;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"
})`;
process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"})`;
🤖 Prompt for AI Agents
In `@packages/cli-v3/src/entryPoints/dev-run-worker.ts` around lines 104 - 105,
The process.title assignment uses a template literal that includes a newline and
spaces before the closing "})", producing an unintended multiline process title;
fix this in the process.title = `trigger-dev-run-worker
(${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"})`; statement by
moving the closing brace and backtick onto the same line as the template
expression so no newline or extra spaces are included (locate the assignment to
process.title and the getEnvVar call to update).


const heartbeatIntervalMs = getEnvVar("HEARTBEAT_INTERVAL_MS");

Expand Down Expand Up @@ -156,7 +147,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager(
apiClientManager.clientOrThrow(),
getEnvVar("TRIGGER_STREAM_URL", getEnvVar("TRIGGER_API_URL")) ?? "https://api.trigger.dev",
(getEnvVar("TRIGGER_STREAMS_DEBUG") === "1" || getEnvVar("TRIGGER_STREAMS_DEBUG") === "true") ??
false
false
);
realtimeStreams.setGlobalManager(standardRealtimeStreamsManager);

Expand Down Expand Up @@ -285,12 +276,12 @@ async function doBootstrap() {

let bootstrapCache:
| {
tracer: TriggerTracer;
tracingSDK: TracingSDK;
consoleInterceptor: ConsoleInterceptor;
config: TriggerConfig;
workerManifest: WorkerManifest;
}
tracer: TriggerTracer;
tracingSDK: TracingSDK;
consoleInterceptor: ConsoleInterceptor;
config: TriggerConfig;
workerManifest: WorkerManifest;
}
| undefined;

async function bootstrap() {
Expand Down
12 changes: 4 additions & 8 deletions packages/cli-v3/src/entryPoints/managed-index-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ import {
} from "@trigger.dev/core/v3/workers";
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
import { readFile } from "node:fs/promises";
import sourceMapSupport from "source-map-support";
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
import { registerResources } from "../indexing/registerResources.js";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";

sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
installSourceMapSupport();

process.on("uncaughtException", function (error, origin) {
if (error instanceof Error) {
Expand Down Expand Up @@ -168,8 +164,8 @@ await sendMessageInCatalog(
typeof processKeepAlive === "object"
? processKeepAlive
: typeof processKeepAlive === "boolean"
? { enabled: processKeepAlive }
: undefined,
? { enabled: processKeepAlive }
: undefined,
timings,
},
importErrors,
Expand Down
28 changes: 10 additions & 18 deletions packages/cli-v3/src/entryPoints/managed-run-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,9 @@ import {
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
import { readFile } from "node:fs/promises";
import { setInterval, setTimeout } from "node:timers/promises";
import sourceMapSupport from "source-map-support";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { VERSION } from "../version.js";
import { promiseWithResolvers } from "@trigger.dev/core/utils";

sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
import { installSourceMapSupport } from "../utilities/sourceMaps.js";

installSourceMapSupport();
Comment on lines +66 to +68

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Missing imports in managed-run-worker.ts cause runtime errors

The PR removed import statements for env, normalizeImportPath, VERSION, and promiseWithResolvers from managed-run-worker.ts, but these symbols are still used in the code, causing undefined reference errors at runtime.

Click to expand

Missing imports and their usages:

  1. env (from std-env) - used at lines 177, 179:

    url: env.TRIGGER_OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318",
    diagLogLevel: (env.TRIGGER_OTEL_LOG_LEVEL as TracingDiagnosticLogLevel) ?? "none",
  2. normalizeImportPath (from ../utilities/normalizeImportPath.js) - used at lines 173, 449, 457:

    const { config, handleError } = await importConfig(normalizeImportPath(workerManifest.configPath));
    await import(normalizeImportPath(workerManifest.initEntryPoint));
    await import(normalizeImportPath(taskManifest.entryPoint));
  3. VERSION (from ../version.js) - used at lines 186, 187:

    const otelTracer: Tracer = tracingSDK.getTracer("trigger-dev-worker", VERSION);
    const otelLogger: Logger = tracingSDK.getLogger("trigger-dev-worker", VERSION);
  4. promiseWithResolvers (from @trigger.dev/core/utils) - used at line 626:

    const { promise, resolve } = promiseWithResolvers<void>();

Impact:

The managed worker will crash immediately when it tries to access these undefined symbols, preventing any task execution in production environments.

Recommendation: Add back the missing imports:

import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { VERSION } from "../version.js";
import { promiseWithResolvers } from "@trigger.dev/core/utils";
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


process.on("uncaughtException", function (error, origin) {
console.error("Uncaught exception", { error, origin });
Expand Down Expand Up @@ -136,7 +128,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager(
apiClientManager.clientOrThrow(),
getEnvVar("TRIGGER_STREAM_URL", getEnvVar("TRIGGER_API_URL")) ?? "https://api.trigger.dev",
(getEnvVar("TRIGGER_STREAMS_DEBUG") === "1" || getEnvVar("TRIGGER_STREAMS_DEBUG") === "true") ??
false
false
);
realtimeStreams.setGlobalManager(standardRealtimeStreamsManager);

Expand Down Expand Up @@ -262,12 +254,12 @@ async function doBootstrap() {

let bootstrapCache:
| {
tracer: TriggerTracer;
tracingSDK: TracingSDK;
consoleInterceptor: ConsoleInterceptor;
config: TriggerConfig;
workerManifest: WorkerManifest;
}
tracer: TriggerTracer;
tracingSDK: TracingSDK;
consoleInterceptor: ConsoleInterceptor;
config: TriggerConfig;
workerManifest: WorkerManifest;
}
| undefined;

async function bootstrap() {
Expand Down
62 changes: 62 additions & 0 deletions packages/cli-v3/src/utilities/sourceMaps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import sourceMapSupport from "source-map-support";
import { installSourceMapSupport } from "./sourceMaps.js";

vi.mock("source-map-support", () => ({
default: {
install: vi.fn(),
},
}));

describe("installSourceMapSupport", () => {
const originalEnv = process.env;
const originalSetSourceMapsEnabled = process.setSourceMapsEnabled;

beforeEach(() => {
vi.clearAllMocks();
process.env = { ...originalEnv };
// Mock setSourceMapsEnabled if it doesn't exist (Node < 16.6) or restore it
process.setSourceMapsEnabled = vi.fn();
});

afterEach(() => {
process.env = originalEnv;
process.setSourceMapsEnabled = originalSetSourceMapsEnabled;
});

it("should install source-map-support by default (undefined env var)", () => {
delete process.env.TRIGGER_SOURCE_MAPS;
installSourceMapSupport();
expect(sourceMapSupport.install).toHaveBeenCalledWith({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
});

it("should install source-map-support if env var is 'true'", () => {
process.env.TRIGGER_SOURCE_MAPS = "true";
installSourceMapSupport();
expect(sourceMapSupport.install).toHaveBeenCalled();
});

it("should NOT install source-map-support if env var is 'false'", () => {
process.env.TRIGGER_SOURCE_MAPS = "false";
installSourceMapSupport();
expect(sourceMapSupport.install).not.toHaveBeenCalled();
});

it("should NOT install source-map-support if env var is '0'", () => {
process.env.TRIGGER_SOURCE_MAPS = "0";
installSourceMapSupport();
expect(sourceMapSupport.install).not.toHaveBeenCalled();
});

it("should enable native node source maps if env var is 'node'", () => {
process.env.TRIGGER_SOURCE_MAPS = "node";
installSourceMapSupport();
expect(sourceMapSupport.install).not.toHaveBeenCalled();
expect(process.setSourceMapsEnabled).toHaveBeenCalledWith(true);
});
Comment on lines +2 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find and read the source file being tested
find . -path "*packages/cli-v3/src/utilities/sourceMaps.ts" -o -path "*packages/cli-v3/src/utilities/sourceMaps.js" | head -5

Repository: triggerdotdev/trigger.dev

Length of output: 114


🏁 Script executed:

# Check the full CLAUDE.md and AGENTS.md for context on mocking policy
find . -name "CLAUDE.md" -o -name "AGENTS.md" | head -5

Repository: triggerdotdev/trigger.dev

Length of output: 92


🏁 Script executed:

# Search for any mocking guidance in documentation files
rg "mock|testcontainers" --type md -A 3 -B 1 | head -100

Repository: triggerdotdev/trigger.dev

Length of output: 3907


🏁 Script executed:

cat -n ./packages/cli-v3/src/utilities/sourceMaps.ts

Repository: triggerdotdev/trigger.dev

Length of output: 751


🏁 Script executed:

# Check if there are any other test files in the repo that mock third-party libraries to understand the policy scope
rg "vi\.mock|vi\.spyOn" --type ts -l packages/ | head -10

Repository: triggerdotdev/trigger.dev

Length of output: 286


🏁 Script executed:

# Check one of these other test files to see if they also mock, and if so, whether this is a systemic issue or expected
cat -n packages/core/src/v3/serverOnly/shutdownManager.test.ts | head -80

Repository: triggerdotdev/trigger.dev

Length of output: 3373


🏁 Script executed:

# Search for any tests that DON'T mock to understand how they structure tests for external dependencies
rg "describe\(" packages/cli-v3/src/utilities/sourceMaps.test.ts -A 30 | head -50

Repository: triggerdotdev/trigger.dev

Length of output: 1179


🏁 Script executed:

# Check if there are any recent commits or guidance about this specific test file
git log --oneline packages/cli-v3/src/utilities/sourceMaps.test.ts | head -5

Repository: triggerdotdev/trigger.dev

Length of output: 160


🏁 Script executed:

# Check if there are any tests in the repo that test source-map behavior without mocking
rg "source-map|sourceMap" --type ts packages/ | grep -E "\.test\.|\.spec\." | head -10

Repository: triggerdotdev/trigger.dev

Length of output: 1205


🏁 Script executed:

# Look for any test files that might show patterns for testing environment-dependent code
rg "process\.env" --type ts packages/*/src/**/*.test.ts | head -10

Repository: triggerdotdev/trigger.dev

Length of output: 820


Remove all mocking from this test file; this violates the repository's explicit "never mock anything" policy.

The test uses vi.mock("source-map-support") and vi.fn() to stub process.setSourceMapsEnabled, which directly contradicts the repository's documented testing standards. Per CLAUDE.md and ai/references/tests.md, mocking, spying, and stubbing are forbidden in tests.

Refactor installSourceMapSupport to be more testable without mocks—for example, by extracting the logic into separate, pure functions that can be tested with real values, or by redesigning the function to accept dependencies as parameters. Alternatively, if testing the actual behavior of source-map-support is necessary, consider writing an integration test that exercises the real module without mocks.

🤖 Prompt for AI Agents
In `@packages/cli-v3/src/utilities/sourceMaps.test.ts` around lines 2 - 61, The
tests violate the no-mocking policy: remove vi.mock("source-map-support") and
any vi.fn() stubs for process.setSourceMapsEnabled from
packages/cli-v3/src/utilities/sourceMaps.test.ts and instead refactor
installSourceMapSupport to accept its dependencies (e.g., a sourceMapSupport
object with an install method and an optional setSourceMapsEnabled function) or
to expose pure helper functions for the decision logic; update the tests to call
those pure functions or pass real dependency objects (or use an integration test
hitting the real source-map-support) and assert behavior without creating mocks
or spies against source-map-support or process.setSourceMapsEnabled.

});
22 changes: 22 additions & 0 deletions packages/cli-v3/src/utilities/sourceMaps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sourceMapSupport from "source-map-support";

export function installSourceMapSupport() {
const sourceMaps = process.env.TRIGGER_SOURCE_MAPS;

if (sourceMaps === "false" || sourceMaps === "0") {
return;
}

if (sourceMaps === "node") {
if (process.setSourceMapsEnabled) {
process.setSourceMapsEnabled(true);
}
return;
}

sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
}