Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:777genius Agent teams ai killTeamProcessAndWait

From Leeroopedia
Knowledge Sources
Domains Process_Management, Team_Management
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for safely terminating team CLI process trees with SIGKILL and exit confirmation, provided by the Agent Teams application.

Description

The killTeamProcessAndWait function terminates a spawned team CLI process and all its descendants using SIGKILL (uncatchable). It confirms the process tree is dead before releasing resources. The synchronous companion killTeamProcess sends SIGKILL without waiting.

Key behaviors:

  • SIGKILL enforcement: Newer Claude CLI versions (>=2.1.x) handle SIGTERM gracefully and run cleanup that deletes team files. SIGKILL is uncatchable and prevents this destructive cleanup.
  • Platform-aware tree kill: On Unix, the process-group identity captured at spawn time identifies descendants even after the root PID exits. On Windows, `taskkill` accepts only a PID, so a reused PID is unsafe — the function skips tree kill if the root already exited on Windows.
  • Exit confirmation: Listens for 'close' and 'exit' events with a 5-second timeout. If the process does not exit within the timeout, falls back to PID-based tree kill.
  • stdin.end() prohibition: EOF on stdin triggers the same cleanup as SIGTERM in some CLI versions; this function never calls `stdin.end()`.

Usage

  • Team shutdown: Call `killTeamProcessAndWait(child)` during team teardown to terminate the process tree and confirm exit before cleanup.
  • Immediate kill: Call `killTeamProcess(child)` when you need to send SIGKILL without waiting (e.g., during app quit when all processes must die immediately).

Code Reference

Source Location

  • Repository: agent-teams
  • File: src/main/services/team/provisioning/TeamProvisioningRunProgress.ts

Signature

/** Kill the owned team process tree and confirm it is gone before resource release. */
export async function killTeamProcessAndWait(
  child: ChildProcess | null | undefined
): Promise<void>;

/** Kill a team CLI process using SIGKILL (uncatchable). Does NOT wait. */
export function killTeamProcess(
  child: ChildProcess | null | undefined
): void;

Import

import { killTeamProcessAndWait, killTeamProcess } from '@main/services/team/provisioning/TeamProvisioningRunProgress';

I/O Contract

Inputs

Name Type Required Description
child null | undefined Yes The spawned team lead process handle to terminate

Outputs

Name Type Description
return Promise<void> Resolves when the process tree is confirmed dead (or was already dead)

Usage Examples

Team Shutdown

import { killTeamProcessAndWait } from '@main/services/team/provisioning/TeamProvisioningRunProgress';

// During team teardown: kill and wait for confirmation
await killTeamProcessAndWait(teamProcess);

// Safe to clean up worktrees, inboxes, and config now
await cleanupTeamResources(teamName);

Immediate Kill During App Quit

import { killTeamProcess } from '@main/services/team/provisioning/TeamProvisioningRunProgress';

// During app quit: send SIGKILL to all team processes without waiting
for (const [teamName, process] of activeTeams) {
  killTeamProcess(process);
}
// App can exit immediately; OS will reap the processes

Guard Against Already-Exited Process

// The function handles already-exited processes safely:
// - If child.pid is falsy, returns immediately
// - If child.exitCode or child.signalCode is set, skips SIGKILL on root
// - On Windows, if root already exited, skips tree kill (PID reuse safety)
await killTeamProcessAndWait(alreadyExitedChild);
// Resolves immediately, no error

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment