@@ -47,6 +47,7 @@ import {
4747 SharedRuntimeManager ,
4848 OtelTaskLogger ,
4949 populateEnv ,
50+ NO_FILE_CONTEXT ,
5051 StandardLifecycleHooksManager ,
5152 StandardLocalsManager ,
5253 StandardMetadataManager ,
@@ -67,7 +68,7 @@ import {
6768import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc" ;
6869import { readFile } from "node:fs/promises" ;
6970import { setInterval , setTimeout } from "node:timers/promises" ;
70- import { installSourceMapSupport } from "../utilities/sourceMaps .js" ;
71+ import { installSourceMapSupport } from "../utilities/installSourceMapSupport .js" ;
7172import { env } from "std-env" ;
7273import { normalizeImportPath } from "../utilities/normalizeImportPath.js" ;
7374import { VERSION } from "../version.js" ;
@@ -125,8 +126,9 @@ process.on("uncaughtException", function (error, origin) {
125126 }
126127} ) ;
127128
128- process . title = `trigger-dev-run-worker (${ getEnvVar ( "TRIGGER_WORKER_VERSION" ) ?? "unknown version"
129- } )`;
129+ process . title = `trigger-dev-run-worker (${
130+ getEnvVar ( "TRIGGER_WORKER_VERSION" ) ?? "unknown version"
131+ } )`;
130132
131133const heartbeatIntervalMs = getEnvVar ( "HEARTBEAT_INTERVAL_MS" ) ;
132134
@@ -171,7 +173,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager(
171173 apiClientManager . clientOrThrow ( ) ,
172174 getEnvVar ( "TRIGGER_STREAM_URL" , getEnvVar ( "TRIGGER_API_URL" ) ) ?? "https://api.trigger.dev" ,
173175 ( getEnvVar ( "TRIGGER_STREAMS_DEBUG" ) === "1" || getEnvVar ( "TRIGGER_STREAMS_DEBUG" ) === "true" ) ??
174- false
176+ false
175177) ;
176178realtimeStreams . setGlobalManager ( standardRealtimeStreamsManager ) ;
177179
@@ -322,12 +324,12 @@ async function doBootstrap() {
322324
323325let bootstrapCache :
324326 | {
325- tracer : TriggerTracer ;
326- tracingSDK : TracingSDK ;
327- consoleInterceptor : ConsoleInterceptor ;
328- config : TriggerConfig ;
329- workerManifest : WorkerManifest ;
330- }
327+ tracer : TriggerTracer ;
328+ tracingSDK : TracingSDK ;
329+ consoleInterceptor : ConsoleInterceptor ;
330+ config : TriggerConfig ;
331+ workerManifest : WorkerManifest ;
332+ }
331333 | undefined ;
332334
333335async function bootstrap ( ) {
@@ -496,8 +498,8 @@ const zodIpc = new ZodIpcConnection({
496498 async ( ) => {
497499 const beforeImport = performance . now ( ) ;
498500 resourceCatalog . setCurrentFileContext (
499- taskManifest . entryPoint ,
500- taskManifest . filePath
501+ taskManifest . filePath ,
502+ taskManifest . entryPoint
501503 ) ;
502504
503505 // Load init file if it exists
@@ -605,6 +607,12 @@ const zodIpc = new ZodIpcConnection({
605607
606608 const signal = AbortSignal . any ( [ _cancelController . signal , timeoutController . signal ] ) ;
607609
610+ // Sentinel context so `task()` calls firing during run / lifecycle
611+ // hooks (e.g. via `await import(...)` of a module containing a task
612+ // definition) register normally instead of being silently dropped.
613+ // Cleared in the surrounding finally below.
614+ resourceCatalog . setCurrentFileContext ( NO_FILE_CONTEXT , NO_FILE_CONTEXT ) ;
615+
608616 const { result } = await executor . execute ( execution , ctx , signal ) ;
609617
610618 if ( _isRunning && ! _isCancelled ) {
@@ -623,6 +631,7 @@ const zodIpc = new ZodIpcConnection({
623631 }
624632 } finally {
625633 standardHeartbeatsManager . stopHeartbeat ( ) ;
634+ resourceCatalog . clearCurrentFileContext ( ) ;
626635
627636 _execution = undefined ;
628637 _isRunning = false ;
0 commit comments