Skip to content

[Bug][Windows] ocx update fails with ENOTDIR/errno mkdir during npm install -g; leftover .opencodex-* temp dir with locked bunx.exe #5624

Closed

Description

@NovaTrailX

Client or integration

OpenCodex dashboard

Area

Installation or packaging

Summary

On Windows, the official update path (ocx update / dashboard background worker) fails to move 2.59.0 → 2.63.0 with:

更新失败。 2.59.0 -> 2.63.0. update command failed (1)

The sanitized job diagnostic is:

exit 1 · code: ENOTDIR · syscall: mkdir · 1953 bytes of full output withheld

Integrity pre-flight succeeds. The proxy is stopped first (as designed). The subsequent npm install -g @bitkyc08/[email protected] then fails with Node/libuv ENOTDIR on mkdir. A leftover npm rename-aside directory remains (node_modules/@bitkyc08/.opencodex-<rand>/), and cleanup of that tree fails with EPERM on bunx.exe.

Expected: the official updater either completes the global replace, or fails closed with a recovery path that restores a working install and reports a concrete next step.

Actual: update reports only update command failed (1); the working 2.59.0 install is left in place (good), but a stale temp tree remains and the only successful path afterwards is a manual npm install -g after stopping the proxy again.

Related but distinct:

No existing issue mentions ENOTDIR or syscall: mkdir.

Reproduction

Environment at failure:

Item Value
OS Windows 11 Home China, build 10.0.26100, AMD64
Node v24.13.1
npm 11.8.0
Installer npm global (%APPDATA%\npm)
npm cache D:\Cache\npm (second volume)
registry https://registry.npmmirror.com
Service backend Task Scheduler (opencodex-proxy)
opencodex before 2.59.0
target 2.63.0
Codex 0.155.0-alpha.9.2 (configured runtime)

Steps (as observed):

  1. Service-managed proxy running on 10100 from a global npm install of 2.59.0 (bundled Bun). Windows tray + Codex autostart shim installed. Codex app-server live.
  2. Trigger dashboard / ocx update (channel latest).
  3. Worker verifies registry integrity for @bitkyc08/[email protected] (sha512 matches) — OK.
  4. Worker stops the proxy / unloads the service — OK.
  5. Worker runs npm install -g @bitkyc08/[email protected].
  6. npm fails: code: ENOTDIR, syscall: mkdir, exit 1.
  7. Recovery restarts the old service; job status becomes failed with error: "update command failed (1)".
  8. On disk afterwards:
    • node_modules/@bitkyc08/opencodex/ still 2.59.0 (runnable)
    • node_modules/@bitkyc08/.opencodex-<rand>/ leftover
    • leftover cleanup cannot unlink .../node_modules/bun/bin/bunx.exe (EPERM, errno -4048) while any process still holds that image

Not intermittently re-run through the GUI after the first failure (leftover + live tray/service make repeated auto-updates noisy). A subsequent manual npm install -g @bitkyc08/[email protected] in a normal shell succeeded in ~6s and reported the same EPERM cleanup warning on the leftover temp tree, then:

added 1 package, and changed 100 packages in 6s

So the tarball/registry/cache path is fine; the failure is specific to the updater-spawned npm install -g replace dance under Windows file locks.

Version

Running process at failure: 2.59.0.
Target / post-manual-install package: @bitkyc08/[email protected].
Diagnostic extraction matches src/update/job.ts (NPM_ERROR_CODES includes ENOTDIR, POSIX_SYSCALLS includes mkdir).

Operating system

Windows 11 Home China, build 10.0.26100. Bundled Bun runtime, service backend scheduler (Task Scheduler).

Provider and model

Not provider-specific. Fails during package replacement, before any provider translation.

Logs or error output

From ~/.opencodex/update-job.json (paths already withheld by the job sanitizer):

{
  "status": "failed",
  "currentVersion": "2.59.0",
  "latestVersion": "2.63.0",
  "channel": "latest",
  "installer": "npm",
  "restart": true,
  "log": [
    "Update job queued for 2.59.0 -> 2.63.0.",
    "Update worker started as PID 15132.",
    "Verified @bitkyc08/[email protected] integrity metadata sha512-TQCsGHZI0wrmUDQYB…",
    "<withheld: 109 bytes, may contain local paths>",
    "exit 1 · code: ENOTDIR · syscall: mkdir · 1953 bytes of full output withheld",
    "<withheld: 187 bytes, may contain local paths>",
    "exit 0 · 35 bytes of output withheld (no recognized diagnostic fields)"
  ],
  "exitCode": 1,
  "error": "update command failed (1)"
}

User-visible symptom:

更新失败。 2.59.0 -> 2.63.0. update command failed (1)

