slopus/happy · warning

taskkill exited with code ${result.status}

Error message

taskkill exited with code ${result.status}

What it means

On Windows, killRunawayHappyProcesses uses spawn.sync('taskkill', ['/F', '/PID', ...]); if taskkill exits non-zero (target not found, access denied), the error is thrown. On Unix the code path uses process.kill with SIGTERM instead and never throws this message.

Source

Thrown at packages/happy-cli/src/daemon/doctor.ts:97

}

/**
 * Kill all runaway Happy CLI processes
 */
export async function killRunawayHappyProcesses(): Promise<{ killed: number, errors: Array<{ pid: number, error: string }> }> {
  const runawayProcesses = await findRunawayHappyProcesses();
  const errors: Array<{ pid: number, error: string }> = [];
  let killed = 0;
  
  for (const { pid, command } of runawayProcesses) {
    try {
      console.log(`Killing runaway process PID ${pid}: ${command}`);
      
      if (process.platform === 'win32') {
        // Windows: use taskkill
        const result = spawn.sync('taskkill', ['/F', '/PID', pid.toString()], { stdio: 'pipe' });
        if (result.error) throw result.error;
        if (result.status !== 0) throw new Error(`taskkill exited with code ${result.status}`);
      } else {
        // Unix: try SIGTERM first
        process.kill(pid, 'SIGTERM');
        
        // Wait a moment
        await new Promise(resolve => setTimeout(resolve, 1000));
        
        // Check if still alive
        const processes = await psList();
        const stillAlive = processes.find(p => p.pid === pid);
        if (stillAlive) {
          console.log(`Process PID ${pid} ignored SIGTERM, using SIGKILL`);
          process.kill(pid, 'SIGKILL');
        }
      }
      
      console.log(`Successfully killed runaway process PID ${pid}`);
      killed++;

View on GitHub (pinned to b824cd0a46)

Solutions

  1. Re-run the doctor command — if the PID was stale, it will no longer be detected
  2. Run the terminal as Administrator so taskkill has permission to force-kill
  3. Verify the PID belongs to a happy process with `tasklist /FI "PID eq <pid>"` before killing
  4. Manually run `taskkill /F /PID <pid>` to see the specific Windows error

Example fix

// before
if (result.status !== 0) throw new Error(`taskkill exited with code ${result.status}`);
// after
if (result.status !== 0) {
  logger.warn(`taskkill could not kill PID ${pid} (exit ${result.status}); it may have already exited`);
} else {
  logger.log(`Killed PID ${pid}`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Windows: verify the PID is still a happy process and that we can kill it
execSync(`tasklist /FI "PID eq ${pid}"`); // throws or shows absence

Try / catch

try {
  killRunawayHappyProcesses();
} catch (err) {
  if (String(err.message).startsWith('taskkill exited')) {
    console.warn('Could not force-kill PID (stale or access denied). Try an elevated terminal.');
  } else throw err;
}

Prevention

When it happens

Trigger: Doctor-mode cleanup finds a runaway happy process PID and taskkill /F fails — the process already exited between detection and kill, or the shell lacks permission to force-kill it.

Common situations: Stale PID from a previous session (process gone), running the doctor command without admin/elevated privileges, antivirus blocking taskkill, or PID reuse by a protected system process.

Related errors


AI-assisted analysis of slopus/happy@b824cd0a46 (2026-08-31). Data as JSON: /api/errors/142760ba31ca2bfb. Report an issue: GitHub.