[Bug][Windows]: ocx stop impossible when WMI GetOwnerSid exceeds the 1 s per-call cap

オープン
#9,026 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
powershell, typescript
領域
cli

調査の方向性

Start in src/service/windows-process-evidence.ts, at windowsProcessSnapshotScript, where each GetOwnerSid call uses a 1 s timeout inside a 1,500 ms owner budget, then follow foreignProcessOwner and bindWindowsStopWrappers into windows-checked-stop.ts, where the evidence-unreadable refusal is returned. Done means a stop succeeds on a host where the owner lookup takes about 1.8 s, or, if it still refuses, the message names the owner-lookup timeout instead of Task Scheduler. The issue leaves the fix direction open, so confirm the approach with maintainers first.

索引モデルが issue の本文から書いたものです。

説明

bug cli platform service
Client or integration

Other — OpenCodex CLI (ocx stop / ocx service stop), not a client integration.

Area

Service lifecycle

Summary

On a Windows host whose WMI Win32_Process.GetOwnerSid is slow (~1.76 s per call), every checked-stop path refuses with "same-account ownership of a service wrapper could not be proven". ocx stop, ocx service stop and the service uninstall path are therefore all unusable while the Task Scheduler wrapper is running. The refusal is surfaced as "The Windows Task Scheduler state could not be read", which misdirects the operator toward Task Scheduler ACLs. Nothing is changed and the proxy keeps running.

The wrapper is in fact owned by the same account as the caller; only the owner lookup exceeds the snapshot's per-call cap.

Expected: the stop succeeds. If it cannot, the refusal should name the real cause (owner lookup timed out) and document a bypass, instead of blaming Task Scheduler access.

Reproduction

Environment: Task Scheduler backend (service-state.json → "backend": "scheduler"), service installed and running, proxy listening on port 10100.

  1. Measure the owner lookup the stop snapshot uses (the wrapper is the wscript.exe running opencodex-service-launcher.vbs):
    $w = Get-CimInstance Win32_Process -Filter "ProcessId=<wscript-pid>"
    Measure-Command { Invoke-CimMethod -InputObject $w -MethodName GetOwnerSid -OperationTimeoutSec 20 }
    
    Observed on this host: 1782 / 1757 / 1756 ms over three calls, every call rv=0 with the correct SID. For reference, #8965 reports a normal Windows x64 desktop resolving 7 owner candidates in 1.4–1.6 s total (~30–100 ms each), so this host is roughly 20–50× slower.
  2. With the wrapper tree running, run ocx stop (or ocx service stop).
  3. Observe the refusal below; the proxy is left running and native Codex is not restored.

Wrapper tree for the minimal trigger:
wscript.exe /b /nologo "%USERPROFILE%\.opencodex\opencodex-service-launcher.vbs" → cmd.exe /c ""%USERPROFILE%\.opencodex\opencodex-service.cmd" " → bun.exe ... src\cli\index.ts start --port 10100.

Version

2.100.7 (latest; npm latest and the GitHub release are both 2.100.7). The same ownership gate also refused on 2.100.4.

Operating system

Windows 11 Pro 26H2, version 10.0.26300, build 26300.9711.

Provider and model

Not provider-specific — the failure happens before any request is sent.

Logs or error output

ocx stop:

❌ 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 (same-account ownership of a service wrapper could not be proven. Stop it from its owning Windows session using Task Manager, then retry); nothing that could not be verified was stopped.
   The proxy was left running and the shared teardown skipped: the service could relaunch it.

ocx service stop:

❌ 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 (same-account ownership of a service wrapper could not be proven. Stop it from its owning Windows session using Task Manager, then retry); nothing that could not be verified was stopped.
   The proxy was left running and native Codex was NOT restored.
Screenshots and supporting files

No screenshots. The timings and process tree above are the supporting evidence.

Redacted configuration

No provider/routing dependence. Relevant service state only:

{ "backend": "scheduler" }
Checks
  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Additional analysis (root cause and suggested direction)

The checked stop enriches the process snapshot with owner SIDs in src/service/windows-process-evidence.ts (windowsProcessSnapshotScript):

  • each owner read is Invoke-CimMethod -InputObject $process -MethodName GetOwnerSid -OperationTimeoutSec 1;
  • the whole owner loop has a 1,500 ms budget and never starts within SNAPSHOT_OWNER_RESERVE_MS (2,000 ms) of the enumeration cap.

On a host where a single GetOwnerSid takes ~1.76 s, every call is cancelled at 1 s, so foreignProcessOwner sees no verified owner and returns null. bindWindowsStopWrappers then puts the otherwise-eligible wrapper into ownershipUnverified, and windows-checked-stop.ts returns finish("unknown", "evidence-unreadable", WRAPPER_OWNER_REFUSAL). Because admission/binding run before any mutation, this blocks ocx stop, ocx service stop, and the uninstall stop alike.

This is a host WMI latency anomaly that the 1 s per-call cap turns into a total loss of stop capability, with a diagnostic that points at Task Scheduler instead of the owner lookup.

Workaround that works today: end the wscript.exe/cmd.exe wrapper first (Task Manager, or Stop-Process -Id <pid> -Force), then run ocx stop — with no wrapper process to bind, the ownership gate is never reached and the stop/restore completes. Disabling the task (schtasks /Change /TN opencodex-proxy /DISABLE) prevents an immediate respawn.

Suggested directions:

  • Prefer native same-handle evidence (creation time plus token SID) over repeated CIM GetOwnerSid calls. #8933 already proposes this for the Link stop path; extending it to the service checked-stop would remove the WMI round-trip entirely.
  • Or make the per-call timeout adaptive/retryable, and make the refusal text name "owner lookup timed out" rather than "Task Scheduler state could not be read".
  • At minimum, document a supported bypass (--force/env) so a slow-WMI host is not locked out of stopping its own service.

Related: #8965 (merged; bounds owner reads inside the enumeration cap, but skipped owners stay unknown and binding still refuses), #8933 (open; native same-handle owner proof).

主要言語
TypeScript
スター
16.9k
フォーク
1.3k
平均マージ
1日 2時間
マージ済み PR(30日)
844

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lidge-jun/opencodex のほかの issue

lidge-jun/opencodex の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。