@@ -10,6 +10,8 @@ import {
1010import * as Effect from "effect/Effect" ;
1111import * as FileSystem from "effect/FileSystem" ;
1212import * as Path from "effect/Path" ;
13+ // @effect -diagnostics-next-line nodeBuiltinImport:off -- the shared login shell probe runs synchronously through execFileSync.
14+ import * as NodeChildProcess from "node:child_process" ;
1315import * as NodeOS from "node:os" ;
1416
1517function logPathHydrationWarning ( message : string , error ?: unknown ) : void {
@@ -18,16 +20,46 @@ function logPathHydrationWarning(message: string, error?: unknown): void {
1820 ) ;
1921}
2022
23+ // mise's record of the PATH entries it added. It must travel with the
24+ // shell's PATH, or `mise x` can rebuild PATH behind a same-named wrapper
25+ // (`exec mise x claude -- claude`) that then re-runs itself forever.
26+ const LOGIN_SHELL_ENVIRONMENT_NAMES = [ "PATH" , "__MISE_DIFF" , "JAVA_HOME" ] ;
27+ const SLOW_LOGIN_SHELL_TIMEOUT_MS = 20_000 ;
28+
29+ function readSlowLoginShellEnvironment ( shell : string ) : Partial < Record < string , string > > {
30+ return readEnvironmentFromLoginShell (
31+ shell ,
32+ LOGIN_SHELL_ENVIRONMENT_NAMES ,
33+ ( file , args , options ) =>
34+ NodeChildProcess . execFileSync ( file , args , {
35+ ...options ,
36+ timeout : SLOW_LOGIN_SHELL_TIMEOUT_MS ,
37+ } ) ,
38+ ) ;
39+ }
40+
2141function hydratePosixPath ( env : NodeJS . ProcessEnv , platform : NodeJS . Platform ) : void {
2242 let shellEnvironment : Partial < Record < string , string > > = { } ;
43+ let waitedForSlowShell = false ;
2344 for ( const shell of listLoginShellCandidates ( platform , env . SHELL ) ) {
2445 try {
25- // mise's record of the PATH entries it added. It must travel with the
26- // shell's PATH, or `mise x` can rebuild PATH behind a same-named wrapper
27- // (`exec mise x claude -- claude`) that then re-runs itself forever.
28- shellEnvironment = readEnvironmentFromLoginShell ( shell , [ "PATH" , "__MISE_DIFF" , "JAVA_HOME" ] ) ;
46+ shellEnvironment = readEnvironmentFromLoginShell ( shell , LOGIN_SHELL_ENVIRONMENT_NAMES ) ;
2947 } catch ( error ) {
3048 logPathHydrationWarning ( `Failed to read PATH from login shell ${ shell } .` , error ) ;
49+ // A profile can be slow only while the machine boots. Wait for it once,
50+ // here: providers copy this env when they are built, so a later read
51+ // would never reach them.
52+ if ( ! waitedForSlowShell && ( error as NodeJS . ErrnoException | null ) ?. code === "ETIMEDOUT" ) {
53+ waitedForSlowShell = true ;
54+ try {
55+ shellEnvironment = readSlowLoginShellEnvironment ( shell ) ;
56+ } catch ( retryError ) {
57+ logPathHydrationWarning (
58+ `Failed to read PATH from slow login shell ${ shell } .` ,
59+ retryError ,
60+ ) ;
61+ }
62+ }
3163 }
3264
3365 if ( shellEnvironment . PATH ) break ;
0 commit comments