After a later manual install, npm verbose log showed the same lock class on the leftover tree:

npm warn cleanup Failed to remove some directories [
npm warn cleanup   '...\\@bitkyc08\\.opencodex-<rand>\\node_modules\\bun\\bin\\bunx.exe'
npm warn cleanup     [Error: EPERM: operation not permitted, unlink '...\\bunx.exe'] {
npm warn cleanup       errno: -4048,
npm warn cleanup       code: 'EPERM',
npm warn cleanup       syscall: 'unlink'
npm warn cleanup     }
]

Workaround that restored 2.63.0 (verified healthy afterwards):

# after understanding the failure; service still installed
npm install -g @bitkyc08/[email protected]
ocx stop
# remove leftover node_modules/@bitkyc08/.opencodex-* if EPERM allows after stop
ocx service start

ocx health --json then returned {"ok":true,...} on port 10100.

Screenshots and supporting files

No screenshots. Full npm verbose log of the successful manual install was captured locally and then deleted (contained absolute paths). Happy to re-capture a failed updater run with a private log if useful.

Redacted configuration

{
  "service-state.json": {
    "version": 2,
    "backend": "scheduler",
    "opencodexHome": "<HOME>\\.opencodex",
    "cliPath": "<NPM_PREFIX>\\node_modules\\@bitkyc08\\opencodex\\src\\cli\\index.ts",
    "bunPath": "<NPM_PREFIX>\\node_modules\\@bitkyc08\\opencodex\\node_modules\\bun\\bin\\bun.exe"
  },
  "runtime-port.json": {
    "pid": 32292,
    "port": 10100,
    "attestationSecret": "<redacted>"
  },
  "npm": {
    "prefix": "<NPM_PREFIX>",
    "cache": "<OTHER_DRIVE>\\Cache\\npm",
    "registry": "https://registry.npmmirror.com"
  }
}

Why this is still worth a separate issue

  1. Failure mode is ENOTDIR/mkdir on the install step, not EPERM on post-install cleanup ([Bug][Windows] Auto-update leaves proxy dead after npm EPERM on bun binary replacement #281) and not an emptied skeleton ([Bug][Windows] Failed ocx update leaves a file-less package skeleton; service wrapper restart-loops 1,009 times with no integrity check or backoff #1849). The sanitized job line is the only breadcrumb the UI gives (update command failed (1)), so operators cannot tell which of the three they hit.
  2. Official updater + integrity pre-flight + stop-first still cannot replace the package when bun.exe/bunx.exe image locks remain (tray, scheduler wrapper children, Codex shim ensure sidecar, AV scanners). Manual npm install -g immediately afterwards works — so this is updater sequencing, not registry corruption.
  3. Leftover .opencodex-* trees accumulate (same as [Bug][Windows] Auto-update leaves proxy dead after npm EPERM on bun binary replacement #281) and make subsequent updates noisier.

Suggested fix

Any of these would help; 1–2 are the high-value ones.

  1. Release Bun image locks before npm install -g. After ocx stop, also stop the Windows tray and any service wrapper / ensure children that may still map bun.exe/bunx.exe, then wait/retry until those images are deletable (or use a short backoff retry on ENOTDIR/EPERM/EBUSY from the install step). [Bug][Windows] Auto-update leaves proxy dead after npm EPERM on bun binary replacement #281 asked for this on the cleanup side; the same lock also breaks the replace.
  2. Treat ENOTDIR/EPERM/EBUSY on the install step as a lock class, not a generic failure. Surface a distinct error (e.g. update blocked by locked package files) and print the manual recovery (ocx stop → npm install -g … → ocx service start) in the UI/job log instead of only update command failed (1).
  3. Post-failure sweep of node_modules/@bitkyc08/.opencodex-* once the install step exits non-zero and processes are known stopped (same ask as [Bug][Windows] Auto-update leaves proxy dead after npm EPERM on bun binary replacement #281).
  4. Optional: persist one unsanitized (local-only) npm stderr excerpt under ~/.opencodex/ when the updater sanitizes the job log, so field diagnosis does not require a manual repro.

Checks

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

Activity

  1. added
    bug
    cli
    install
    platform
    on Sep 23, 2026
  2. lidge-jun commented on Sep 23, 2026

    @lidge-jun
    Owner

    Landed on dev in 41ba802 via #5643: the updater now handles leftover rename-aside directories and locked files it owns from an earlier attempt, never deletes leftovers it does not own, keeps the previous install and service when a step fails, and prints the recovery command; the docs gained a troubleshooting page for failed updates. An updater already installed on an older version cannot be changed retroactively, so that page covers the manual path from those versions. Closing manually since dev merges do not auto-close; please reopen if the current updater still fails this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliinstallplatform

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions