Skip to content

[Bug][Windows] Service wrapper still aborts before launching bun when %DATE% contains parentheses (ko-KR) — #5093 unfixed in 2.73.0 #6290

Closed

Description

@Superstone-han

Client or integration

Codex App

Area

Service lifecycle

Summary

On Korean Windows (ko-KR), the Task Scheduler service never launches the proxy. The generated wrapper %USERPROFILE%\.opencodex\opencodex-service.cmd stops parsing before the bun line, so opencodex-proxy fires at every logon/unlock, appends its 7-line header to service.log, and exits silently. Last Run Result stays 0 (wscript does not propagate the batch exit code), so RestartOnFailure never engages either. The proxy only runs when started by hand, and Codex cannot connect until then.

This is the same defect as #5093 (ja-JP, 2.59.0), which was auto-closed by the issue-quality bot as not planned (missing template headings) and never fixed — the offending template lines are still present in 2.73.0.

Root cause: cmd.exe percent-expands %DATE% while parsing a parenthesized block, before the if condition is evaluated. The ko-KR short date is 2026-09-30(수); the ) inside the expanded value closes the block early, the remainder becomes a syntax error, and cmd aborts the whole batch. Since the block is dead code when the runtime files exist, the failure happens on every single start:

if not exist "%OCX_BUN%" (
  >>"%OCX_SERVICE_LOG%" echo [%DATE% %TIME%] installation is incomplete: bundled Bun is missing; reinstall opencodex, then run ocx service repair
  exit /b 3
)

The parse error goes to the hidden wscript console, so nothing is visible anywhere. Top-level echo [%DATE% %TIME%] lines outside blocks are unaffected, which is why the header block still lands in service.log and the failure looks silent.

Impact data from this machine: 9,459 lines of service.log (2026-08-19 → 2026-09-30) contain exactly one proxy startup banner (2026-09-07, presumably an older template generation) and zero child exited lines — every wrapper block ends at the token_file= echo. Instrumenting the generated wrapper confirmed execution stops between that echo and the bun launch line.

Reproduction

Minimal repro of the parse abort (any ko-KR/ja-JP machine, no opencodex needed):

@echo off
if not exist "C:\definitely-missing-file.xyz" (
  echo [%DATE% %TIME%] installation is incomplete
  exit /b 3
)
echo REACHED-AFTER-BLOCK
$ cmd /c date-paren-repro.cmd
12:16:55.17]은(는) 예상되지 않습니다.      <- "...was unexpected at this time." (ko-KR cmd)
EXIT=255

REACHED-AFTER-BLOCK is never printed — the batch dies at the block even though the condition is false. The 12:16:55.17] fragment is the tail of the expanded %TIME% after the date's ) closed the block, matching the 8:12:31.98] was unexpected at this time. output in #5093.

Full repro with opencodex:

  1. Windows with a locale whose short date contains parentheses — ko-KR (2026-09-30(수)); ja-JP per [Bug][Windows] Service wrapper fails to parse on locales where %DATE% contains parentheses (e.g. ja-JP); proxy never starts under Task Scheduler #5093 (2026/09/19 (土)).
  2. npm i -g @bitkyc08/opencodex (2.73.0), then ocx service install (or repair).
  3. schtasks /run /tn opencodex-proxy (or just relogon).
  4. Actual: service.log gains only the wrapper start header block; curl http://127.0.0.1:10100/healthz never answers; no bun.exe process; task shows Last Run Result: 0. ocx service repair reports "repaired" but nothing serves.

Running the same bun <cli> start --port 10100 by hand with OCX_SERVICE=1 works fine, so the failure is purely in the wrapper.

Template source: src/service/windows-taskxml.ts — the two installation is incomplete lines (~105, ~112) sit inside if not exist (...) blocks, and restored previous install from %%B has the same pattern inside the nested for parens of :restore_backup.

Version

2.73.0

Operating system

Windows 11 Pro (10.0.26100), system locale ko-KR

Logs or error output

service.log after schtasks /run — the block always ends at token_file, nothing follows, no bun process (paths shortened):

