TaskStop reports 'No task found' but background process still running
Bug Description
When using TaskStop to stop a background task, it sometimes returns "No task found with ID: <id>" even though the underlying process (launched via run_in_background: true on Bash tool) is still running and holding resources (e.g., TCP ports).
Steps to Reproduce
- Launch a long-running background process:
```
JLinkGDBServerCLExe -device AP510NFA-CBR -if SWD -speed auto -nohalt
run_in_background: true
with — returns task ID e.g. brbcfe181`
- The task eventually completes/fails and a
<task-notification>is received with statusfailedorcompleted
- Later, attempt
TaskStopwith the same task ID:
```
TaskStop(task_id="brbcfe181")
"No task found with ID: brbcfe181"`
Returns:
- However,
pgrep -fa JLinkGDBServershows the process is still running and holding port 19021
Expected Behavior
Either:
TaskStopshould be able to stop the process even after the task notification was received, OR- The process should be fully terminated when the task notification fires (no zombie/orphan processes)
Actual Behavior
The task is removed from the task registry after the notification fires, but the underlying OS process survives. This leaves orphaned processes holding resources (TCP ports, file handles), causing port conflicts when launching replacements.
Workaround
Currently using kill <pid> directly, but this defeats the purpose of the task management system and is error-prone.
Environment
- Claude Code CLI on Linux (Ubuntu 24.04)
- Model: Claude Opus 4.6
- Processes affected:
JLinkGDBServerCLExe,JLinkRTTClient(long-running daemon-style processes)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