Bug Hunter
Mission Profile
You are a forward reconnaissance unit dropped into unfamiliar terrain. Your job
is not to respond to explosions — that's EOD (systematic-debugging). Your job is
not to interrogate a captured prisoner — that's intel (hostile-review). Your job
is to map the minefield before the infantry walks through it.
Operational doctrine: Systematic sweep → threat model → targeted hunt →
proof of kill → debrief.
You report what you find. You verify it's real. You don't guess.
Phase 0: Mission Briefing
Before entering the codebase, establish scope and rules of engagement:
Define the AO (Area of Operations)
- Full codebase, specific module, recent changes only, or pre-deploy delta?
- What's the tech stack? (Language, framework, DB, infra)
- What's the deployment target? (serverless, containers, bare metal, edge)
Identify high-value targets
- What would hurt most if it broke? (auth, payments, data integrity, uptime)
- What changed recently? (recent commits are higher-probability minefields)
- What has no tests? (undefended territory)
Set severity threshold
- Hunt everything, or only P0/P1 potential?
- Include code quality / maintainability debt, or strictly runtime defects?
If the user doesn't specify, default to: full codebase, all severities, runtime
defects + data integrity issues prioritized.
Phase 1: Terrain Mapping (Reconnaissance)
Systematically map the codebase topology before hunting. You can't find what's
wrong if you don't know what's there.
1.1 Structure Scan
1. Map directory structure and module boundaries
2. Identify entry points (HTTP routes, CLI commands, event handlers, cron jobs)
3. Identify exit points (DB writes, API calls, file I/O, message publishing)
4. Map dependency graph (internal module deps + external packages)
5. Locate configuration surfaces (env vars, config files, feature flags)
1.2 Data Flow Mapping
1. Trace primary data paths: input → processing → storage → output
2. Identify trust boundaries (user input, external API responses, DB reads)
3. Map state mutation points (where does shared state get modified?)
4. Identify serialization/deserialization boundaries (JSON parse, DB ORM, API contracts)
5. Note any implicit contracts between modules (undocumented assumptions)
1.3 Test Coverage Recon
1. Check test coverage metrics if available
2. Identify modules with zero or minimal test coverage
3. Note what KIND of tests exist (unit only? integration? e2e?)
4. Flag any tests that are skipped, flaky, or test implementation not behavior
5. Mark untested code paths as HIGH PRIORITY hunt zones
Output: A mental (or written) map of the codebase with annotated risk zones.
Untested code near trust boundaries = highest priority.
Phase 2: Threat Modeling
For each identified zone, systematically enumerate what CAN go wrong. This is
not guessing — it's applying known failure categories to the specific code.
The Failure Taxonomy
Apply each category to every relevant component. Not all apply everywhere — skip
what doesn't fit, but don't skip categories out of laziness.
2.1 Input & Validation Failures
- Unvalidated user input reaching business logic or DB queries
- Type coercion surprises (string "0" vs number 0, empty string vs null)
- Missing bounds checks (negative numbers, zero, MAX_INT, empty arrays)
- Encoding mismatches (UTF-8 assumptions, URL encoding, HTML entities)
- Malformed payloads accepted silently (partial JSON, truncated data)
2.2 State & Concurrency Failures
- Race conditions on shared mutable state
- Time-of-check-to-time-of-use (TOCTOU) gaps
- Missing atomicity (multi-step operations that can partially complete)
- Stale reads (cache invalidation failures, read-your-writes violations)
- Session/request state bleed (shared objects across requests)
2.3 Error Handling Failures
- Silent swallowing (catch-and-ignore, empty catch blocks)
- Error type confusion (catching broad Exception, masking specific errors)
- Missing error propagation (error logged but caller not informed)
- Inconsistent error responses (different error formats from same API)
- Resource leaks on error paths (connections, file handles, locks not released)
2.4 Boundary & Integration Failures
- External service timeout/failure not handled (no circuit breaker)
- API contract assumptions not validated (trusting external response shape)
- DB schema drift (code assumes columns/types that may change)
- Version skew between services (deploy order dependencies)
- Missing idempotency on retry-able operations
2.5 Data Integrity Failures
- Silent data loss (overwrite without check, truncation without warning)
- Partial writes visible to readers (no transaction boundaries)
- Orphaned records (parent deleted, children remain)
- Precision loss (float arithmetic on currency, integer overflow)
- Timezone confusion (mixing UTC and local, DST edge cases)
2.6 Resource & Capacity Failures
- Unbounded growth (collections that grow without limit, log files, queues)
- N+1 query patterns (loop-driven DB queries)
- Missing pagination (loading all records into memory)
- Connection pool exhaustion under load
- Memory leaks (event listeners not removed, closures capturing scope)
2.7 Security Failures
- Auth checks missing or in wrong order (check after expensive work)
- Privilege escalation paths (horizontal: user A sees user B's data)
- Secrets in code, logs, or error messages
- Injection vectors (SQL, command, template, path traversal)
- Missing rate limiting on sensitive endpoints
2.8 Temporal & Ordering Failures
- Assumption that operations complete in a specific order
- Missing retry/backoff on transient failures
- Cron job overlap (next execution starts before previous finishes)
- Clock skew sensitivity (distributed systems relying on wall clock)
- Daylight saving time transitions breaking scheduled operations
Phase 3: The Hunt
Now execute targeted searches based on Phase 2 threat model. For each risk zone
identified, apply the appropriate hunt patterns.
Hunt Methodology
For each high-risk zone from Phase 1+2:
1. SELECT applicable failure categories from Phase 2
2. SEARCH for concrete instances in the code
3. TRACE the data/control flow to confirm exploitability
4. CLASSIFY: confirmed bug, latent risk, or false positive
5. MOVE to next zone
Hunt Patterns (Quick-Reference Kill Chain)
These are the specific code patterns to grep/search for. Use as a checklist
during the hunt.
Silent killers (often zero symptoms until catastrophe):
catch blocks that don't re-throw or return error state
.then() chains without .catch() (unhandled promise rejections)
- Writes without transactions where atomicity matters
DELETE operations without cascading or cleanup
- Floating point used for money or precision-critical values
Ticking time bombs (work now, explode under load or at scale):
- Array/list operations inside database query loops
- No pagination on queries that return growing datasets
- In-memory caches without eviction policy or TTL
- String concatenation in hot paths (vs. builder/buffer)
- Synchronous I/O on async code paths
Trust violations (assumes the world is kind):
- External API response used without schema validation
- User-supplied values in file paths, SQL, shell commands, or template strings
- JWT/token validation that only checks signature, not claims/expiry
- CORS/CSP policies that are overly permissive or missing
- Deserialization of untrusted data without type checking
State corruption (the Heisenbug factory):
- Mutable default arguments (Python:
def f(x=[]))
- Shared object references across request contexts
- Global/module-level state modified at runtime
- Event listeners registered but never removed
- Async operations modifying shared state without locks
The "works on my machine" special:
- Hardcoded paths, ports, or hostnames
- Locale-dependent string operations (date parsing, number formatting)
- OS-specific behavior (path separators, line endings, case sensitivity)
- Timezone assumptions (server vs. user vs. database)
- Missing environment variable fallbacks or validation at startup
Phase 4: Verification (Proof of Kill)
A suspected bug is not a confirmed bug until you can demonstrate it. Do NOT
report unverified suspicions as findings.
Verification Methods (in order of preference)
Write a failing test — The gold standard. If you can write a test that
fails because of the bug, it's confirmed and you've started the fix.
Construct a trigger scenario — Describe the exact sequence of
inputs/events/timing that would trigger the bug. Be specific enough that
someone could reproduce it.
Static proof — For logic errors, show the code path that leads to the
invalid state. Trace it step by step with concrete values.
Analogous evidence — If the exact trigger is hard to construct (race
conditions, distributed timing), cite the pattern and demonstrate it's
present in the code with specific line references.
Verification Checklist
For each finding:
Kill threshold: If you can't satisfy at least items 1 and 2, downgrade from
"confirmed bug" to "risk / needs investigation".
Phase 5: Debrief (Report)
Report Format
# 🎯 Bug Hunt Report: [Target / Scope]
**AO:** [what was scanned]
**Hunt duration:** [time/effort]
**Terrain:** [tech stack summary]
## Executive Summary
[2-3 sentences: how many findings, worst severity, overall health assessment]
## Findings
### [SEVERITY] [BH-001]: Title
**Location:** `path/to/file.ext:line`
**Category:** [from Phase 2 taxonomy, e.g., "State & Concurrency > Race Condition"]
**Status:** Confirmed Bug | Latent Risk | Needs Investigation
**The problem:**
[What's wrong, in one paragraph. Be precise.]
**Trigger scenario:**
[How this actually breaks. Specific inputs, timing, conditions.]
**Evidence:**
[Code snippet showing the vulnerable path]
**Impact:**
[What happens when this fires. Data loss? Auth bypass? Silent corruption?]
**Recommended fix:**
[Concrete fix — code preferred, description acceptable for architectural issues]
---
[repeat for each finding]
## Risk Map
[Optional: visual or tabular summary of where risk concentrates]
| Zone | Findings | Worst Severity | Coverage |
|------|----------|---------------|----------|
| auth/ | 3 | CRITICAL | 12% |
| api/handlers/ | 5 | HIGH | 45% |
| utils/ | 1 | LOW | 80% |
## Hunt Coverage
[What was scanned, what was skipped, and why. Intellectual honesty about blind spots.]
Severity Definitions
| Level |
Meaning |
Example |
| CRITICAL |
Data loss, security breach, or total service failure possible |
Auth bypass, silent data corruption |
| HIGH |
Significant functionality broken under realistic conditions |
Race condition on concurrent writes, unbounded query |
| MEDIUM |
Incorrect behavior in edge cases, degraded performance |
Missing null check on optional field, N+1 query |
| LOW |
Code quality issue that increases future bug probability |
Implicit type coercion, missing error context |
| INFO |
Not a bug, but worth knowing |
Undocumented behavior, unusual pattern |
Operational Rules
Sweep systematically. Don't random-walk through the code hoping to spot
something. Follow the phases. Map first, model second, hunt third.
Verify before reporting. Unverified suspicions waste everyone's time. If
you can't verify it, say so explicitly and classify as "Needs Investigation".
Don't fix during the hunt. Your job is reconnaissance, not repair. Mixing
the two means you'll stop hunting once you start fixing. Report everything
first, fix later (or hand off to systematic-debugging for confirmed issues).
Track your coverage. Know what you've scanned and what you haven't. A
hunt that covers 30% of the codebase should say so, not pretend to be
comprehensive.
Prioritize by blast radius. Hunt high-value targets first: auth,
payments, data writes, external integrations. The logging utility can wait.
Fresh eyes principle. Don't assume anything works correctly because it
hasn't failed yet. Absence of errors is not evidence of correctness —
especially in code with no tests.
Integration with Other Skills
- hostile-review: For deep-dive on specific suspicious code found during hunt
- systematic-debugging: Hand off confirmed bugs for proper root-cause fix cycle
- staff-review: Escalate architectural concerns found during terrain mapping
1---2name: bug-hunter3description: Proactive bug-hunting methodology — autonomous codebase reconnaissance to find latent bugs, hidden failure modes, and ticking time bombs BEFORE they detonate in production. Use this skill whenever the user asks to "find bugs", "hunt for issues", "audit this codebase", "what could go wrong", "find what's broken", "stress-test this project", "find landmines", "what will bite me later", or any variation of proactive defect discovery. Also trigger when the user says "scan for problems", "pre-flight check", "what am I missing across the codebase", "find the weak spots", or asks for a proactive quality sweep before a release, merge, or deployment. This is NOT for debugging known errors (use systematic-debugging) or reviewing specific code you're handed (use hostile-review). This is for when there are no known errors yet and you need to go FIND them.4---56# Bug Hunter78## Mission Profile910You are a forward reconnaissance unit dropped into unfamiliar terrain. Your job11is not to respond to explosions — that's EOD (systematic-debugging). Your job is12not to interrogate a captured prisoner — that's intel (hostile-review). Your job13is to map the minefield before the infantry walks through it.1415**Operational doctrine:** Systematic sweep → threat model → targeted hunt →16proof of kill → debrief.1718You report what you find. You verify it's real. You don't guess.1920---2122## Phase 0: Mission Briefing2324Before entering the codebase, establish scope and rules of engagement:25261. **Define the AO (Area of Operations)**27 - Full codebase, specific module, recent changes only, or pre-deploy delta?28 - What's the tech stack? (Language, framework, DB, infra)29 - What's the deployment target? (serverless, containers, bare metal, edge)30312. **Identify high-value targets**32 - What would hurt most if it broke? (auth, payments, data integrity, uptime)33 - What changed recently? (recent commits are higher-probability minefields)34 - What has no tests? (undefended territory)35363. **Set severity threshold**37 - Hunt everything, or only P0/P1 potential?38 - Include code quality / maintainability debt, or strictly runtime defects?3940If the user doesn't specify, default to: full codebase, all severities, runtime41defects + data integrity issues prioritized.4243---4445## Phase 1: Terrain Mapping (Reconnaissance)4647Systematically map the codebase topology before hunting. You can't find what's48wrong if you don't know what's there.4950### 1.1 Structure Scan5152```531. Map directory structure and module boundaries542. Identify entry points (HTTP routes, CLI commands, event handlers, cron jobs)553. Identify exit points (DB writes, API calls, file I/O, message publishing)564. Map dependency graph (internal module deps + external packages)575. Locate configuration surfaces (env vars, config files, feature flags)58```5960### 1.2 Data Flow Mapping6162```631. Trace primary data paths: input → processing → storage → output642. Identify trust boundaries (user input, external API responses, DB reads)653. Map state mutation points (where does shared state get modified?)664. Identify serialization/deserialization boundaries (JSON parse, DB ORM, API contracts)675. Note any implicit contracts between modules (undocumented assumptions)68```6970### 1.3 Test Coverage Recon7172```731. Check test coverage metrics if available742. Identify modules with zero or minimal test coverage753. Note what KIND of tests exist (unit only? integration? e2e?)764. Flag any tests that are skipped, flaky, or test implementation not behavior775. Mark untested code paths as HIGH PRIORITY hunt zones78```7980**Output:** A mental (or written) map of the codebase with annotated risk zones.81Untested code near trust boundaries = highest priority.8283---8485## Phase 2: Threat Modeling8687For each identified zone, systematically enumerate what CAN go wrong. This is88not guessing — it's applying known failure categories to the specific code.8990### The Failure Taxonomy9192Apply each category to every relevant component. Not all apply everywhere — skip93what doesn't fit, but don't skip categories out of laziness.9495#### 2.1 Input & Validation Failures96- Unvalidated user input reaching business logic or DB queries97- Type coercion surprises (string "0" vs number 0, empty string vs null)98- Missing bounds checks (negative numbers, zero, MAX_INT, empty arrays)99- Encoding mismatches (UTF-8 assumptions, URL encoding, HTML entities)100- Malformed payloads accepted silently (partial JSON, truncated data)101102#### 2.2 State & Concurrency Failures103- Race conditions on shared mutable state104- Time-of-check-to-time-of-use (TOCTOU) gaps105- Missing atomicity (multi-step operations that can partially complete)106- Stale reads (cache invalidation failures, read-your-writes violations)107- Session/request state bleed (shared objects across requests)108109#### 2.3 Error Handling Failures110- Silent swallowing (catch-and-ignore, empty catch blocks)111- Error type confusion (catching broad Exception, masking specific errors)112- Missing error propagation (error logged but caller not informed)113- Inconsistent error responses (different error formats from same API)114- Resource leaks on error paths (connections, file handles, locks not released)115116#### 2.4 Boundary & Integration Failures117- External service timeout/failure not handled (no circuit breaker)118- API contract assumptions not validated (trusting external response shape)119- DB schema drift (code assumes columns/types that may change)120- Version skew between services (deploy order dependencies)121- Missing idempotency on retry-able operations122123#### 2.5 Data Integrity Failures124- Silent data loss (overwrite without check, truncation without warning)125- Partial writes visible to readers (no transaction boundaries)126- Orphaned records (parent deleted, children remain)127- Precision loss (float arithmetic on currency, integer overflow)128- Timezone confusion (mixing UTC and local, DST edge cases)129130#### 2.6 Resource & Capacity Failures131- Unbounded growth (collections that grow without limit, log files, queues)132- N+1 query patterns (loop-driven DB queries)133- Missing pagination (loading all records into memory)134- Connection pool exhaustion under load135- Memory leaks (event listeners not removed, closures capturing scope)136137#### 2.7 Security Failures138- Auth checks missing or in wrong order (check after expensive work)139- Privilege escalation paths (horizontal: user A sees user B's data)140- Secrets in code, logs, or error messages141- Injection vectors (SQL, command, template, path traversal)142- Missing rate limiting on sensitive endpoints143144#### 2.8 Temporal & Ordering Failures145- Assumption that operations complete in a specific order146- Missing retry/backoff on transient failures147- Cron job overlap (next execution starts before previous finishes)148- Clock skew sensitivity (distributed systems relying on wall clock)149- Daylight saving time transitions breaking scheduled operations150151---152153## Phase 3: The Hunt154155Now execute targeted searches based on Phase 2 threat model. For each risk zone156identified, apply the appropriate hunt patterns.157158### Hunt Methodology159160```161For each high-risk zone from Phase 1+2:162 1. SELECT applicable failure categories from Phase 2163 2. SEARCH for concrete instances in the code164 3. TRACE the data/control flow to confirm exploitability165 4. CLASSIFY: confirmed bug, latent risk, or false positive166 5. MOVE to next zone167```168169### Hunt Patterns (Quick-Reference Kill Chain)170171These are the specific code patterns to grep/search for. Use as a checklist172during the hunt.173174**Silent killers (often zero symptoms until catastrophe):**175- `catch` blocks that don't re-throw or return error state176- `.then()` chains without `.catch()` (unhandled promise rejections)177- Writes without transactions where atomicity matters178- `DELETE` operations without cascading or cleanup179- Floating point used for money or precision-critical values180181**Ticking time bombs (work now, explode under load or at scale):**182- Array/list operations inside database query loops183- No pagination on queries that return growing datasets184- In-memory caches without eviction policy or TTL185- String concatenation in hot paths (vs. builder/buffer)186- Synchronous I/O on async code paths187188**Trust violations (assumes the world is kind):**189- External API response used without schema validation190- User-supplied values in file paths, SQL, shell commands, or template strings191- JWT/token validation that only checks signature, not claims/expiry192- CORS/CSP policies that are overly permissive or missing193- Deserialization of untrusted data without type checking194195**State corruption (the Heisenbug factory):**196- Mutable default arguments (Python: `def f(x=[])`)197- Shared object references across request contexts198- Global/module-level state modified at runtime199- Event listeners registered but never removed200- Async operations modifying shared state without locks201202**The "works on my machine" special:**203- Hardcoded paths, ports, or hostnames204- Locale-dependent string operations (date parsing, number formatting)205- OS-specific behavior (path separators, line endings, case sensitivity)206- Timezone assumptions (server vs. user vs. database)207- Missing environment variable fallbacks or validation at startup208209---210211## Phase 4: Verification (Proof of Kill)212213A suspected bug is not a confirmed bug until you can demonstrate it. Do NOT214report unverified suspicions as findings.215216### Verification Methods (in order of preference)2172181. **Write a failing test** — The gold standard. If you can write a test that219 fails because of the bug, it's confirmed and you've started the fix.2202212. **Construct a trigger scenario** — Describe the exact sequence of222 inputs/events/timing that would trigger the bug. Be specific enough that223 someone could reproduce it.2242253. **Static proof** — For logic errors, show the code path that leads to the226 invalid state. Trace it step by step with concrete values.2272284. **Analogous evidence** — If the exact trigger is hard to construct (race229 conditions, distributed timing), cite the pattern and demonstrate it's230 present in the code with specific line references.231232### Verification Checklist233234For each finding:235- [ ] Can I show the EXACT code path that fails?236- [ ] Can I describe SPECIFIC inputs or conditions that trigger it?237- [ ] Is this a real production risk, or only theoretical under absurd conditions?238- [ ] Have I ruled out that existing code elsewhere doesn't already handle this?239240**Kill threshold:** If you can't satisfy at least items 1 and 2, downgrade from241"confirmed bug" to "risk / needs investigation".242243---244245## Phase 5: Debrief (Report)246247### Report Format248249```markdown250# 🎯 Bug Hunt Report: [Target / Scope]251252**AO:** [what was scanned]253**Hunt duration:** [time/effort]254**Terrain:** [tech stack summary]255256## Executive Summary257[2-3 sentences: how many findings, worst severity, overall health assessment]258259## Findings260261### [SEVERITY] [BH-001]: Title262**Location:** `path/to/file.ext:line`263**Category:** [from Phase 2 taxonomy, e.g., "State & Concurrency > Race Condition"]264**Status:** Confirmed Bug | Latent Risk | Needs Investigation265266**The problem:**267[What's wrong, in one paragraph. Be precise.]268269**Trigger scenario:**270[How this actually breaks. Specific inputs, timing, conditions.]271272**Evidence:**273[Code snippet showing the vulnerable path]274275**Impact:**276[What happens when this fires. Data loss? Auth bypass? Silent corruption?]277278**Recommended fix:**279[Concrete fix — code preferred, description acceptable for architectural issues]280281---282[repeat for each finding]283284## Risk Map285[Optional: visual or tabular summary of where risk concentrates]286287| Zone | Findings | Worst Severity | Coverage |288|------|----------|---------------|----------|289| auth/ | 3 | CRITICAL | 12% |290| api/handlers/ | 5 | HIGH | 45% |291| utils/ | 1 | LOW | 80% |292293## Hunt Coverage294[What was scanned, what was skipped, and why. Intellectual honesty about blind spots.]295```296297### Severity Definitions298299| Level | Meaning | Example |300|-------|---------|---------|301| **CRITICAL** | Data loss, security breach, or total service failure possible | Auth bypass, silent data corruption |302| **HIGH** | Significant functionality broken under realistic conditions | Race condition on concurrent writes, unbounded query |303| **MEDIUM** | Incorrect behavior in edge cases, degraded performance | Missing null check on optional field, N+1 query |304| **LOW** | Code quality issue that increases future bug probability | Implicit type coercion, missing error context |305| **INFO** | Not a bug, but worth knowing | Undocumented behavior, unusual pattern |306307---308309## Operational Rules3103111. **Sweep systematically.** Don't random-walk through the code hoping to spot312 something. Follow the phases. Map first, model second, hunt third.3133142. **Verify before reporting.** Unverified suspicions waste everyone's time. If315 you can't verify it, say so explicitly and classify as "Needs Investigation".3163173. **Don't fix during the hunt.** Your job is reconnaissance, not repair. Mixing318 the two means you'll stop hunting once you start fixing. Report everything319 first, fix later (or hand off to systematic-debugging for confirmed issues).3203214. **Track your coverage.** Know what you've scanned and what you haven't. A322 hunt that covers 30% of the codebase should say so, not pretend to be323 comprehensive.3243255. **Prioritize by blast radius.** Hunt high-value targets first: auth,326 payments, data writes, external integrations. The logging utility can wait.3273286. **Fresh eyes principle.** Don't assume anything works correctly because it329 hasn't failed yet. Absence of errors is not evidence of correctness —330 especially in code with no tests.331332---333334## Integration with Other Skills335336- **hostile-review**: For deep-dive on specific suspicious code found during hunt337- **systematic-debugging**: Hand off confirmed bugs for proper root-cause fix cycle338- **staff-review**: Escalate architectural concerns found during terrain mapping