[2026-09-30(수) 11:23:58.85] opencodex service wrapper start
bun="...\npm\node_modules\@bitkyc08\opencodex\node_modules\bun\bin\bun.exe"
bun_source="bundled"
cli="...\npm\node_modules\@bitkyc08\opencodex\src\cli\index.ts"
opencodex_home=""
codex_home=""
token_file="C:\Users\me\.opencodex\service-api-token"

Screenshots and supporting files

Verified workaround — rewrite the wrapper with goto-based flow so no %DATE% is ever expanded inside parentheses. After patching, schtasks /run /tn opencodex-proxy launches bun, /healthz answers, and the log gains runtime files OK; launching bun / child exited with code ... lines:

Working wrapper shape (env/PATH lines elided)
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "ERRORLEVEL="
cd /d "%USERPROFILE%\.opencodex"
set "OCX_SERVICE=1"
set "OCX_WINDOWS_WRAPPER_PROTOCOL=1"
rem ... same OCX_* / PATH / token lines as the generated wrapper ...

:loop
>>"%OCX_SERVICE_LOG%" echo [%DATE% %TIME%] opencodex service wrapper start
rem ... same header echoes as generated ...
if not exist "%OCX_BUN%" goto bun_missing
if not exist "%OCX_CLI%" goto cli_missing
"%OCX_BUN%" "%OCX_CLI%" start --port 10100 >>"%OCX_SERVICE_LOG%" 2>&1
>>"%OCX_SERVICE_LOG%" echo [%DATE% %TIME%] child exited with code %ERRORLEVEL%
if "%ERRORLEVEL%"=="42" goto stopped
>>"%OCX_SERVICE_LOG%" echo [%DATE% %TIME%] restarting in 5s
ping -n 6 127.0.0.1 >nul
goto loop

:stopped
endlocal
exit /b 0

:bun_missing
>>"%OCX_SERVICE_LOG%" echo [%DATE% %TIME%] installation is incomplete: bundled Bun is missing; reinstall opencodex, then run ocx service repair
endlocal
exit /b 3

:cli_missing
>>"%OCX_SERVICE_LOG%" echo [%DATE% %TIME%] installation is incomplete: CLI entry is missing; reinstall opencodex, then run ocx service repair
endlocal
exit /b 3

Suggested template fixes (any one suffices):

Two smaller hardening observations from the same debugging session:

  • The long-running child holds its >>service.log handle open for its whole lifetime; any concurrent wrapper instance then fails its appends with The process cannot access the file because it is being used by another process, and cmd skips the command entirely when redirect setup fails — so a racing wrapper (logon + unlock + console-connect triggers can overlap with a stray instance) can silently never launch bun. Per-instance child log files avoid it.
  • chcp 65001 early in the wrapper also produced silent mid-script stops in fresh Task Scheduler consoles during testing; dropping it changed nothing functionally (the log timestamps were mojibake either way).
  • ocx service repair / ocx doctor currently report the service as installed/viable while nothing serves. A one-shot wrapper smoke test (run cmd /c once and look for was unexpected at this time. or a header-only log) would surface this class of failure immediately.

Checks

Activity

  1. coderabbitai commented on Sep 30, 2026

    @coderabbitai
    Contributor
    ⚠️ Possible Duplicate Issue(s)

    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. added
    bug
    platform
    service
    on Sep 30, 2026
  3. Ingwannu commented on Oct 1, 2026

    @Ingwannu
    Owner

    Confirmed that current dev 6429463 still emits %DATE% inside parenthesized wrapper blocks; closing #5093 did not land a fix. #6298 is the active fix PR, so I am keeping this report open rather than treating the old closure as resolution. Its author reports Windows cmd.exe fixtures; those are the relevant evidence, since Linux skips this path. Before integration it still needs current-dev/head readiness and required CI. An installed old wrapper also needs the documented repair step after a fixed release; this comment does not authorize or perform a live service repair.

  4. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  5. added a commit that references this issue on Oct 1, 2026
    8a3a776
  6. lidge-jun commented on Oct 1, 2026

    @lidge-jun
    Owner

    Fixed on dev by #6391 (8a3a776). It ships in the next release.

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

    bugplatformservice

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions