Skip to content

fix(cli): scope process detection to the current session - #1743

Open
fvarano wants to merge 1 commit into
LGUG2Z:masterfrom
fvarano:fix/session-scoped-process-detection
Open

fvarano wants to merge 1 commit into
LGUG2Z:masterfrom
fvarano:fix/session-scoped-process-detection

Conversation

@fvarano

@fvarano fvarano commented Aug 26, 2026

Copy link
Copy Markdown

Summary

Support running komorebi in multiple Windows sessions at the same time (e.g, Fast User Switching) without conflicts.

At the moment it is not possible to run Komorebi in two different Windows accounts if both are signed in.
I spotted this because i was trying to setup a new local account, and wasn't able to run the WM when the other user was already running it, but the CLI didn't give me any incling of what was happening. It just saw a process called "komorebi.exe" and assumed it was already running, so it skipped the start command entirely.

  • komorebic start/stop/kill matched komorebi.exe (and whkd, komorebi-bar, masir, AutoHotkey) by process name alone, system-wide. On a machine with more than one Windows session (RDP, Fast User Switching, a session-0 service instance), an instance running in a different session was indistinguishable from one in the caller's own session:
    • start could report an existing instance in another session as "already running" and skip launching a new one in the current session.
    • stop/kill could count/target processes across all sessions, producing false "still running" force-quit attempts and PowerShell scripts that filtered by name only.
  • Resolve the caller's session id natively (GetCurrentProcessId + ProcessIdToSessionId, mirroring what komorebi's core already does via WindowsApi::process_id_to_session_id) and use that session_id in every PS script to filter processes.
  • The komorebi.exe startup guard in komorebi/src/main.rs gets the same session filter so the duplicate-instance check only considers processes in the same session.
  • Note: i opted to use .replace instead of a format! String because doing that would have needed some escaping (braces in particular) in the PowerShell scripts. I thought it might have been more valuable to avoid that, keeping the scripts as close as possible to native PS for readability and debuggability, at the cost of being a bit less idiomatic. It is surely possible to do better there.

Test plan

  • cargo check and cargo clippy pass for both komorebi and komorebic
  • Manual verification of komorebic start/stop/kill in a single-session setup
  • Manual verification in a multi-session (RDP / Fast User Switching) setup

I used Devin to find the problems and write up the initial summary of this PR, but most of the code I wrote myself, and of course, I executed the manual tests.

komorebic start/stop/kill matched komorebi.exe (and whkd, komorebi-bar,
masir, AutoHotkey) by name alone, system-wide. On a machine with more
than one Windows session (RDP, Fast User Switching, a session-0 service
instance), an instance running in a different session was
indistinguishable from one in the caller's own session:

- `start` would report an existing instance in another session as
  already running and skip launching a new one in the current session.
- `stop`/`kill` would count/target processes across all sessions,
  producing false "still running" force-quit attempts and PowerShell
  scripts that filtered by name only.

Resolve the caller's session id natively (GetCurrentProcessId +
ProcessIdToSessionId, mirroring what komorebi's core already does via
WindowsApi::process_id_to_session_id) instead of shelling out to
PowerShell and parsing its output, and filter every process lookup and
generated PowerShell script by that session id. The komorebi.exe
startup guard in komorebi/src/main.rs gets the same session filter so a
duplicate-instance check only considers processes in the same session.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant