-
-
Notifications
You must be signed in to change notification settings - Fork 988
fix(cli-v3): allow disabling source-map-support to prevent OOM with Sentry #2989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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(); | ||||||||
|
|
||||||||
| process.on("uncaughtException", function (error, origin) { | ||||||||
| logError("Uncaught exception", { error, origin }); | ||||||||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 The template literal on lines 104-105 preserves the newline and two spaces before 🔧 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
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| const heartbeatIntervalMs = getEnvVar("HEARTBEAT_INTERVAL_MS"); | ||||||||
|
|
||||||||
|
|
@@ -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); | ||||||||
|
|
||||||||
|
|
@@ -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() { | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Click to expandMissing imports and their usages:
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";Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| process.on("uncaughtException", function (error, origin) { | ||
| console.error("Uncaught exception", { error, origin }); | ||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -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() { | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 -5Repository: 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 -5Repository: 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 -100Repository: triggerdotdev/trigger.dev Length of output: 3907 🏁 Script executed: cat -n ./packages/cli-v3/src/utilities/sourceMaps.tsRepository: 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 -10Repository: 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 -80Repository: 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 -50Repository: 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 -5Repository: 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 -10Repository: 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 -10Repository: 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 Refactor 🤖 Prompt for AI Agents |
||
| }); | ||
| 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, | ||
| }); | ||
| } |
There was a problem hiding this comment.
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, andpromiseWithResolversfromdev-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:
env(fromstd-env) - used at lines 180, 197, 201:normalizeImportPath(from../utilities/normalizeImportPath.js) - used at lines 169, 457, 465:VERSION(from../version.js) - used at lines 206, 207:promiseWithResolvers(from@trigger.dev/core/utils) - used at line 637: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:
Was this helpful? React with 👍 or 👎 to provide feedback.