Automated Bug Hunting
Quickly locate the root cause of a subtle bug and apply a verified fix. OpenCode reads the stack trace, traces execution paths, and proposes targeted changes.
When to use this recipe
- You have a stack trace or failing test but no clear cause.
- The bug is intermittent or involves concurrency.
- You want a fix with an explanation, not a guess.
Prerequisites
- The failing test case or a reliable reproduction step.
- OpenCode set up in your project with LSP enabled.
Steps
-
Provide the failure signal
Paste the stack trace or the failing test command into the session.
FAIL src/workers/queue.test.ts > Timeout: message processed twice under load -
Ask for root-cause analysis
This test fails intermittently under load. Trace the message flow from producer to consumer and find why a message can be processed twice.
-
Review the trace
OpenCode walks the call path and points to the exact race condition — for example, a missing mutex around a shared channel.
-
Apply the fix
Confirm the proposed change (e.g. adding a lock) and let OpenCode implement it.
-
Verify with the reproduction
Re-run the test under load to confirm the fix holds.
npm test -- --grep queue
Key prompt
Here is the stack trace: [paste]. Trace the execution path through the code and identify the root cause. Propose the smallest fix that resolves it without introducing side effects.
Common pitfalls
- Fixing symptoms: Ask OpenCode for the root cause first; a superficial patch may hide the bug elsewhere.
- Concurrency bugs: Re-run the test many times — a single pass doesn’t prove the race is gone.
- Environment-only bugs: If it can’t reproduce, share logs and timing details so OpenCode can reason about the path.
Related recipes
- refactor-codebase —
reason.bug-hunting.to-refactor - remote-server-troubleshoot —
reason.bug-hunting.to-remote - git-commit-workflow —
reason.bug-hunting.to-git
Related docs
Next up
- remote-server-troubleshoot —
next.bug-hunting.to-remote