Skip to content

fix(windows): query the named task within the stop deadline - #8974

Merged
lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/windows-stop-exact-task-registration
Nov 21, 2026
Merged

lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/windows-stop-exact-task-registration

Conversation

@luvs01

@luvs01 luvs01 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When the Windows Desktop updater drains the proxy, the shipped registration probe can spend its two-second deadline listing every scheduled task after a named query misses. A machine with no OpenCodex task can consequently report unreadable service registration.

Query the fixed root task using the trusted schtasks.exe /query /tn \opencodex-proxy /fo CSV /nh /hresult. On x64 the live runner pins the spawned child with a read-only Windows process handle, reads its full exit code after completion, and releases the handle. An exact matching CSV row proves presence. The full 0x80070002 from the named lookup with a consistent process result proves absence. Bun 1.4.4 exposes only the low byte through its ordinary child exit status, so the value 2 alone supplies no such proof. Other HRESULTs and late answers leave the registration unknown. The exact COM lookup remains available within the original deadline where the full native result cannot be captured.

Verification

  • Integration with the other Windows stop changes. On e632b73c, the three focused Windows stop suites passed all 65 tests (409 assertions). I combined fix(service): enforce Windows stop evidence and deadline boundaries #8931 (02ef13eb), this PR (e632b73c) and fix(windows): recognize Korean disabled and queued task states #8976 (37d9f429) locally. All six merge orders produced tree 8de47af512ebed48dd62e286ce4cedb4d036e535 without conflict. Five Windows suites on that tree passed 141 tests (681 assertions). Three additional integration checks passed: the named task probe and state parser handled Korean queued/disabled values without a PowerShell fallback, and a spent pre-dispatch budget prevented a Scheduler query from starting. Both the standalone and combined trees passed typecheck, structure and diff checks. The Desktop installation described below was tested on the earlier revision.
  • Windows x64, Bun 1.4.4. With no root OpenCodex task, the v2.100.5/pre-change dev probe returned unknown at 2,017 ms. A full listing took 4,146 ms for 607 lines. The updated live runner observed child status 2, native exit code 2147942402, and returned absent after 112 ms. Under concurrent validation, a late answer was rejected at the original deadline.
  • Desktop regression in the initial PR revision. In a Windows Sandbox, stock v2.100.5 completed a real tray update to v2.100.6. A v2.100.5 backport of the initial COM-only revision instead downloaded the update and failed the runtime drain. The same user, session, and token took 2,238 ms just to launch and finish the COM helper. The named native /HRESULT query returned 0x80070002 there in 66 ms.
  • Actual Desktop update with the revised native-handle change. In the same isolated Windows guest, the v2.100.5 Desktop shell owned the running v2.100.5 sidecar built with the production changes from 94500b43. The ordinary tray Install update action at 10:35:40 handed off to Windows Installer at 10:35:57. At 10:38:06 the official v2.100.6 MSI completed with exit code 0 (MsiInstaller events 1033, 11707 and 1042). The accepted MSI matched the official SHA-256. The old shell and sidecar exited. The official v2.100.6 shell relaunched automatically, started its own v2.100.6 listener, and returned HTTP 200 from /healthz. The guest returned HTTP 503 from /readyz before and after the update. This run verifies the normal updater handoff, installation, and runtime restart. It leaves the independent readiness condition unresolved. The stock control succeeded under a different initial state.
  • bun --no-env-file --no-install scripts/test.ts --no-env-file --no-install --isolate --parallel=1 tests/windows/windows-checked-stop-live.test.ts tests/windows/windows-process-evidence.test.ts tests/windows/windows-service-stop-wiring.test.ts passed all 65 tests, 409 assertions. A native child-process test distinguishes two 32-bit HRESULTs that both end in 02. The PowerShell fixture covers a missing task, denied access, inaccessible service/folder, and invalid output.
  • bun run typecheck passed for 2,681 files. bun run structure:check and git diff --check passed. Local validation used the affected Windows suites on a shared workstation. Broader suite coverage is left to CI.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows scheduled-task status reporting. A task is reported as absent only when the system confirms it is missing; connection issues, access denials, timeouts, and inconclusive results remain unknown.
    • Windows stop results now preserve the process exit code when available, supporting more precise status checks.
    • When direct exit-code capture is unavailable, a bounded fallback check can confirm task registration.
  • Documentation
    • Clarified how Windows scheduled-task registration is checked and when its status remains unknown.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Windows checked-stop probe uses full process exit codes and bounded Scheduler queries to classify a task as present, absent, or unknown. When native exit-code capture is unavailable, it uses the remaining deadline for a Scheduler registration probe.

