FuelLabs/sway · error
Failed to execute tasklist command
Error message
Failed to execute tasklist command
What it means
Windows counterpart of the PID liveness check in forc-util's file locking: is_pid_active runs `tasklist /FI "PID eq <pid>"` and this expect panics when tasklist.exe cannot be spawned. As on Unix, the check only runs when an existing lock file's staleness must be determined.
Source
Thrown at forc-util/src/fs_locking.rs:65
.arg("-p")
.arg(pid.to_string())
.output()
.expect("Failed to execute ps command");
let output_str = String::from_utf8_lossy(&output.stdout);
output_str.contains(&format!("{pid} "))
}
#[cfg(target_os = "windows")]
fn is_pid_active(pid: usize) -> bool {
// Not using sysinfo here because it has compatibility issues with fuel.nix
// https://github.com/FuelLabs/fuel.nix/issues/64
use std::process::Command;
let output = Command::new("tasklist")
.arg("/FI")
.arg(format!("PID eq {}", pid))
.output()
.expect("Failed to execute tasklist command");
let output_str = String::from_utf8_lossy(&output.stdout);
// Check if the output contains the PID, indicating the process is active
output_str.contains(&format!("{}", pid))
}
/// Removes the lock file if it is not locked or the process that locked it is no longer active
pub fn release(&self) -> io::Result<()> {
if self.is_locked() {
Err(io::Error::other(format!(
"Cannot remove a dirty lock file, it is locked by another process (PID: {:#?})",
self.get_locker_pid()
)))
} else {
self.remove_file()?;
Ok(())
}
}View on GitHub (pinned to 47e5e902fa)
Solutions
- Run builds on a Windows image that includes tasklist.exe (full/Server Core rather than Nano-style minimal images).
- Remove the stale lock file under the package's out/ directory so the PID check is skipped.
- Adjust sandbox/AV policy to allow spawning tasklist.exe from build processes.
Example fix
# before # Windows Nano Server container + stale .forc-lock -> panic "Failed to execute tasklist command" # after # use mcr.microsoft.com/windows/servercore (has tasklist) and delete stale lock: Remove-Item -Recurse out\*.forc-lock; forc build
Defensive patterns
Strategy: validation
Validate before calling
# PowerShell guard on Windows before forc build
if (-not (Get-Command tasklist -ErrorAction SilentlyContinue)) {
Write-Error "tasklist.exe unavailable; use a fuller Windows image or fix the sandbox"; exit 1
} Prevention
- Prefer Windows Server Core images over Nano-style minimal images for builds.
- Delete stale out/**/.forc-lock files after force-killing forc.
- Allow tasklist.exe in AV/AppLocker policy for build agents.
When it happens
Trigger: A lock file is present and the environment cannot spawn tasklist.exe: stripped-down Windows containers (Nano Server style images without the full toolset), AppContainer/restricted tokens denying execute, antivirus or policy blocking CreateProcess, or corrupted System32 tooling.
Common situations: forc build on Windows Server Core/Nano container images; CI runners with hardened process-creation policies; leftover lock files from a forc process that was force-killed.
Related errors
- Failed to execute ps command
- unable to find the user home directory
- Could not get plugin description.
- Could not get homedir
- Failed to execute ps command
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/8d1b0e249bde9b75.
Report an issue: GitHub.