---
title: "Parallel agent sessions: a pattern-based pkill in one session kills every other session's test run"
url: "https://www.dariuszparys.com/notes/pattern-based-pkill-kills-other-sessions-test-runs"
author: "Dariusz Parys"
published: 2026-11-24T00:00:00.000Z
description: "A test run in one git worktree died with exit code 144 and SQL connection errors because a coding-agent session in another worktree stopped its own run with pkill -f, and the pattern matched the processes of every session on the machine."
tags:
  - "Agentic Coding"
  - "AI"
  - "Shell"
  - "Testing"
---

# Parallel agent sessions: a pattern-based pkill in one session kills every other session's test run

## Context

Several coding-agent sessions run a heavy test suite at the same time, each in its own git worktree, on one machine with a shared Docker VM. A wrapper script starts one SQL Server container per run and removes it on SIGTERM.

## Symptom

A run dies with an odd exit code (144), and the test hosts still running throw SQL "transport-level error / connection terminated" exceptions. No test fails, and one test host is left behind.

## Insight

The SQL errors are a symptom, not the cause. Another session stopped its own run with a pattern:

```sh
pkill -f 'just backend-test'; pkill -f 'dotnet test'
```

That pattern matches every session's processes. The killed wrapper removed its SQL container on the way out, so the test hosts that survived lost their database.

## Finding the culprit

```sh
# Map surviving test processes to their worktree
lsof -a -p <pid> -d cwd -Fn | grep ^n

# Search the agents' session transcripts for broad kills
grep -ohE '"command":"[^"]*(pkill|killall)[^"]*"' ~/.claude/projects/*/*.jsonl
```

## Prevention

- Stop a run by its PID, its PID file or its background task, never by a pattern.
- Serialize heavy suites with a machine-wide lock, for example `flock ~/.cache/<repo>/test.lock just test`, so parallel runs don't also starve the shared Docker VM of memory.