Changes: Windows Scheduler registration probe

Layer / File(s) Summary
Capture child exit codes
src/service/windows-process-native.ts, src/service/windows-checked-stop-live.ts
The native API can read a child’s full Windows exit code after the process exits. The live runner adds the captured code to command results unless the child was killed.
Classify Scheduler registration
src/service/windows-checked-stop-live.ts, tests/windows/windows-checked-stop-live.test.ts, structure/ops/windows-checked-stop.md
The probe uses a deadline-bounded /hresult query. It reports absence only when the missing-task HRESULT and process status agree. If native exit-code capture is unavailable, it uses the remaining deadline for a Scheduler registration probe. Tests and documentation cover result classification and timeout behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to e632b

The change makes the Windows updater's scheduled-task lookup fit within the two-second stop deadline, with a fallback when the full exit code cannot be captured. No concrete merge-blocking risk was found; the affected Windows test suites are reported as passing.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the Windows stop path now queries the named scheduled task within the stop deadline instead of listing every task after a named lookup misses. The raw summary and obje…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: the Windows stop path now queries the named scheduled task within the stop deadline instead of listing every task after a named lookup misses. The raw summary and objectives both center on a bounded /query /tn /hresult probe with a PowerShell and COM fallback, so the title matches the changeset. It is specific, concise, and uses the conventional fix(scope) format.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 94500b4 and e632b73.

Files selected for processing: 2

  • src/service/windows-checked-stop-live.ts
  • structure/ops/windows-checked-stop.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@github-actions

github-actions Bot commented Nov 20, 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 20, 2026
@luvs01
luvs01 marked this pull request as ready for review November 20, 2026 02:38
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration into dev (per MAINTAINERS.md; maintainer integration, not an independent approval)

  • Exact head: e632b73ccb8dabb79a9a8e45951ed86310057846
  • Checks on this head: 20 passed, 13 skipped, none pending or failing (Ubuntu PR CI; Windows/macOS are covered by the next dev batch gate).
  • Review threads: none unresolved.
  • Review: gpt-6.1-terra, two rounds, final verdict PASS (handle lifetime and PID reuse concerns withdrawn: the exit-code reader runs from the execFile completion callback and closes its handle in finally; capture happens synchronously after spawn while the child handle is still held).
  • Regression: the Scheduler registration test fails with src/service/windows-checked-stop-live.ts restored from dev. Native HRESULT capture and PowerShell fixtures run only on Windows (the next dev batch gate).
  • Recheck against current dev: merged locally with fix(service): enforce Windows stop evidence and deadline boundaries #8931 and fix(windows): recognize Korean disabled and queued task states #8976 (already on dev); Windows stop suites 402 pass / 7 skip / 0 fail in the combined focused set.

@lidge-jun
lidge-jun merged commit cc304ef into lidge-jun:dev Nov 21, 2026
41 checks passed
lidge-jun added a commit to luvs01/opencodex that referenced this pull request Nov 21, 2026
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.

kaicot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Additional real-world reproduction on Windows 11 Pro x64 (10.0.26100), OpenCodex Desktop 2.100.7:

  • Desktop initially timed out waiting for the runtime, then Take over failed with the guarded stop could not confirm the approved runtime (outcome failed, proxy unknown, exit 1).
  • ocx stop --json --deadline-ms 120000 independently returned service: state-unknown, serviceStopReason: evidence-unreadable, and left the proxy running. ocx service status reported no installed Task Scheduler service.
  • The root opencodex-proxy task was absent. A full schtasks /query /fo CSV listing took 8.8 seconds in one measurement (an earlier listing took ~55 seconds), exceeding the shipped two-second registration probe budget. The exact root task query with /fo CSV /nh /hresult returned 0x80070002 in 77, 47, and 46 ms.
  • Desktop's Stay a guest path opened the dashboard, but the user wants Desktop to take ownership normally. The initial log also reported Codex write refused (service-home); its exact cause has not been independently verified and may involve a separate probe.

This looks consistent with the issue addressed here. The /hresult measurements are command-level checks only; we have not tested the patched runtime or a successful takeover on this machine. Desktop's update check currently reports 2.100.7 as up to date. Please consider including the fix in the next stable Desktop release and covering a slow full-listing/no-task takeover scenario.

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.

3 participants