Skip to content

fix(windows): verify service owners when WMI evidence is missing - #9027

Draft
luvs01 wants to merge 3 commits into
lidge-jun:devfrom
luvs01:codex/windows-wrapper-owner-evidence
Draft

luvs01 wants to merge 3 commits into
lidge-jun:devfrom
luvs01:codex/windows-wrapper-owner-evidence

Conversation

@luvs01

@luvs01 luvs01 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • A Windows service stop can lose wrapper ownership evidence when a bounded WMI owner lookup returns no sample. On Windows x64, check eligible wrappers from this installation using a query-only process handle. The observed creation time must match the original CIM sample to the microsecond, and the process token must match the caller and the supported Windows account named by the helper.
  • Verify the engines of the captured Task Scheduler instances with the same native identity primitive before authorizing the existing COM stop operation. Keep the registration, instance and deadline checks. Inconclusive or contradictory evidence continues to refuse the stop. Hosts without native support keep the bounded CIM path.
  • Report the available Windows stop reason in the CLI. Distinguish a registration query failure from a later ownership or process-evidence refusal in operator guidance. The management endpoint retains its 409 and service_state_unknown contract.

Refs #9026. The reported WMI latency is specific to the reporter's host. This draft is ready for ownership-boundary review and independent Windows testing.

Verification

  • Windows x64, Bun 1.4.4: bun test --isolate across seven files covering process evidence, wrapper binding, checked stop, its command adapter and callers, the Windows CLI stop, and graceful process control: 198 passed, 0 failed (946 assertions).
  • Eight selected CLI, uninstall, HTTP and fallback-message cases across five files passed (94 assertions; includes overlap with the preceding suite). Coverage includes rejected owners, timestamp mismatches, expired deadlines, changed registrations, and the distinction between registration and ownership errors.
  • A query-only physical Windows check observed the real CIM image, command line and creation time of a disposable launcher process. With only its WMI owner sample deliberately omitted, the native fallback established same-account ownership in a 1.61 s snapshot. The target received no stop request in this check.
  • bun run typecheck (2,688 files), bun run structure:check, bun run privacy:scan, git diff --check, and the documentation build (820 pages, 126,243 internal links) passed. Local coverage was focused to keep the full shared Windows run bounded. Upstream CI is checked separately for the submitted head.

Checklist

  • Scope stays focused on Windows service ownership evidence and its diagnostics.
  • The checked-stop architecture contract and operator documentation are updated.
  • Maintainer security review of process identity binding and Scheduler authorization.

Use same-account query handles for eligible wrapper snapshots and captured Scheduler engines on Windows x64. Keep ambiguous identities, expired deadlines and changed registrations refused, and report Windows stop evidence separately from a registration query failure.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 21, 2026
@luvs01

luvs01 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Windows Sandbox acceptance on cc980ed0d (Windows x64 build 26100.10075, Bun 1.4.4). The candidate executable was built from this PR's exact Git tree.

The guest started with empty application homes, no registered OpenCodex task and no listener on port 10100. ocx service install --scheduler exited 1 with “the task end command did not answer within its cap” and reported rolling back the new registration. After rollback, no task, service wrapper, candidate process or listener remained. There was no running service on which to exercise ocx stop.

I timed a read-only control inside the same guest, from spawning trusted Windows PowerShell until child exit. Empty startup/exit took 1.94 s. With the task absent, the initial registration lookup from the native helper took 2.60 s and 2.32 s; the equivalent legacy helper took 2.76 s and 2.42 s. Each lookup exceeded the existing 2 s task-end budget, before any per-engine owner query was needed. These controls do not establish which COM or authorization step the original install reached.

This leaves two separate results: the actual-handle fallback accepted a same-account wrapper with a missing WMI owner in the physical Windows check, while the full install-to-stop acceptance remains open on this guest. The original reporter's 1 s WMI-owner symptom and this guest's task-end timeout should be tracked separately.

Resolve against lidge-jun#8931 and lidge-jun#8974: keep dev's framed baseline snapshot,
partial output, stop-before cutoff and mutation evidence, and apply this
branch's native engine-identity proof and missing-owner fallback on top.
The engine-proof verdict still has to match the helper verdict, and the
fixture helper gains the dev clock and approval stubs plus both scenario sets.
@lidge-jun

Copy link
Copy Markdown
Owner

Integration status from the current maintainer batch:

  • I merged dev into this branch (470bd8278) to resolve conflicts with fix(service): enforce Windows stop evidence and deadline boundaries #8931 and fix(windows): query the named task within the stop deadline #8974, which changed the same Scheduler-stop and snapshot code. The resolution keeps dev's framed baseline snapshot, partial output, stop-before cutoff and mutation evidence, and applies this PR's native engine-identity proof and missing-owner fallback on top. With native identity, the helper verdict must still equal the engine-proof verdict.
  • On that head: typecheck clean, structure:check passes, 10 touched or adjacent test files give 502 pass / 8 skip / 0 fail on macOS (the skips are native Windows and PowerShell cases).
  • gpt-6.1-terra review (two rounds): PASS, no findings. A process from another user or installation, or a reused PID, cannot gain foreignOwner=false: the fallback only fills an absent CIM owner sample and requires a wrapper image carrying this installation's path token, an exact CIM-tick creation match, and a token SID equal to both the caller and the helper-reported SID.

This stays in draft: the PR's own checklist asks for a maintainer security review of the process-identity binding, and native Windows validation is still outstanding. I've handed it to the maintainers for that review.

@luvs01

luvs01 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for resolving the merge. I tested the published head 470bd8278 on a physical Windows x64 host with Bun 1.4.4. The eight Windows stop, snapshot, binding, caller and graceful-control test files passed with 232 tests, 1,154 assertions and zero skips. Typecheck and the structure check passed. In a separate query-only check, the real creation time and account of an owned wrapper were confirmed from a complete baseline frame followed by an incomplete enrichment frame. The WMI owner sample was absent and the check took 0.62 s.

One non-mutating timing edge remains in the shared Scheduler helper. When an empty instance collection was returned and the final COM .State getter consumed the rest of stop-before, the helper reported not-running. It issued zero Stop() calls. A small follow-up samples the state once, then checks the clock before reporting it. Its regression failed on this head and passed with that change. The two related test files passed all 63 cases. The follow-up is separate from the branch under maintainer review.

The earlier Sandbox install result applied to cc980ed0d. An installed Scheduler service on the reporter's slow-WMI host remains the outstanding end-to-end check.

This branch has not been deployed

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants