Dispatch Parallel Agents
Overview
When you encounter multiple unrelated failures (different test files, different subsystems, different errors), investigating them sequentially wastes time. Each investigation is independent and can be conducted in parallel.
Core Principle: Assign one agent to each independent problem domain. Let them work simultaneously.
When to Use
dot
digraph when_to_use {
"Multiple failures?" [shape=diamond];
"Are they independent?" [shape=diamond];
"Single agent investigates all" [shape=box];
"One agent per problem domain" [shape=box];
"Can they work in parallel?" [shape=diamond];
"Sequential agents" [shape=box];
"Parallel dispatch" [shape=box];
"Multiple failures?" -> "Are they independent?" [label="yes"];
"Are they independent?" -> "Single agent investigates all" [label="no - related"];
"Are they independent?" -> "Can they work in parallel?" [label="yes"];
"Can they work in parallel?" -> "Parallel dispatch" [label="yes"];
"Can they work in parallel?" -> "Sequential agents" [label="no - shared state"];
}
When to use:
- 3 or more test files failing due to different root causes
- Multiple subsystems broken independently
- Each problem can be understood without context from other problems
- No shared state between investigations
Do NOT use when:
- Failures are related (fixing one may fix others)
- Full system state understanding is required
- Agents will interfere with each other
Patterns
1. Identify Independent Domains
Group failures by broken functionality:
- File A tests: Tool approval flow
- File B tests: Batch completion behavior
- File C tests: Abort functionality
Each domain is independent - fixing tool approval won't affect abort tests.
2. Create Targeted Agent Tasks
Each agent gets:
- Specific Scope: One test file or subsystem
- Clear Goal: Pass these tests
- Constraints: Do not change other code
- Expected Output: A summary of what you found and fixed
3. Parallel Dispatch
typescript
// In Claude Code / AI environment
Task("Fix agent-tool-abort.test.ts failures")
Task("Fix batch-completion-behavior.test.ts failures")
Task("Fix tool-approval-race-conditions.test.ts failures")
// All three run concurrently
4. Review and Integrate
When agents return:
- Read each summary
- Verify fixes do not conflict
- Run the full test suite
- Integrate all changes
Agent Prompt Structure
Good agent prompts are:
- Focused - One clear problem domain
- Self-Contained - All context needed to understand the problem
- Specific Output - What should the agent return?
markdown
Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
1. "should abort tool with partial output capture" - expects 'interrupted at' in message
2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
3. "should properly track pendingToolCount" - expects 3 results but gets 0
These are timing/race condition issues. Your task:
1. Read the test file and understand what each test verifies
2. Identify root cause - timing issues or actual bugs?
3. Fix by:
- Replacing arbitrary timeouts with event-based waiting
- Fixing bugs in abort implementation if found
- Adjusting test expectations if testing changed behavior
Do NOT just increase timeouts - find the real issue.
Return: Summary of what you found and what you fixed.
Common Mistakes
❌ Too Broad: "Fix all tests" - Agent gets lost
✅ Specific: "Fix agent-tool-abort.test.ts" - Focused scope
❌ No Context: "Fix race conditions" - Agent doesn't know where
✅ Context: Paste error messages and test names
❌ No Constraints: Agent might refactor everything
✅ Constraints: "Do not change production code" or "Only fix tests"
❌ Vague Output: "Fix it" - You don't know what changed
✅ Specific: "Return summary of root cause and changes made"
When Not to Use
Related Failures: Fixing one may fix others - Investigate together first
Full Context Required: Understanding requires seeing the entire system
Exploratory Debugging: You don't yet know what's broken
Shared State: Agents will interfere (editing same files, using same resources)
Real-World Session Example
Scenario: 6 test failures across 3 files after major refactoring
Failures:
- agent-tool-abort.test.ts: 3 failures (timing issues)
- batch-completion-behavior.test.ts: 2 failures (tools not executing)
- tool-approval-race-conditions.test.ts: 1 failure (execution count = 0)
Decision: Independent domains - abort logic is separate from batch completion, which is separate from race conditions
Dispatch:
Agent 1 → Fix agent-tool-abort.test.ts
Agent 2 → Fix batch-completion-behavior.test.ts
Agent 3 → Fix tool-approval-race-conditions.test.ts
Results:
- Agent 1: Replaced timeouts with event-based waiting
- Agent 2: Fixed event structure bug (threadId in wrong place)
- Agent 3: Added waiting for async tool execution completion
Integration: All fixes are independent, no conflicts, full suite green
Time Saved: Solved 3 problems in parallel vs sequentially
Key Benefits
- Parallelization - Multiple investigations happen simultaneously
- Focus - Each agent has a narrow scope with less context to track
- Independence - Agents don't interfere with each other
- Speed - Solve 3 problems in the time of 1
Validation
After agents return:
- Review Each Summary - Understand what changed
- Check for Conflicts - Did agents edit the same code?
- Run Full Suite - Verify all fixes work together
- Spot Check - Agents can make systematic errors
Real-World Impact
From debugging session (2025-10-03):
- 6 failures across 3 files
- 3 agents dispatched in parallel
- All investigations completed simultaneously
- All fixes successfully integrated
- Zero conflicts between agent changes