You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: Sentry debug ID injection causes OOM during module loading #2920
Sentry's debug ID injection (sentry-cli sourcemaps inject) adds new Error().stack calls to every bundled .mjs file.
Trigger.dev's source-map-support library parses sourcemaps on every .stack access. This causes all sourcemaps to be parsed during module loading, leading to OOM before any task code runs.
Affects large projects (e.g., ~2000+ bundled files) on smaller machines like small-1x.
Reproduction repo
n/a
To reproduce
Deploy a project with many bundled files to Trigger.dev
Enable Sentry debug ID injection: sentry-cli sourcemaps inject --ext mjs
Use small-1x machine (0.5GB RAM)
Trigger any task
Task fails with OOM before execution
Workaround: Skip sourcemaps inject step, rely on release-based sourcemap matching.
The issue is a specific interaction between Sentry's debug ID injection and source-map-support:
Sentry's sourcemaps inject adds new Error().stack calls to every bundled .mjs file for debug ID mapping
source-map-support hooks Error.prepareStackTrace - meaning every .stack access triggers sourcemap parsing
During module loading, Sentry's injected code executes new Error().stack
This causes all sourcemaps to be parsed synchronously during the import phase - before any task code runs
For large projects (~2000+ files), this creates a massive memory spike that exceeds small-1x (0.5GB RAM)
Key insight: While source-map-support is designed to be lazy (only parsing on actual errors), Sentry's injection turns every module import into an "error stack access" event.
Proposed Solutions
Option 1: Add config option to disable source-map-support (Recommended)
Add a new runtime.sourceMapSupport config option to TriggerConfig:
// In packages/core/src/v3/config.tsexporttypeTriggerConfig={// ...runtime?: {/** * Enable source-map-support for better stack traces. * Set to false if using tools that access Error.stack during module loading * (e.g., Sentry debug ID injection), which can cause OOM on memory-constrained machines. * * @default true */sourceMapSupport?: boolean;};};
Then conditionally install in worker entry points:
// In entryPoints/*-worker.tsif(config?.runtime?.sourceMapSupport!==false){sourceMapSupport.install({handleUncaughtExceptions: false,environment: "node",hookRequire: false,});}
Use a custom retrieveSourceMap callback that defers parsing until an actual error handler requests it:
sourceMapSupport.install({handleUncaughtExceptions: false,environment: "node",hookRequire: false,retrieveSourceMap: (source)=>{// Only parse sourcemaps when explicitly needed (e.g., uncaught exception handlers)if(!shouldParseSourceMaps()){returnnull;}// Default behaviorreturnundefined;},});
Pros: Preserves stack traces for real errors, prevents OOM during loading Cons: More complex, needs careful implementation to track "real" vs "synthetic" stack access
Option 3: Environment variable toggle (Quick fix)
Add TRIGGER_DISABLE_SOURCE_MAP_SUPPORT=1 env var check:
Activity
ericallam commentedon Jan 21, 2026
@claude
claude commentedon Jan 21, 2026
Claude finished @ericallam's task in 3m 17s —— View job
Analysis Complete
Root Cause Analysis
The issue is a specific interaction between Sentry's debug ID injection and
source-map-support:sourcemaps injectaddsnew Error().stackcalls to every bundled.mjsfile for debug ID mappingsource-map-supporthooksError.prepareStackTrace- meaning every.stackaccess triggers sourcemap parsingnew Error().stacksmall-1x(0.5GB RAM)Key insight: While
source-map-supportis designed to be lazy (only parsing on actual errors), Sentry's injection turns every module import into an "error stack access" event.Proposed Solutions
Option 1: Add config option to disable source-map-support (Recommended)
Add a new
runtime.sourceMapSupportconfig option toTriggerConfig:Then conditionally install in worker entry points:
Pros: Simple, user-controlled, no performance impact
Cons: Users lose source-mapped stack traces
Option 2: Lazy/deferred sourcemap parsing
Use a custom
retrieveSourceMapcallback that defers parsing until an actual error handler requests it:Pros: Preserves stack traces for real errors, prevents OOM during loading
Cons: More complex, needs careful implementation to track "real" vs "synthetic" stack access
Option 3: Environment variable toggle (Quick fix)
Add
TRIGGER_DISABLE_SOURCE_MAP_SUPPORT=1env var check:Pros: Immediate fix, no config schema changes
Cons: Less discoverable, not as clean
Recommendation
I'd suggest implementing Option 1 (config option) as the primary solution, with Option 3 (env var) as a quick workaround users can use immediately.
Would you like me to implement one of these solutions?
ericallam commentedon Jan 21, 2026
@claude could you investigate option 2 first and event see if thats possible?
claude commentedon Jan 21, 2026
Claude finished @ericallam's task in 5m 46s —— View job
Investigation Complete: Lazy Sourcemap Parsing (Option 2)
source-map-supportworks and its APISummary
Yes, Option 2 (lazy/deferred sourcemap parsing) is feasible.
The most practical approach is Phase-Based Deferred Parsing: skip sourcemap parsing during module loading, enable it once bootstrap completes.
How it works:
Why this works:
new Error().stackcalls return unmapped stacks (fast, no memory pressure)Why V8 can't distinguish "synthetic" vs "real" errors:
Error.prepareStackTraceis called identically for both.stackaccessedFiles to modify:
packages/cli-v3/src/entryPoints/managed-run-worker.tspackages/cli-v3/src/entryPoints/dev-run-worker.tspackages/cli-v3/src/entryPoints/managed-index-worker.tspackages/cli-v3/src/entryPoints/dev-index-worker.tsLet me know if you'd like me to implement this!
ericallam commentedon Jan 21, 2026
@claude implement this and please create a reference project as well to test this
claude commentedon Jan 21, 2026
Claude finished @ericallam's task in 6m 31s —— View job •
claude/issue-2920-20260121-0712• Create PR ➔Implementation Complete
Summary
Implemented phase-based deferred sourcemap parsing to fix OOM during module loading when using Sentry's debug ID injection.
Changes:
New utility module (
packages/cli-v3/src/entryPoints/deferredSourceMapSupport.ts):installDeferredSourceMapSupport()- Installs source-map-support with a customretrieveSourceMapcallback that returnsnullduring loading phaseenableSourceMapSupport()- Enables sourcemap parsing after bootstrap completesUpdated worker entry points:
managed-run-worker.ts- Uses deferred sourcemap support, enables after bootstrapdev-run-worker.ts- Uses deferred sourcemap support, enables after bootstrapmanaged-index-worker.ts- Uses deferred sourcemap support, enables after bootstrapdev-index-worker.ts- Uses deferred sourcemap support, enables after bootstrapNew reference project (
references/sentry-sourcemap-oom/):new Error().stackcalled during import (like Sentry does)How it works:
retrieveSourceMapreturnsnull, skipping all sourcemap parsingfalse, enabling normal sourcemap retrievalTrade-off: Import errors won't have source-mapped stack traces, but bundler messages are usually sufficient for those cases.
--- |
fix(cli): defer sourcemap parsing to prevent OOM during module loading
fix(cli-v3): allow disabling source-map-support to prevent OOM with S…