Skip to content

Fix power plan switching after process exit - #124

Open
PrimeBuild-pc wants to merge 1 commit into
mainfrom
fix/power-plan-process-exit
Open

PrimeBuild-pc wants to merge 1 commit into
mainfrom
fix/power-plan-process-exit

Conversation

@PrimeBuild-pc

Copy link
Copy Markdown
Owner

Summary

A process can exit while ThreadPilot is still handling its start. A delayed power plan switch can then leave the rule's plan active after the process has gone, even with a default plan configured.

This change checks that the process is still running before requesting the switch and reevaluates the remaining processes after any switch already in progress. The configured default is restored after the last matching instance exits.

Related to #123.

Verification

  • Release suite passed all 944 tests, including five new regression cases.
  • Verified with native WMI and fallback polling disabled. Starting the first instance activated the rule's plan, closing it kept that plan active while a second instance ran, and closing the last instance restored the configured default.
  • Confirmed the active plan changes in the Power plans screen using an isolated test profile.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T14:58:45.675568Z e338cce PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e338cce5d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Read the list after any in-flight plan change has completed. Stop events
// remove their processes before waiting for this lock.
var candidates = this.runningAssociatedProcesses.Values
.Select(process => (Process: process, Association: configuration.FindMatchingAssociation(process)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reconcile cached processes before reevaluating the plan

If WMI recovery misses a process stop and start while Windows reuses that PID for a process with no association, the snapshot cleanup keeps the old entry because the PID is still present. This candidate enumeration then evaluates the stale ProcessModel, and IsProcessStillRunning checks only the PID, so the replacement process can activate the old process's plan. Reconcile cached entries against the current process identity before using them.

Useful? React with 👍 / 👎.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 79.26829% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Services/ProcessMonitorManagerService.cs 79.26% 6 Missing and 11 partials ⚠️

📢 Thoughts on this report? Let us know!

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants