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
2 changes: 1 addition & 1 deletion packages/cli-v3/src/entryPoints/dev-index-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@trigger.dev/core/v3/workers";
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
import { readFile } from "node:fs/promises";
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
import { registerResources } from "../indexing/registerResources.js";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
Expand Down
33 changes: 21 additions & 12 deletions packages/cli-v3/src/entryPoints/dev-run-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
SharedRuntimeManager,
OtelTaskLogger,
populateEnv,
NO_FILE_CONTEXT,
StandardLifecycleHooksManager,
StandardLocalsManager,
StandardMetadataManager,
Expand All @@ -67,7 +68,7 @@ import {
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
import { readFile } from "node:fs/promises";
import { setInterval, setTimeout } from "node:timers/promises";
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { VERSION } from "../version.js";
Expand Down Expand Up @@ -125,8 +126,9 @@ 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"
})`;

const heartbeatIntervalMs = getEnvVar("HEARTBEAT_INTERVAL_MS");

Expand Down Expand Up @@ -171,7 +173,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 @@ -322,12 +324,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 Expand Up @@ -496,8 +498,8 @@ const zodIpc = new ZodIpcConnection({
async () => {
const beforeImport = performance.now();
resourceCatalog.setCurrentFileContext(
taskManifest.entryPoint,
taskManifest.filePath
taskManifest.filePath,
taskManifest.entryPoint
);

// Load init file if it exists
Expand Down Expand Up @@ -605,6 +607,12 @@ const zodIpc = new ZodIpcConnection({

const signal = AbortSignal.any([_cancelController.signal, timeoutController.signal]);

// Sentinel context so `task()` calls firing during run / lifecycle
// hooks (e.g. via `await import(...)` of a module containing a task
// definition) register normally instead of being silently dropped.
// Cleared in the surrounding finally below.
resourceCatalog.setCurrentFileContext(NO_FILE_CONTEXT, NO_FILE_CONTEXT);

const { result } = await executor.execute(execution, ctx, signal);

if (_isRunning && !_isCancelled) {
Expand All @@ -623,6 +631,7 @@ const zodIpc = new ZodIpcConnection({
}
} finally {
standardHeartbeatsManager.stopHeartbeat();
resourceCatalog.clearCurrentFileContext();

_execution = undefined;
_isRunning = false;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-v3/src/entryPoints/managed-index-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "@trigger.dev/core/v3/workers";
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
import { readFile } from "node:fs/promises";
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
import { registerResources } from "../indexing/registerResources.js";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
Expand Down Expand Up @@ -190,8 +190,8 @@ await sendMessageInCatalog(
typeof processKeepAlive === "object"
? processKeepAlive
: typeof processKeepAlive === "boolean"
? { enabled: processKeepAlive }
: undefined,
? { enabled: processKeepAlive }
: undefined,
timings,
},
importErrors,
Expand Down
28 changes: 18 additions & 10 deletions packages/cli-v3/src/entryPoints/managed-run-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
OtelTaskLogger,
populateEnv,
ProdUsageManager,
NO_FILE_CONTEXT,
StandardLifecycleHooksManager,
StandardLocalsManager,
StandardMetadataManager,
Expand All @@ -67,7 +68,7 @@ import {
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
import { readFile } from "node:fs/promises";
import { setInterval, setTimeout } from "node:timers/promises";
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
import { env } from "std-env";
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
import { VERSION } from "../version.js";
Expand Down Expand Up @@ -145,7 +146,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 @@ -298,12 +299,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 Expand Up @@ -486,8 +487,8 @@ const zodIpc = new ZodIpcConnection({
async () => {
const beforeImport = performance.now();
resourceCatalog.setCurrentFileContext(
taskManifest.entryPoint,
taskManifest.filePath
taskManifest.filePath,
taskManifest.entryPoint
);

// Load init file if it exists
Expand Down Expand Up @@ -591,6 +592,12 @@ const zodIpc = new ZodIpcConnection({

const signal = AbortSignal.any([_cancelController.signal, timeoutController.signal]);

// Sentinel context so `task()` calls firing during run / lifecycle
// hooks (e.g. via `await import(...)` of a module containing a task
// definition) register normally instead of being silently dropped.
// Cleared in the surrounding finally below.
resourceCatalog.setCurrentFileContext(NO_FILE_CONTEXT, NO_FILE_CONTEXT);

const { result } = await executor.execute(execution, ctx, signal);

if (_isRunning && !_isCancelled) {
Expand All @@ -609,6 +616,7 @@ const zodIpc = new ZodIpcConnection({
}
} finally {
standardHeartbeatsManager.stopHeartbeat();
resourceCatalog.clearCurrentFileContext();

_execution = undefined;
_isRunning = false;
Expand Down
32 changes: 32 additions & 0 deletions packages/cli-v3/src/utilities/installSourceMapSupport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sourceMapSupport from "source-map-support";

/**
* Installs source-map-support with a workaround for Bun's source map handling.
*
* Bun's runtime can produce source maps with column values of -1, which causes
* source-map@0.6.1 (used by source-map-support) to throw:
* "Column must be greater than or equal to 0, got -1"
*
* This wraps the prepareStackTrace hook so that if source map processing fails,
* it falls back to default stack trace formatting instead of crashing.
*
* See: https://github.com/oven-sh/bun/issues/8087
*/
export function installSourceMapSupport() {
sourceMapSupport.install({
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This always installs source-map-support and drops existing TRIGGER_SOURCE_MAPS runtime controls (false, 0, node), which changes configured behavior in worker entrypoints.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli-v3/src/utilities/installSourceMapSupport.ts, line 16:

<comment>This always installs source-map-support and drops existing `TRIGGER_SOURCE_MAPS` runtime controls (`false`, `0`, `node`), which changes configured behavior in worker entrypoints.</comment>

<file context>
@@ -0,0 +1,32 @@
+ * See: https://github.com/oven-sh/bun/issues/8087
+ */
+export function installSourceMapSupport() {
+  sourceMapSupport.install({
+    handleUncaughtExceptions: false,
+    environment: "node",
</file context>

handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});

const _prepareStackTrace = (Error as any).prepareStackTrace;
if (_prepareStackTrace) {
(Error as any).prepareStackTrace = (error: Error, stackTraces: NodeJS.CallSite[]) => {
try {
return _prepareStackTrace(error, stackTraces);
} catch {
return error + "\n" + stackTraces.map((s) => " at " + s).join("\n");
}
};
}
}
Loading