Bug Hunt Prompt
Use this prompt after implementing features or making significant changes to proactively find bugs.
Prompt
You are conducting a thorough bug hunt on recent code changes. Your goal is to find bugs before they reach production.
Review the following changes: [paste git diff or describe changes]
Review methodology:
- Logic Errors:
- Check conditional logic (off-by-one, incorrect operators, wrong branch taken)
- Verify loop termination conditions
- Check for unhandled edge cases
- Look for incorrect default values
- Data Flow Issues:
- Trace data through the system
- Check for data type mismatches or coercion issues
- Verify nullability assumptions
- Check for mutations where immutability is expected
- Error Handling:
- Are all error paths handled?
- Do error handlers actually handle the error (or just log and continue)?
- Can exceptions escape unhandled?
- Are errors surfaced to users appropriately?
- Race Conditions & Concurrency:
- Check for shared mutable state
- Verify thread-safety assumptions
- Look for time-of-check-time-of-use bugs
- Check for missing locks or synchronization
- Resource Management:
- Are files/connections/handles properly closed?
- Check for memory leaks
- Verify cleanup in error paths (not just happy path)
- Security Vulnerabilities:
- SQL injection, XSS, command injection
- Missing authentication/authorization checks
- Insecure defaults
- Sensitive data leakage (logs, error messages, responses)
- Boundary Conditions:
- Empty collections
- Null/undefined values
- Maximum values (integer overflow, buffer overflow)
- Minimum values (underflow, negative indices)
- Integration Issues:
- API contract violations
- Incorrect assumptions about external services
- Missing timeout/retry logic
- Deserialization errors
- Performance Problems:
- N+1 queries
- Unnecessary loops or operations
- Missing database indices
- Large object allocations in hot paths
- Invariant Violations:
- Check against INVARIANTS.md
- Does this code maintain all system invariants?
- Are there new code paths that bypass existing checks?
- Cross-Boundary Contract Bugs:
- Trace data across component boundaries (producer → consumer)
- Do all layers agree on the exact fields, types, and semantics of shared data objects?
- Does serialization → deserialization (or save → restore) preserve all fields and types?
- Are there type mismatches at boundaries (e.g.,
Decimalleaking into JSON,datetimenot handled by serializer)? - After adding a field to a data model, does every consumer (persistence, API, filters, serializers, tests) know about it?
- If data comes from multiple sources, are units and semantics compatible when combined?
- State Machine & Partial Failure:
- If an operation fails midway, is the system state rolled back or left partially modified?
- Can a user reach a state (via error or unusual sequence) that no code path was designed to handle?
- After an error, are filters/settings preserved, reset, or left in an invalid state?
- For multi-step operations, is new state built in a temporary variable and swapped atomically on success?
- Regression Pattern Search:
- For each bug found, search the entire codebase for the same pattern
- Common patterns that repeat across files:
vars(obj)instead ofobj.to_dict(), hardcoded format strings, silentexcept: pass, inconsistentddofin statistics, sentinel value checks (== 0.0instead of explicit flag) - If you fixed a bug in one file, assume it exists in others generated during different LLM sessions
- Degenerate Input Scenarios:
- Empty collection after filtering → division by zero in averages/ratios?
- Single element →
std(ddof=1)produces NaN, ratios divide by zero? - All identical values → zero variance, degenerate statistics?
- Extremely large values → does capping/sanitization silently corrupt legitimate data?
- Zero-quantity items → infinite loops in matching algorithms?
Output format:
For each potential bug found:
- Location: [file:line or function name]
- Type: [category from above]
- Issue: [description of the problem]
- Impact: [High/Medium/Low]
- Suggested fix: [how to fix it]
If no bugs found, explicitly state: “No bugs detected in this review” and list what was checked.
Remember: It’s better to flag a false positive than miss a real bug.