@@ -397,7 +397,7 @@ export async function runInstallerFreshSuite(
397397 const usesManagedGateway = shouldUseManagedGatewayService ( ) ;
398398 const useManagedGatewayAfterInstall = shouldUseManagedGatewayForInstallerRuntime ( ) ;
399399 const manualGateway : { current : GatewayHandle | null } = { current : null } ;
400- let managedHostLease : ManagedGatewayInstallerHostLease | null = null ;
400+ const managedHostLease : { current : ManagedGatewayInstallerHostLease | null } = { current : null } ;
401401 let managedHostOwned = false ;
402402 let managedHostEnv : NodeJS . ProcessEnv | null = null ;
403403 let managedHostCliPath = "" ;
@@ -453,7 +453,7 @@ export async function runInstallerFreshSuite(
453453 if ( ! accountHome ) {
454454 throw new Error ( "Managed installer service checks require the host account home." ) ;
455455 }
456- managedHostLease = acquireManagedGatewayInstallerHostLease ( accountHome ) ;
456+ managedHostLease . current = acquireManagedGatewayInstallerHostLease ( accountHome ) ;
457457 assertManagedGatewayInstallerHostAvailable ( {
458458 accountHome,
459459 serviceInstalled : false ,
@@ -615,12 +615,13 @@ export async function runInstallerFreshSuite(
615615 }
616616
617617 let managedCleanupError : Error | undefined ;
618- if ( managedHostLease ) {
618+ const acquiredManagedHostLease = managedHostLease . current ;
619+ if ( acquiredManagedHostLease ) {
619620 let hostCleanupError : Error | undefined ;
620621 try {
621622 if ( managedHostOwned && managedHostEnv && managedHostCliPath ) {
622623 await cleanupManagedGatewayInstallerHost ( {
623- accountHome : managedHostLease . accountHome ,
624+ accountHome : acquiredManagedHostLease . accountHome ,
624625 cliPath : managedHostCliPath ,
625626 env : managedHostEnv ,
626627 lane,
@@ -633,7 +634,7 @@ export async function runInstallerFreshSuite(
633634 }
634635 let leaseReleaseError : Error | undefined ;
635636 try {
636- managedHostLease . release ( ) ;
637+ acquiredManagedHostLease . release ( ) ;
637638 } catch ( error ) {
638639 leaseReleaseError = error instanceof Error ? error : new Error ( formatError ( error ) ) ;
639640 }
@@ -927,21 +928,33 @@ export function resolveManagedGatewayInstallerEnv(params: {
927928 }
928929 const accountHome = params . accountHome ?? userInfo ( ) . homedir ;
929930 const hostEnv = params . hostEnv ?? process . env ;
930- return {
931+ const env : NodeJS . ProcessEnv = {
931932 ...params . env ,
932933 HOME : accountHome ,
933934 USERPROFILE : accountHome ,
934935 APPDATA : hostEnv . APPDATA ,
935936 LOCALAPPDATA : hostEnv . LOCALAPPDATA ,
936- OPENCLAW_HOME : undefined ,
937- OPENCLAW_PROFILE : undefined ,
938- OPENCLAW_STATE_DIR : undefined ,
939- OPENCLAW_CONFIG_PATH : undefined ,
940- OPENCLAW_WINDOWS_TASK_NAME : undefined ,
941- OPENCLAW_TASK_SCRIPT_NAME : undefined ,
942- OPENCLAW_TASK_SCRIPT : undefined ,
943- OPENCLAW_SERVICE_KIND : undefined ,
944937 } ;
938+ const isolatedIdentityKeys = new Set (
939+ [
940+ "OPENCLAW_HOME" ,
941+ "OPENCLAW_PROFILE" ,
942+ "OPENCLAW_STATE_DIR" ,
943+ "OPENCLAW_CONFIG_PATH" ,
944+ "OPENCLAW_WINDOWS_TASK_NAME" ,
945+ "OPENCLAW_TASK_SCRIPT_NAME" ,
946+ "OPENCLAW_TASK_SCRIPT" ,
947+ "OPENCLAW_SERVICE_KIND" ,
948+ ] . map ( ( key ) => key . toUpperCase ( ) ) ,
949+ ) ;
950+ // Windows environment keys are case-insensitive. Remove every casing variant
951+ // so the installed CLI cannot inherit the isolated lane identity.
952+ for ( const key of Object . keys ( env ) ) {
953+ if ( isolatedIdentityKeys . has ( key . toUpperCase ( ) ) ) {
954+ delete env [ key ] ;
955+ }
956+ }
957+ return env ;
945958}
946959
947960export function parseManagedGatewayServiceInstalled ( result : CommandResult ) : boolean {
0 commit comments