Skip to content

fix(windows): check the stop deadline after reading the idle task state - #9058

Merged
lidge-jun merged 6 commits into
lidge-jun:devfrom
luvs01:codex/windows-idle-task-deadline
Nov 25, 2026
Merged

lidge-jun merged 6 commits into
lidge-jun:devfrom
luvs01:codex/windows-idle-task-deadline

Conversation

@luvs01

@luvs01 luvs01 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Windows Task Scheduler helper reads the registered task's state before it reports that no instances are running. On a slow host that final COM read can consume the remaining stop budget. The helper now reads the state once and checks the elapsed time before accepting a ready or disabled task as idle.

This follows up on the timing case found during #9027. #9026 also involves the installed service and desktop updater. That end-to-end check remains open.

Verification

  • On Windows x64 with Bun 1.4.4, the new test advances a synthetic clock to the exact deadline during the final state read. On the base commit the helper returned not-running. With this change it returns failed. Both cases made zero stop calls.
  • bun test tests/windows/windows-checked-stop.test.ts tests/windows/windows-checked-stop-live.test.ts passed all 82 cases with 327 assertions.
  • bun check --no-script --noEmit, bun scripts/structure-ssot.ts, bun scripts/privacy-scan.ts, and git diff HEAD^ HEAD --check passed.
  • Local validation covered the shared stop helper and its Windows callers. Concurrent Windows validation on the same host limited the local run to the affected suites. Broader coverage remains with CI.

Checklist

  • Scope stays focused on the final idle-state read.
  • The Windows checked-stop documentation describes the deadline.
  • Reviewed the deadline branch for unsafe defaults. It performs no stop operation.

Summary by CodeRabbit

  • Bug Fixes

    • Stop checks now recheck the deadline when no running task instances are found. If the deadline has elapsed, the result is reported as failed; otherwise, the task is reported as not running only when its state can be verified.
    • An empty instance list no longer proves a task is idle unless its final state is ready or disabled. Unverifiable states are reported as unreadable evidence, with guidance to verify the task and seek repair assistance.
  • Documentation

    • Clarified that stopping a running instance alone does not repair an unverifiable task registration.

A slow final Task Scheduler state read could outlast stop-before and report the task idle. Check the deadline after sampling the state. Cover the cutoff with a simulated getter and a zero-stop assertion.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 99944b2 and 921cfd8.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

When no task instances are captured, the stop path reads the task state and checks the deadline before returning a result. The helper documentation and live test describe and cover this idle-state deadline behavior.

Changes: Windows checked stop

Layer / File(s) Summary
Idle-state deadline check
structure/ops/windows-checked-stop.md, src/service/windows-task-instance-stop.ts, tests/windows/windows-checked-stop-live.test.ts
The stop path returns failed if the deadline has elapsed after the task-state read. Before the deadline, states 1 or 3 return not-running; other states return unverified-registration. The documentation describes the final-state requirement, and the live test expects failed when the deadline elapses on the second state read.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · previous review cbbea

This change stops the Windows stop helper from reporting a task as idle when reading its state used up the remaining deadline. The change is small and covered by a targeted test, with no concrete merge-blocking risk identified. The installed-service and updater end-to-end check remains open.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix and its specific behavior: the Windows stop helper now checks the stop deadline after reading the idle task state. The raw summary and objectives both describe this change: a d…
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.
Full details: Title check

Explanation

The title names the fix and its specific behavior: the Windows stop helper now checks the stop deadline after reading the idle task state. The raw summary and objectives both describe this change: a deadline re-check after the final idle-state read, which returns failed instead of not-running or unverified results when the deadline has elapsed. The title is concise, specific, and follows the conventional fix(scope) format. It does not mention the evidence-unreadable status or the test additions, which are secondary details.

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 9e0e298 and cbbeac1.

Files selected for processing: 3

  • src/service/windows-task-instance-stop.ts
  • structure/ops/windows-checked-stop.md
  • tests/windows/windows-checked-stop-live.test.ts

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

@github-actions

github-actions Bot commented Nov 23, 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 23, 2026

luvs01 commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Checked the interaction with #9027 at 470bd8278. The two changes previously inserted test cases at the same spot. cbbeac158 moves only the new deadline case within the test table. Both merge orders now produce tree 8f8525b4, with the two native ownership cases and the idle deadline case intact.

On Windows x64 with Bun 1.4.4, the affected PowerShell fixture passed all 58 assertions on that combined tree. It used a mock Scheduler and synthetic process identities. The runtime code in this PR is unchanged from the previously tested commit.

@luvs01
luvs01 marked this pull request as ready for review November 23, 2026 03:15
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration (lane W, @lidge-jun) at exact head 921cfd849506852514cd68e5397cc161d45db812, which contains current dev 9b5861c1a1 (0 commits behind).

  • PR CI on this head: all 19 checks pass, including gates, test changed and ci. The exact-head test changed job on a branch containing current dev is the test:changed evidence (coordinator ruling; local test:changed could not finish under host load).
  • Local, macOS: bun run typecheck clean; tests/windows/windows-checked-stop.test.ts + windows-checked-stop-live.test.ts 79 pass / 0 fail.
  • Real Windows x64 (Bun 1.4.4), PR head merged with dev: the same two files 82 pass / 0 fail, including the new idle-state-deadline case.
  • Independent gpt-6.1-terra review: PASS, no findings.
  • scripts/ci/assert-mergeable-review.sh --maintainer-integration 9058: OK.

This also closes the late idle-state read the #9027 review flagged as pre-existing.

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