Skip to content

Windows: failed ocx service install leaves proxy stopped and Codex routing un-injected because teardown runs before the elevation check #1454

Description

@MarcusNeufeldt

Client or integration

Codex CLI

Area

Service lifecycle

Summary

On Windows, ocx service install stops the proxy and removes opencodex's injected Codex config keys before it discovers it needs elevation. When the schtasks call is then denied, the teardown is not undone — so a failed install leaves a previously working setup broken.

Observed sequence:

  1. ocx service install stops the running proxy and restores native Codex routing (removing openai_base_url and model_catalog_json from <CODEX_HOME>/config.toml).
  2. It then runs schtasks /create ..., which fails because the shell is not elevated:
❌ Service install cleanup failed: Windows access denied while running Task Scheduler.
Command: schtasks /create /tn opencodex-proxy /xml <OPENCODEX_HOME>\opencodex-service-task.xml /f
Approve the Windows UAC prompt to install the background service, or run `ocx service install`
from an elevated PowerShell window.
OCX_ERROR_CODE=WINDOWS_SCHTASKS_CREATE_ACCESS_DENIED
  1. The service is not installed and the proxy is left stopped with routing removed. ocx status afterwards reports Restart safety: native Codex routing (no opencodex restart dependency).

Expected: elevation is checked (or the task creation attempted) before any teardown, so that a permission failure is a no-op; or the teardown is rolled back when install fails.

The message text does anticipate the failure ("Approve the Windows UAC prompt… or run from an elevated PowerShell window"), so the elevation requirement is known in advance — it just is not checked early enough.

Reproduction

100% reproducible on my machine.

  1. Have a working opencodex install with the proxy running and Codex routed through it.
  2. From a non-elevated shell, run ocx service install.
  3. Observe the access-denied error above.
  4. Check <CODEX_HOME>/config.tomlopenai_base_url and model_catalog_json are gone.
  5. Check the proxy — stopped.

Recovering is harder than it should be because ocx restore back and ocx sync both refuse afterwards with a message naming no reason (filed separately). I restored routing by hand using the keys in <CODEX_HOME>/opencodex.config.toml.

Suggested fixes

  1. Probe for elevation (or attempt the schtasks create) before stopping the proxy and un-injecting the config. A permissions failure should leave the system exactly as it was found.
  2. Failing that, make the cleanup path actually restore what the install path removed — the current message says "Service install cleanup failed", so a cleanup step exists but does not cover the config/proxy teardown.
  3. Consider detecting non-elevated invocation up front and printing the "run from an elevated PowerShell window" guidance instead of starting the install at all.

Version

2.11.0 (the install path is unchanged in 2.12.0 as far as I can tell from the release notes)

Operating system

Windows 11 Pro 10.0.26200

Provider and model

Not provider-specific.

Logs or error output

$ ocx health --json
{"ok":true,"pid":19940,"port":10100}

$ ocx service install
❌ Service install cleanup failed: Windows access denied while running Task Scheduler.
Command: schtasks /create /tn opencodex-proxy /xml <OPENCODEX_HOME>\opencodex-service-task.xml /f
Approve the Windows UAC prompt to install the background service, or run `ocx service install`
from an elevated PowerShell window.
OCX_ERROR_CODE=WINDOWS_SCHTASKS_CREATE_ACCESS_DENIED

$ ocx health --json
{"ok":false,"pid":null,"port":null}

$ ocx service status
❌ service not installed (Task Scheduler).

$ ocx status
❌ Proxy: not running
   Restart safety: native Codex routing (no opencodex restart dependency)
   Service: not installed

# and the injected keys are gone from <CODEX_HOME>/config.toml:
#   openai_base_url      -> removed
#   model_catalog_json   -> removed

Screenshots and supporting files

No response

Redacted configuration

{
  "providers": {
    "openai": { "adapter": "openai-responses", "codexAccountMode": "direct", "authMode": "forward" }
  },
  "codexAutoStart": true,
  "activeCodexAccountId": "__main__"
}

Windows sandbox mode is unelevated in the Codex config; the shell used was a normal (non-admin) terminal.

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