Skip to content

[Bug][Windows] ocx service install fails with 'exit code 199' — elevated Register-ScheduledTask launcher script split by '; ' join (no UAC, Start-Process -ArgumentList/-Verb never run) #1843

Description

@browseros247-dev

Client or integration

CLI — ocx service install on Windows from a non-elevated PowerShell 7 terminal.

Area

Service install / Task Scheduler registration — src/lib/windows-elevation.tsrunWindowsElevatedScheduledTaskRegistration() (the fresh-install elevated fallback used by registerFreshWindowsSchedulerTask() in service.ts).

Summary

On a clean install with no existing opencodex-proxy scheduled task, ocx service install fails immediately with ❌ Service install cleanup failed: Background service install failed with exit code 199. and never shows the UAC prompt. Expected: the elevated fallback should prompt UAC, run Register-ScheduledTask, then publish assets and serve on port 10100.

The failure is a launcher-script bug, not a UAC-denial edge case. runWindowsElevatedScheduledTaskRegistration() builds the elevated PowerShell launcher by joining its array with "; ", which terminates the Start-Process statement right after -FilePath. The resulting script is:

$p = Start-Process -FilePath 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe';  -ArgumentList '-NoProfile ...';  -Verb RunAs -WindowStyle Hidden -PassThru -Wait; if ($null -eq $p) { exit 1223 } ...

So -ArgumentList and -Verb RunAs become standalone statements → two CommandNotFoundException errors, elevation never runs (no UAC), and PowerShell exits with a spurious code (observed 199) that the CLI surfaces verbatim. The adjacent runWindowsElevated() builds the same kind of launcher correctly using join("") with ; terminators embedded on the previous lines.

Reproduction

  1. Fresh npm i -g @bitkyc08/opencodex (2.19.0), or ensure no task exists: schtasks /delete /tn opencodex-proxy /f
  2. From a non-elevated PowerShell 7: ocx service install
  3. Observe: no UAC prompt appears; it prints ❌ Service install cleanup failed: Background service install failed with exit code 199.

I also verified that elevation itself works on this machine: a manual elevated Register-ScheduledTask with the same generated task XML succeeds (exit 0). The malformed launcher script is the only failing piece.

Version

@bitkyc08/opencodex 2.19.0 (latest on npm)

Operating system

Windows 11 24H2 (build 10.0.26200), non-elevated PowerShell 7.5

Provider and model

N/A — not provider-specific

Logs or error output

CLI:

❌ Service install cleanup failed: Background service install failed with exit code 199.

Elevated launcher stderr (captured by instrumenting startPowerShellCommand):

-ArgumentList : The term '-ArgumentList' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:92
+ ... stem32\WindowsPowerShell\v1.0\powershell.exe';  -ArgumentList '-NoPro ...
+                                                     ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-ArgumentList:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

-Verb : The term '-Verb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:11070
+ ... aQBvAG4AIABTAHQAbwBwACAAfAAgAE8AdQB0AC0ATgB1AGwAbAA=';  -Verb RunAs - ...
+                                                             ~~~~~
    + CategoryInfo          : ObjectNotFound: (-Verb:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Screenshots and supporting files

n/a

Redacted configuration

None required — no configuration shape is involved.

Suggested fix

In runWindowsElevatedScheduledTaskRegistration(), mirror runWindowsElevated(): move the ; terminators onto the preceding lines and join(""):

const script = [
  `$p = Start-Process -FilePath ${psSingleQuote(windowsPowerShell())}`,
  ` -ArgumentList ${psSingleQuote(buildWindowsElevatedArgumentList([...]))}`,
  " -Verb RunAs -WindowStyle Hidden -PassThru -Wait;",
  `if ($null -eq $p) { exit ${OCX_ELEVATED_UAC_CANCELLED} }`,
  "$null = $p.Handle;",
  `if ($null -eq $p.ExitCode) { exit ${OCX_ELEVATED_PROTOCOL_FAILED} }`,
  "exit $p.ExitCode",
].join("");

With this one-line fix the identical reproduction completes successfully: task \opencodex-proxy registered (ownership nonce), assets published under ~/.opencodex, and the proxy serving on port 10100.

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcliCLI, config inject, packaging flagsplatformOS/service/tray/ACL (Windows-heavy, not Windows-only)serviceService lifecycle (WinSW/launchd/scheduler)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions