@@ -902,7 +902,7 @@ export class NodeExecutionDriver implements RuntimeDriver {
902902 }
903903
904904 private async waitForManagedResources ( ) : Promise < void > {
905- const graceDeadline = Date . now ( ) + 5000 ;
905+ const graceDeadline = Date . now ( ) + 100 ;
906906
907907 // Give async bridge callbacks a moment to register their host-side handles.
908908 while ( ! this . disposed && ! this . hasManagedResources ( ) && Date . now ( ) < graceDeadline ) {
@@ -1048,12 +1048,8 @@ export class NodeExecutionDriver implements RuntimeDriver {
10481048 // large dependency trees (e.g., PI has hundreds of @sinclair/typebox
10491049 // sub-modules). CJS mode uses the in-process require-setup transform
10501050 // which is orders of magnitude faster.
1051- // If the code was already CJS-transformed by _resolveEntry (has the
1052- // require-esm marker), use exec mode so require() and __dirname work.
1053- const REQUIRE_ESM_MARKER = "/*__secure_exec_require_esm__*/" ;
1054- const alreadyTransformed = options . code . startsWith ( REQUIRE_ESM_MARKER ) ;
1055- const sessionMode = alreadyTransformed ? "exec" : ( options . mode === "run" || entryIsEsm ? "run" : "exec" ) ;
1056- const userCode = entryIsEsm && ! alreadyTransformed
1051+ const sessionMode = options . mode === "run" || entryIsEsm ? "run" : "exec" ;
1052+ const userCode = entryIsEsm
10571053 ? options . code
10581054 : ( ( ) => {
10591055 const transformed = transformSourceForRequireSync (
@@ -1280,7 +1276,7 @@ export class NodeExecutionDriver implements RuntimeDriver {
12801276 } ,
12811277 timingMitigation ,
12821278 frozenTimeMs ,
1283- sessionMode ,
1279+ options . mode ,
12841280 options . filePath ,
12851281 bindingKeys ,
12861282 ) ;
@@ -1289,7 +1285,6 @@ export class NodeExecutionDriver implements RuntimeDriver {
12891285 this . _currentSession = session ;
12901286
12911287 // Execute in V8 session
1292- console . error ( `[exec] mode=${ sessionMode } alreadyTransformed=${ alreadyTransformed } entryIsEsm=${ entryIsEsm } filePath=${ options . filePath } codeLen=${ userCode . length } ` ) ;
12931288 const result = await session . execute ( {
12941289 bridgeCode,
12951290 postRestoreScript,
@@ -1330,7 +1325,7 @@ export class NodeExecutionDriver implements RuntimeDriver {
13301325 } ,
13311326 } ) ;
13321327
1333- if ( ! result . error ) {
1328+ if ( options . mode === "exec" && ! result . error ) {
13341329 await this . waitForManagedResources ( ) ;
13351330 }
13361331
@@ -1542,9 +1537,7 @@ function buildPostRestoreScript(
15421537 parts . push ( getIsolateRuntimeSource ( "applyTimingMitigationOff" ) ) ;
15431538 }
15441539
1545- // Apply env, cwd, and stdin overrides for all modes.
1546- // These must run even in "run" (ESM) mode so that process.env and
1547- // process.cwd() reflect the spawn-time configuration.
1540+ // Apply env/cwd overrides for all modes (needed for ESM process.env access)
15481541 if ( processConfig . env ) {
15491542 parts . push ( `globalThis.__runtimeProcessEnvOverride = ${ JSON . stringify ( processConfig . env ) } ;` ) ;
15501543 parts . push ( getIsolateRuntimeSource ( "overrideProcessEnv" ) ) ;
@@ -1553,8 +1546,7 @@ function buildPostRestoreScript(
15531546 parts . push ( `globalThis.__runtimeProcessCwdOverride = ${ JSON . stringify ( processConfig . cwd ) } ;` ) ;
15541547 parts . push ( getIsolateRuntimeSource ( "overrideProcessCwd" ) ) ;
15551548 }
1556-
1557- // CJS file globals (__filename, __dirname, module) only for exec mode.
1549+ // CJS file globals and stdin only for exec mode
15581550 if ( mode === "exec" ) {
15591551 const commonJsFileConfig = ( ( ) => {
15601552 if ( filePath ) {
0 commit comments