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

Aperta
#9,026 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
powershell, typescript
Ambito
cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
TypeScript
Stelle
16.9k
Fork
1.3k
Merge medio
1g 2h
PR unite (30g)
844

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lidge-jun/opencodex

Tutte le issue di lidge-jun/opencodex

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.