Skip to content
Back to skills

Collection

ASecurity

Prevents infinite polling loops when monitoring background shells. Triggers when running tests, builds, or long processes. Enforces timeout limits, max poll attempts, and foreground preference. Integrates with KillShell for stuck process recovery.

  • 24 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 8, 2026
testingtypescriptshellbashdebuggingdatabase

Works with

  • mcp

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-c7194074/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-c7194074)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: stuck-process-detection
description: Prevents infinite polling loops when monitoring background shells. Triggers when running tests, builds, or long processes. Enforces timeout limits, max poll attempts, and foreground preference. Integrates with KillShell for stuck process recovery.
---

# Stuck Process Detection & Recovery

## Purpose

Prevent the agent from entering infinite polling loops when waiting for background shell output that never arrives. This is a common failure mode when:
- A test suite hangs
- A build process is stuck
- A server fails to start
- A command exits with no output

## When This Skill Activates

### Trigger Conditions (ANY of these)

| Condition | Example |
|-----------|---------|
| Running tests in background | `npm test`, `vitest`, `playwright test` |
| Starting long builds | `npm run build`, `tsc`, `webpack` |
| Starting dev servers | `npm run dev`, `npm start` |
| Any `run_in_background: true` bash call | Launching background processes |
| Multiple consecutive BashOutput calls | Agent polling repeatedly |

### Keywords That Trigger This Skill

- `run_in_background`
- `background`
- `BashOutput`
- `wait for`
- `check output`
- `poll`
- `monitoring`
- `long-running`
- `tests running`
- `build running`
- `server starting`

---

## The Anti-Pattern (What We're Preventing)

```
// BAD - Infinite polling loop
agent: "Let me run tests in background"
Bash(run_in_background: true): npm test
BashOutput: (No content)
BashOutput: (No content)
BashOutput: (No content)
... repeats 50+ times ...
agent: "Let me wait a bit longer"
BashOutput: (No content)
... forever ...
```

---

## The Correct Pattern

### Rule 1: Prefer Foreground with Timeout

For most operations, run in foreground with explicit timeout:

```typescript
// CORRECT - Foreground with timeout
Bash({
  command: "npm test -- --reporter=verbose",
  timeout: 120000,  // 2 minutes
  description: "Run unit tests"
})
```

### Rule 2: If Background Required, Set Max Polls

When background is truly needed (e.g., dev server):

```typescript
// Step 1: Start in background
Bash({
  command: "npm run dev",
  run_in_background: true,
  description: "Start dev server"
})

// Step 2: Poll with strict limit (MAX 5 attempts)
let attempts = 0;
const MAX_ATTEMPTS = 5;

while (attempts < MAX_ATTEMPTS) {
  const output = BashOutput({ bash_id: shellId });
  if (output.includes("ready") || output.includes("listening")) {
    // Success - proceed
    break;
  }
  if (attempts >= MAX_ATTEMPTS) {
    // STOP polling - investigate or kill
    KillShell({ shell_id: shellId });
    throw new Error("Process did not start within expected time");
  }
  attempts++;
}
```

### Rule 3: Detect Stuck After 3 Empty Outputs

If you get **3 consecutive empty BashOutput results**, STOP and:

1. **Check if process is alive**: `ps aux | grep <process>`
2. **Kill the stuck shell**: `KillShell({ shell_id: "..." })`
3. **Try foreground instead**: Re-run with timeout, not background
4. **Investigate the failure**: Don't just retry

---

## Recovery Actions

### When Stuck is Detected

```
1. STOP polling immediately
2. Kill the stuck shell with KillShell
3. Check for error indicators:
   - Port already in use?
   - Missing dependencies?
   - Syntax error in config?
4. Re-run in foreground with timeout
5. If still failing, investigate root cause
```

### KillShell Usage

```typescript
// Always provide the shell_id from your original Bash call
KillShell({ shell_id: "shell-abc123" })
```

---

## Process-Specific Timeouts

| Process Type | Recommended Approach | Max Timeout |
|--------------|---------------------|-------------|
| Unit tests (`npm test`) | Foreground | 2 minutes |
| Type check (`tsc --noEmit`) | Foreground | 1 minute |
| Build (`npm run build`) | Foreground | 3 minutes |
| E2E tests (`playwright`) | Foreground | 5 minutes |
| Dev server | Background, 5 polls max | N/A |
| Database migrations | Foreground | 1 minute |

---

## Warning Signs You're About to Loop

If you catch yourself thinking:
- "Let me wait a bit longer" -> STOP, you're looping
- "I'll check again" (3rd+ time) -> STOP, kill and investigate
- "The output will come eventually" -> STOP, it probably won't
- "No content yet, keep polling" -> STOP after 3 attempts

---

## Integration with Other Skills

### Works With

- **fail-fast-debugging**: If a process is stuck, investigate why before retrying
- **verification-before-completion**: Don't claim tests pass if they never finished
- **root-cause-tracing**: Stuck processes often indicate deeper issues

### Escalation Path

```
3 empty polls -> Kill shell, try foreground
Foreground fails -> Activate fail-fast-debugging
2 attempts fail -> Question the approach (mcp__zen__thinkdeep)
```

---

## Quick Reference

```
BACKGROUND PROCESS CHECKLIST:
[ ] Is background truly necessary? (Prefer foreground)
[ ] Set max poll limit (5 attempts max)
[ ] Have shell_id ready for KillShell
[ ] Know the success indicators to look for
[ ] Have a timeout strategy for foreground fallback

STUCK DETECTION:
- 3 consecutive empty BashOutput = STUCK
- Action: Kill, investigate, foreground retry
- NEVER poll more than 5 times
```

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.