Skip to content

[Bug][Windows] zh-CN schtasks status makes ocx stop and ocx update fail closed inside the 1s manager-state cap #8863

Closed

Description

@mouzhi

Client or integration

Other. This is the ocx CLI service lifecycle (ocx update, ocx stop, ocx service stop), not a model provider.

Area

Service lifecycle, on Windows Task Scheduler. WinSW is not installed (sc query opencodex-proxy-native returns 1060).

Summary

On zh-CN Windows, ocx update, ocx stop, and ocx service stop fail closed while ocx service status reports the Task Scheduler service as installed and the proxy as running.

The checked stop (#7771) reads schtasks /query /tn opencodex-proxy /fo CSV /nh, then only accepts the English status words Running, Ready, Disabled, and Queued. zh-CN schtasks.exe.mui emits 正在运行, 就绪, 已禁用, and 已排队. Those decode correctly (this is not the #4691 GBK mojibake bug) and parseTaskCsvState returns unknown.

The intended fallback is Windows PowerShell Get-ScheduledTask, whose .State is the locale-independent enum. That fallback cannot finish. taskState is capped by WINDOWS_STOP_CAPS.managerState (1000 ms) via runCapped in stopWindowsServiceChecked. On this machine the CSV query returns in about 35–50 ms, and the same powershell.exe -NoProfile Get-ScheduledTask path then takes about 1.6 s. At 1000 ms, taskState returns unknown. Part A therefore finishes with evidence-unreadable / "the stop could not be verified".

Every state-unknown result is printed as "The Windows Task Scheduler state could not be read" and tells the operator to run ocx service status. That command uses probeWindowsSchedulerTask, which only checks that the task name is present, so it stays green and does not show this failure.

schtasks /end runs before this read. The message still says nothing unverified was stopped and that the proxy was left running. After one failed ocx update here, the task's last result was 267014 (0x41306, SCHED_S_TASK_TERMINATED) and ports 10100/10101 were not listening. The end had already happened. The failure was the follow-up status read.

Reproduction

Windows 10 Pro 26H2, build 26320.9877, UI culture zh-CN. Package installed globally with npm. Service backend is the opencodex-proxy Task Scheduler task. No WinSW service.

  1. ocx service status → service installed, proxy running on port 10101.
  2. ocx update (2.100.3 → 2.100.4), ocx stop, or ocx service stop.

Observed output:

❌ The Windows Task Scheduler state could not be read, so this stop cannot tell whether a wrapper would respawn the proxy.
   Run 'ocx service status' to see the query error, repair Task Scheduler access, then retry.
   The Windows service or process state could not be read (the stop could not be verified); nothing that could not be verified was stopped.
   The proxy was left running and the shared teardown skipped: the service could relaunch it.
opencodex: could not stop the running proxy; aborting the update. Run 'ocx stop' and retry.

ocx service stop ends with:

❌ service stop did not take effect: the Windows service could not be proven stopped (unknown).
   The Windows service or process state could not be read (the stop could not be verified); nothing that could not be verified was stopped.
   The proxy was left running and native Codex was NOT restored.

Direct check, using the installed decodeWindowsTextBytes path and windowsCheckedStopLiveDeps().taskState:

  • CSV status field is 就绪 while the task is Ready, and 正在运行 while it is Running. parseTaskCsvState returns unknown for both.
  • taskState(1000) returns unknown in about 1016 ms.
  • taskState(5000) returns not-running in about 1582 ms when the task is Ready. The PowerShell fallback works. The 1 s cap is what drops it.
  • A warm Get-ScheduledTask in PowerShell 7 also took 1399 ms and returned State=Ready, so this is not specific to one PowerShell edition.

The published parseTaskCsvState in 2.100.4 is still English-only. Recognizing the four zh-CN words from schtasks.exe.mui makes taskState(1000) return running in about 50 ms, and ocx update from 2.100.3 to 2.100.4 can then stop the service and finish. The replacement package restores the English-only parser.

Version

Reproduced on @bitkyc08/opencodex 2.100.3. The same parser and 1000 ms cap are in 2.100.4.

Operating system

Windows 10 Pro 26H2 (build 26320.9877), culture zh-CN.

Provider and model

Not provider-specific.

Logs or error output

Relevant code:

  • src/service/windows-checked-stop-live.ts: parseTaskCsvState accepts only /^running$/i and /^(ready|disabled|queued)$/i. taskState falls back to powershell.exe -NoProfile -NoLogo -NonInteractive -Command "(Get-ScheduledTask ...).State".
  • src/service/windows-stop-budget.ts: managerState: 1_000.
  • src/service/windows-checked-stop.ts: an unknown taskState sets unreadable, then returns finish("unknown", "evidence-unreadable", "the stop could not be verified").
  • src/cli/index.ts: any serviceStop === "state-unknown" prints the Task Scheduler read error and points at ocx service status.
  • src/cli/stop-windows-checked.ts: describeWindowsPartA / windowsPartAHolds add the "could not be read" and "proxy was left running" lines.
  • src/service/windows-scheduler.ts: probeWindowsSchedulerTask is a presence probe, which is why status succeeds.

Related closed reports, not the same bug: #2914 (localized schtasks text plus a timeout), #4691 (GBK decode of schtasks XML), #7771 (the checked stop this path belongs to).

Suggested fix

  1. Map the zh-CN schtasks status words before returning unknown. From System32\zh-CN\schtasks.exe.mui: 正在运行 = Running, 就绪 = Ready, 已禁用 = Disabled, 已排队 = Queued. The CSV query already succeeded, so this does not need another process. Other locales still need a working fallback.
  2. Make that fallback able to finish. runCapped(clock, C.managerState, deps.taskState) bounds the CSV query and the PowerShell startup together. Raising only the time left inside taskState does nothing while managerState stays 1000. A cold powershell.exe start needs more than 1.6 s here. Either raise WINDOWS_STOP_CAPS.managerState to cover it (about 4 s) and the admission budget that includes it, or read the TaskState enum without starting a full PowerShell runspace.
  3. When Part A detail is "the stop could not be verified", do not tell the operator that Task Scheduler could not be queried or that ocx service status will show the query error. Say the post-stop status read was inconclusive. schtasks /end has already been issued at that point, so the text should not claim that nothing was stopped.

Checks

Activity

  1. added
    bug
    cli
    platform
    service
    on Nov 17, 2026
  2. coderabbitai commented on Nov 17, 2026

    @coderabbitai
    Contributor
    🔗 Related PRs

    #8573 - feat(service): wire the checked Windows stop into every stop path (#7771 slice 2) [merged]


    📝 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!

  3. jundev0001 commented on Nov 17, 2026

    @jundev0001

    Same failure on ko-KR Windows, on two machines with 2.100.3. Adding data that may affect the fix.

    ko-KR status words. Inside taskState the CSV status column is 준비 (Ready) and 실행 중 (Running). A zh-CN word table does not cover this locale. The child console code page selects the language: under the same execFile(..., { windowsHide: true }) options, cmd /d /c "chcp 437 >nul & schtasks /query /tn opencodex-proxy /fo CSV /nh" returns "Running" (chcp 65001 also returns "Running"). A locale-independent read like this may be more robust than per-locale word lists.

    The cold PowerShell fallback time varies widely, so a fixed cap near 1-4 s is fragile.

    laptop (fails) desktop (passes)
    powershell -NoProfile -Command 1 0.97-1.2 s 0.13-0.14 s
    cold Get-ScheduledTask ... .State 3.1-4.9 s 0.71-0.83 s
    taskState(1000) unknown 3/3 running 10/10, PowerShell 707-760 ms of a 951-966 ms remainder

    Both machines have the same November .NET security updates (KB5132061/KB5132688). On the laptop, the .NET NGEN maintenance task has not run since then because it does not start on battery. Its powershell.exe loads System.Management.Automation, Microsoft.PowerShell.ConsoleHost and Microsoft.Management.Infrastructure as IL, not .ni.dll, and ngen display System.Management.Automation reports "not installed". The desktop regenerated these native images a few hours after the update. So the desktop passes with only about 0.2 s of margin, and any machine can fail between a .NET update and the next NGEN run.

    Replay of Part A (stopWindowsServiceChecked with live probes; endTask/terminate/winswStop stubbed so nothing changed):

    • as shipped: unknown / evidence-unreadable / "the stop could not be verified"
    • parseTaskCsvState accepting the ko-KR words: correct verdict in 2.5 s
    • WINDOWS_STOP_CAPS.managerState = 6000 only: correct verdict in 7.9 s

    Side effect after the failed stop. The update had already ended the task and terminated the bound wrappers. Task last result was 0x41306, the same as in this report. The bun proxy kept running without a wrapper. Then:

    • ocx service status printed "service installed (Task Scheduler); OpenCodex proxy not running".
    • ocx status printed that the proxy was healthy on the same port.
    • ocx restart refused with "the running proxy identity could not be attested".
    • A later ocx update failed the same way.

    Only a reboot (the task's logon trigger) restored a supervised proxy.

  4. lidge-jun commented on Nov 17, 2026

    @lidge-jun
    Owner

    Fixed by #8870, merged into dev as b233a8e (2026-11-17 triage round). PRs target dev, so this is closed manually.

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

    bugcliplatformservice

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions