Fix the stuck agent detector for flaky test fixes
Your task
An agent asked to fix a flaky Go test added a mutex, then time.Sleep(50 * time.Millisecond), then raised the sleep to 200 ms. Raising the same number again and again is the sign that it has no model of the bug. Your tooling watches the agent's patch history and says when to stop and reset the approach.
An assistant wrote detect_magic_number_loop(patches). It is in the editor. It has a bug. Find it and fix it.
Input and output:
patches: the agent's edits in order, each writtenkey=value, such assleep_ms=200.- Return
"reset:<key>"for the knob the agent keeps raising, or"continue".
Rules the tests check:
- Split each patch at its first
=. Skip a patch with no=, an empty key, or a value that is not one or more digits from 0 to 9. - For each key, look at all of its patches in list order, wherever they are. Other patches can come between them.
- A key is escalating when it has at least 3 patches and each one after the first has a strictly greater value than the one before it. A repeated value or a drop at any point means it is not escalating.
- If several keys are escalating, pick the one whose third patch comes earliest in the list.
- If no key is escalating, return
"continue".
Examples
detect_magic_number_loop(patches: list[str]) -> strExample 1
Input
detect_magic_number_loop(["mutex=1", "sleep_ms=50", "sleep_ms=200"])Output
"continue"Example 2
Input
detect_magic_number_loop(["sleep_ms=50", "sleep_ms=200", "sleep_ms=500"])Output
"reset:sleep_ms"Example 3
Input
detect_magic_number_loop(["timeout_ms=1000", "timeout_ms=1000", "timeout_ms=1000"])Output
"continue"