"Deep research for bugs" – Agentic root cause analysis through hypothesis-driven debugging
TypeScript
106
37 commits
updated Sep 10, 2025
Agentic root cause analysis through hypothesis-driven debugging
dilagent automates the tedious process of reproducing, diagnosing, and fixing bugs through systematic hypothesis testing and experimentation. It combines LLM agents with structured scientific methodology to identify root causes and validate fixes.
Ideal for:
Not suitable for:
dilagent follows a structured, multi-stage approach to debugging:
First, dilagent attempts to reproduce the issue:
repro.ts)Based on successful reproduction, dilagent generates targeted hypotheses:
hypotheses.json for trackingEach hypothesis is tested in parallel:
For complex issues requiring human insight:
The process continues iteratively until the root cause is found and validated.
dilagent manager setup --working-directory ./debug-session --context-directory ./my-project
.dilagent/ directory structurecontext.md with codebase information and issue descriptiondilagent manager repro --working-directory ./debug-session --llm claude
reproduction.md with steps to reproduce the issuedilagent manager generate-hypotheses --working-directory ./debug-session --hypothesis-count 3 --llm claude
H001-config-issue/, H002-race-condition/, etc.hypothesis.md - The specific theory about the buginstructions.md - Steps to test the hypothesisdilagent manager run-hypotheses --working-directory ./debug-session --llm claude
worktree-H001-config-issue/)report.md in each hypothesis directory with findings.dilagent/H{NNN}-{slug}/hypothesis.log# Hypothesis H003: Race Condition in Connection Pool
## Status: ✅ PROVEN
## Initial Analysis
The intermittent timeout errors in production suggested a potential race condition
in the database connection pool management. The error pattern showed:
- Errors occur only under high concurrent load (>100 req/s)
- Error rate increases exponentially with load
- Database logs show connection pool exhaustion messages
- Issue started appearing after the connection pooling refactor in commit abc123
## Investigation Steps
### Step 1: Reproduce the Issue
Created load test script that successfully reproduced the issue:
```bash
# Load test that triggers the race condition
ab -n 10000 -c 50 http://localhost:3000/api/users/search
# Result: 3.2% failure rate with "connection pool timeout" errors
Identified suspicious code in src/db/pool.ts:42-58:
// PROBLEMATIC: Race condition between check and increment
if (this.activeConnections < this.maxConnections) {
// Gap here - another request could increment activeConnections
this.activeConnections++;
return this.createConnection();
}
The race condition occurs when multiple requests simultaneously:
activeConnections < maxConnections (both see same value)activeConnectionsmaxConnectionsImplemented atomic operation using mutex lock:
// FIXED: Atomic check-and-increment
async acquireConnection(): Promise<Connection> {
return this.mutex.acquire(async () => {
if (this.activeConnections >= this.maxConnections) {
throw new PoolExhaustedError();
}
this.activeConnections++;
return this.createConnection();
});
}
src/db/pool.ts - Fixed race conditiontests/db/pool.test.ts - Added concurrency testspackage.json - Added async-mutex dependency</details>
### Stage 4: Summary
```bash
dilagent manager summary --working-directory ./debug-session
# Install
npm install -g dilagent
# Run the complete workflow in one command
dilagent manager all \
--context-directory ./my-project \
--working-directory ./debug-session \
--hypothesis-count 3 \
--llm claude
# Key options:
# --llm claude|codex - Choose AI model (Claude recommended)
# --working-directory - Where dilagent stores its files
# --context-directory - The codebase to debug
# --hypothesis-count - Number of hypotheses to generate (default: 3)
# --flaky - Use this flag for intermittent/flaky issues
# --repl - Start interactive mode for complex debugging
Issue: Reproduction fails
Issue: All hypotheses are inconclusive
--hypothesis-count to generate more hypothesescontext.md about recent changes--repl mode for manual explorationIssue: Worktree creation fails
Environment Variables:
DILAGENT_CLI_PATH - Automatically set to CLI location for MCP proxyLLM Tools:
claude or codex command in your PATHWorking Directory Best Practices:
./debug-sessions/issue-123/)claude or codex command available in PATH)36 commits
1 commits
TypeScript
95.5%
Mermaid
3.2%
"Deep research for bugs" – Agentic root cause analysis through hypothesis-driven debugging
TypeScript
106
37 commits
updated Sep 10, 2025
Agentic root cause analysis through hypothesis-driven debugging
dilagent automates the tedious process of reproducing, diagnosing, and fixing bugs through systematic hypothesis testing and experimentation. It combines LLM agents with structured scientific methodology to identify root causes and validate fixes.
Ideal for:
Not suitable for:
dilagent follows a structured, multi-stage approach to debugging:
First, dilagent attempts to reproduce the issue:
repro.ts)Based on successful reproduction, dilagent generates targeted hypotheses:
hypotheses.json for trackingEach hypothesis is tested in parallel:
For complex issues requiring human insight:
The process continues iteratively until the root cause is found and validated.
dilagent manager setup --working-directory ./debug-session --context-directory ./my-project
.dilagent/ directory structurecontext.md with codebase information and issue descriptiondilagent manager repro --working-directory ./debug-session --llm claude
reproduction.md with steps to reproduce the issuedilagent manager generate-hypotheses --working-directory ./debug-session --hypothesis-count 3 --llm claude
H001-config-issue/, H002-race-condition/, etc.hypothesis.md - The specific theory about the buginstructions.md - Steps to test the hypothesisdilagent manager run-hypotheses --working-directory ./debug-session --llm claude
worktree-H001-config-issue/)report.md in each hypothesis directory with findings.dilagent/H{NNN}-{slug}/hypothesis.log# Hypothesis H003: Race Condition in Connection Pool
## Status: ✅ PROVEN
## Initial Analysis
The intermittent timeout errors in production suggested a potential race condition
in the database connection pool management. The error pattern showed:
- Errors occur only under high concurrent load (>100 req/s)
- Error rate increases exponentially with load
- Database logs show connection pool exhaustion messages
- Issue started appearing after the connection pooling refactor in commit abc123
## Investigation Steps
### Step 1: Reproduce the Issue
Created load test script that successfully reproduced the issue:
```bash
# Load test that triggers the race condition
ab -n 10000 -c 50 http://localhost:3000/api/users/search
# Result: 3.2% failure rate with "connection pool timeout" errors
Identified suspicious code in src/db/pool.ts:42-58:
// PROBLEMATIC: Race condition between check and increment
if (this.activeConnections < this.maxConnections) {
// Gap here - another request could increment activeConnections
this.activeConnections++;
return this.createConnection();
}
The race condition occurs when multiple requests simultaneously:
activeConnections < maxConnections (both see same value)activeConnectionsmaxConnectionsImplemented atomic operation using mutex lock:
// FIXED: Atomic check-and-increment
async acquireConnection(): Promise<Connection> {
return this.mutex.acquire(async () => {
if (this.activeConnections >= this.maxConnections) {
throw new PoolExhaustedError();
}
this.activeConnections++;
return this.createConnection();
});
}
src/db/pool.ts - Fixed race conditiontests/db/pool.test.ts - Added concurrency testspackage.json - Added async-mutex dependency</details>
### Stage 4: Summary
```bash
dilagent manager summary --working-directory ./debug-session
# Install
npm install -g dilagent
# Run the complete workflow in one command
dilagent manager all \
--context-directory ./my-project \
--working-directory ./debug-session \
--hypothesis-count 3 \
--llm claude
# Key options:
# --llm claude|codex - Choose AI model (Claude recommended)
# --working-directory - Where dilagent stores its files
# --context-directory - The codebase to debug
# --hypothesis-count - Number of hypotheses to generate (default: 3)
# --flaky - Use this flag for intermittent/flaky issues
# --repl - Start interactive mode for complex debugging
Issue: Reproduction fails
Issue: All hypotheses are inconclusive
--hypothesis-count to generate more hypothesescontext.md about recent changes--repl mode for manual explorationIssue: Worktree creation fails
Environment Variables:
DILAGENT_CLI_PATH - Automatically set to CLI location for MCP proxyLLM Tools:
claude or codex command in your PATHWorking Directory Best Practices:
./debug-sessions/issue-123/)claude or codex command available in PATH)36 commits
1 commits
TypeScript
95.5%
Mermaid
3.2%