LGUG2Z/komorebi · error
could not determine current session id
Error message
could not determine current session id
What it means
process_id_to_session_id calls the Win32 ProcessIdToSessionId API on the current process id to obtain the terminal-services session id. If the API fails, komorebi bails with 'could not determine current session id'. This is essentially an OS-level failure to map the current PID to a session.
Source
Thrown at komorebi/src/windows_api.rs:867
HWND(as_ptr!(hwnd)),
Option::from(std::ptr::addr_of_mut!(process_id)),
)
};
(process_id, thread_id)
}
pub fn current_process_id() -> u32 {
unsafe { GetCurrentProcessId() }
}
pub fn process_id_to_session_id() -> eyre::Result<u32> {
let process_id = Self::current_process_id();
let mut session_id = 0;
unsafe {
if ProcessIdToSessionId(process_id, &mut session_id).is_err() {
bail!("could not determine current session id")
}
}
Ok(session_id)
}
#[cfg(target_pointer_width = "64")]
fn set_window_long_ptr_w(
hwnd: HWND,
index: WINDOW_LONG_PTR_INDEX,
new_value: isize,
) -> eyre::Result<()> {
Result::from(WindowsResult::from(unsafe {
SetWindowLongPtrW(hwnd, index, new_value)
}))
.map(|_| {})
}
View on GitHub (pinned to e0709f02bf)
Solutions
- Run komorebi inside the interactive user desktop session (not as a service or from SSH)
- Verify ProcessIdToSessionId's return value/error code with GetLastError for the specific cause
- Ensure the current process id is valid and not terminating
- Avoid calling this in service contexts; gate it behind an interactive-session check
Example fix
// before
let session_id = WindowsApi::process_id_to_session_id()?;
// after
let session_id = WindowsApi::process_id_to_session_id()
.context("komorebi must run in an interactive user session")?; Defensive patterns
Strategy: try-catch
Validate before calling
// Check process is in the interactive session
fn is_interactive_session() -> bool {
std::env::var("SESSIONNAME").map(|s| s.starts_with("Console")).unwrap_or(false)
} Try / catch
let session_id = match WindowsApi::process_id_to_session_id() {
Ok(id) => id,
Err(e) => {
log::error!("komorebi must run in an interactive desktop session: {e}");
std::process::exit(1);
}
}; Prevention
- Launch komorebi from the user's interactive desktop session, never as a service
- Avoid running komorebi over SSH or from session-0 contexts
- Log GetLastError details when ProcessIdToSessionId fails to diagnose session context
- Document the interactive-session requirement in your deployment scripts
When it happens
Trigger: Calling WindowsApi::process_id_to_session_id() in an environment where ProcessIdToSessionId fails, e.g. the process is not attached to an interactive session or the API returns FALSE (invalid process id, service-session contexts).
Common situations: Running komorebi from a service session, SSH session, or scheduled task that is not attached to the interactive desktop session; heavily restricted sandboxed environments.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- failed call to AllowSetForegroundWindow after 5 retries
- window handles for move operation don't match: {} != {}
- could not close window
- could not find next window
- could not find device_id for hmonitor: {hmonitor}
AI-assisted analysis of LGUG2Z/komorebi@e0709f02bf (2026-09-06).
Data as JSON: /api/errors/80af4aed287e8fe5.
Report an issue: GitHub.