@@ -739,14 +739,15 @@ async function reportServiceServing(
739739 verb : "installed" | "started" | "repaired" ,
740740 deps : Parameters < typeof confirmServiceServing > [ 0 ] = { } ,
741741) : Promise < void > {
742- const serving = await confirmServiceServing ( deps ) ;
742+ const healthBudgetMs = deps . timeoutMs ?? serviceInstallHealthMs ( ) ;
743+ const serving = await confirmServiceServing ( { ...deps , timeoutMs : healthBudgetMs } ) ;
743744 if ( serving . ok ) {
744745 console . log ( `✅ opencodex service ${ verb } and serving on port ${ serving . port } .` ) ;
745746 return ;
746747 }
747748 console . error (
748749 `⚠️ Service ${ verb } , but no proxy answered on port ${ serving . port } within `
749- + `${ Math . trunc ( SERVICE_INSTALL_HEALTH_MS / 1000 ) } s.\n`
750+ + `${ Math . trunc ( healthBudgetMs / 1000 ) } s.\n`
750751 + ` The manager registered the job; that is not the same as serving.\n`
751752 + ` Log: ${ serviceLogPath ( ) } \n`
752753 + ` Meanwhile: ocx start (serves in the foreground)` ,
@@ -1832,7 +1833,7 @@ export function buildWindowsTaskXml(
18321833 script = windowsServiceScriptPath ( ) ,
18331834 launcher = windowsLauncherVbsPath ( ) ,
18341835 attemptNonce ?: string ,
1835- sessionTriggerUserId = cachedCurrentWindowsIdentity ( ) ?. name ,
1836+ sessionTriggerUserId = cachedCurrentWindowsIdentity ( ) ?. sid ,
18361837) : string {
18371838 const escapedWscript = taskXmlString ( windowsWscript ( ) ) ;
18381839 // Escape the launcher path independently for the <Arguments> element; quoting it
@@ -2086,14 +2087,12 @@ function windowsTaskTriggerScopeAcceptable(element: string, expectedUserId: stri
20862087 if ( userIdCount === 0 ) return true ;
20872088 if ( userIdCount !== 1 ) return false ;
20882089 if ( expectedUserId === undefined ) return false ;
2089- // Same tolerance as Command and Arguments, and for the same reason:
2090- // buildWindowsTaskXml writes the live account name here, so an account named
2091- // outside the console code page comes back mangled and an exact comparison
2092- // rejects a task that is in fact correctly scoped (#3064). The literal-ASCII
2093- // requirement is what keeps this safe -- a DOMAIN\\User scope keeps its backslash
2094- // verified, so a substitution run can never swallow the domain and let another
2095- // domain's account match.
2096- return taskXmlDecodedLossyValueEquals ( element , "UserId" , expectedUserId ) ;
2090+ // Scope is an identity boundary, unlike the launcher path. Newly generated tasks
2091+ // use the locale-independent SID from cachedCurrentWindowsIdentity(), so there is
2092+ // no reason to forgive code-page substitutions here. A lossy account-name compare
2093+ // lets two non-ASCII users collapse to the same `???` value and can make repair
2094+ // start another account's fixed-name task.
2095+ return taskXmlDecodedValueEquals ( element , "UserId" , expectedUserId ) ;
20972096}
20982097
20992098/** Validate the stable OpenCodex action, principal, settings, and logon trigger. */
@@ -2139,7 +2138,7 @@ export function windowsTaskRegistrationHealthy(
21392138 xml : string ,
21402139 wscript = windowsWscript ( ) ,
21412140 launcher = windowsLauncherVbsPath ( ) ,
2142- expectedUserId : string | null = cachedCurrentWindowsIdentity ( ) ?. name ?? null ,
2141+ expectedUserId : string | null = cachedCurrentWindowsIdentity ( ) ?. sid ?? null ,
21432142) : boolean {
21442143 const scrubbed = taskXmlWithoutCommentsAndCdata ( xml ) ;
21452144 const triggers = taskXmlSection ( scrubbed , "Triggers" ) ;
@@ -2178,7 +2177,7 @@ export function readWindowsSchedulerXmlState(
21782177 xml : string ,
21792178 wscript ?: string ,
21802179 launcher ?: string ,
2181- expectedUserId : string | null = cachedCurrentWindowsIdentity ( ) ?. name ?? null ,
2180+ expectedUserId : string | null = cachedCurrentWindowsIdentity ( ) ?. sid ?? null ,
21822181) : WindowsSchedulerXmlState {
21832182 const installed = xml . length > 0 ;
21842183 if ( ! installed ) return { installed : false , enabled : false , registrationHealthy : false } ;
@@ -3830,7 +3829,7 @@ export function serviceStartableFromTray(service: ServiceDiagnostic): boolean {
38303829}
38313830
38323831export interface WindowsTaskDiagnosticIdentityDeps {
3833- currentIdentity ?: ( ) => Readonly < { name : string } > | null ;
3832+ currentIdentity ?: ( ) => Readonly < { sid : string ; name : string } > | null ;
38343833 resolvePrincipal ?: ( timeoutMs : number ) => string ;
38353834}
38363835
@@ -3845,7 +3844,7 @@ export function resolveWindowsTaskDiagnosticUserId(
38453844) : string | null {
38463845 const currentIdentity = deps . currentIdentity ?? cachedCurrentWindowsIdentity ;
38473846 const cached = currentIdentity ( ) ;
3848- if ( cached ) return cached . name ;
3847+ if ( cached ) return cached . sid ;
38493848
38503849 const scrubbed = taskXmlWithoutCommentsAndCdata ( schedulerXml ) ;
38513850 const triggers = taskXmlSection ( scrubbed , "Triggers" ) ;
@@ -3856,7 +3855,7 @@ export function resolveWindowsTaskDiagnosticUserId(
38563855 } catch {
38573856 return null ;
38583857 }
3859- return currentIdentity ( ) ?. name ?? null ;
3858+ return currentIdentity ( ) ?. sid ?? null ;
38603859}
38613860
38623861export interface WindowsServiceDiagnosticInputs {
@@ -3880,7 +3879,7 @@ export interface WindowsServiceDiagnosticInputs {
38803879
38813880export function deriveWindowsServiceDiagnostic ( inputs : WindowsServiceDiagnosticInputs ) : ServiceDiagnostic {
38823881 const expectedUserId = inputs . schedulerExpectedUserId === undefined
3883- ? cachedCurrentWindowsIdentity ( ) ?. name ?? null
3882+ ? cachedCurrentWindowsIdentity ( ) ?. sid ?? null
38843883 : inputs . schedulerExpectedUserId ;
38853884 const schedulerState = readWindowsSchedulerXmlState (
38863885 inputs . schedulerXml ,
0 commit comments