Find the Commit That Broke a Flaky Test Using Repeated Bisection
Last updated: November 29, 2026
Quick Overview
A test that already fails 5 percent of the time on healthy code started failing about 30 percent of the time somewhere in the last few hundred commits. Write a bisection routine that finds the first bad commit while tolerating the flakiness.
Meta
November 29, 20260
0
0 solved
A test that already fails 5 percent of the time on healthy code started failing about 30 percent of the time somewhere in the last few hundred commits. Write a bisection routine that finds the first bad commit while tolerating the flakiness.
Meta's monorepo lands thousands of diffs a day, and continuous integration has to blame regressions on specific diffs even when the tests involved are flaky. In an onsite fundamentals or debugging round, the interviewer is looking for the realization that a single pass or fail is not evidence, and for a principled stopping rule rather than 'run it ten times'.
What the Interviewer Expects
- Explains why naive bisection is wrong when a single run can mislead
- Frames each probe as a hypothesis test between two failure rates
- Uses a sequential test (SPRT) or a justified fixed sample size with early stopping
- Verifies the final boundary with stricter error rates before blaming a diff
- Estimates total test runs and discusses the error compounding across log2(n) steps
- Mentions practical measures such as quarantining flaky tests and recording flake rates
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How do you estimate p_good and p_bad if nobody gives them to you?
- What if the regression is caused by two commits interacting rather than one?
- How would you parallelize probes across many CI machines to cut wall-clock time?
- How would you change the approach if some commits do not build?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Input: ordered
commits, first known good, last known bad, andrun_test(commit) -> bool(True means pass). - Failure rate is
p_goodbefore the regression andp_badfrom the culprit onward. - ...
High-Level Design
Ordinary binary search keeps the invariant lo good, hi bad, but one spurious result breaks the invariant forever. So each probe must answer 'is this commit's failure rate p_good or p_bad?' with a ...