It happened twice, you cannot make it happen again, and every debugging technique assumes you can. This is the hardest category and it has a different method: stop trying to reproduce it and start gathering evidence about the occasions it does happen.
What produces intermittent failures?
- Timing. Two things happening in an order that is usually different.
- Specific data. One record with something unusual in it.
- External services. Which fail occasionally by nature.
- Resource limits. Memory, connections, quotas reached under load.
- Environment. One machine, one browser, one configuration.
- Accumulated state. Something that only fails on the second run.
What should you collect?
Everything about the occasions it occurred. Time, user, input, what else was happening, which machine, how long the process had been running. The pattern is in the differences between failing and succeeding cases.
What is the most useful question?
What is different about the times it fails. That reframes an unanswerable question into a comparative one, and comparisons are tractable where mysteries are not.
This fails roughly one time in twenty and I cannot reproduce it. Here is what the code does and here is what I know about the occasions it failed. Given these categories of cause, which fit the pattern, and what should I log to distinguish between them?
Why ask what to log rather than what is wrong?
Because you cannot confirm any hypothesis without more information, and adding the right logging turns the next occurrence into a diagnosis rather than another report.
This is the one situation where waiting is the productive strategy.
What should you log?
The values involved, a request identifier, timing, and anything the suspected causes would distinguish. Enough to tell afterwards exactly what the conditions were, since you will not be watching when it happens.
How do you rule out timing?
By asking whether anything runs concurrently and whether order is guaranteed. Race conditions are the classic intermittent cause and they are invisible in the code, since each part is correct on its own.
This is a category AI handles poorly, so the answer is a prompt to investigate rather than a conclusion.
What about the one bad record?
Frequently the answer and easy to check. Running the operation across all your data, catching failures and reporting which items failed, converts an intermittent bug into a specific and reproducible one in about ten minutes.
How do you make it happen more often?
By exaggerating the conditions you suspect. If you think it is load, run it under heavy load; if you think it is timing, add a delay in the place you suspect; if you think it is one record, run it against everything.
Deliberately making a rare failure common is the most productive move available here, and it converts an intermittent bug into a reproducible one. It also confirms the category before you spend time on a specific diagnosis, which is where most investigations of this kind go wrong.
What is worth accepting?
That some of these are not worth chasing. Something failing rarely, with a small consequence and a retry that resolves it, may be a reasonable thing to log and leave. Spending three days on it is a choice rather than an obligation.