Fix the next-step rule for a flaky test agent
Your task
You asked an agent to fix a flaky integration test. First it added a sleep(2). You asked for a real fix, and it wrapped the assertion in a retry loop: the same move again. Your team now uses a simple rule, based on the agent's attempts so far, to decide what to do next.
An assistant wrote decide_agent_next_step(attempts). It is in the editor. It has a bug. Find it and fix it.
Input and output:
attempts: a short tag for each attempt, oldest first, likeadd_sleep_2sorawait_ready_signal.- Return
"delegate","accept","resteer"or"take_over".
Rules the tests check:
- With no attempts yet:
"delegate". - An attempt is stalled when its tag, lowercased, contains
sleep,retry,timeout,pollorbackoff, or when the tag is empty. Those only add waiting. The textwaitalone is not a marker:await_ready_signalis a real fix. - Count the stalled attempts at the end of the list only. Start from the newest attempt and stop at the first one that is not stalled.
- That count is 0:
"accept", the latest attempt is a real fix. It is 1:"resteer", one try on the wrong track, so nudge once with better evidence. It is 2 or more:"take_over".
Examples
decide_agent_next_step(attempts: list[str]) -> strExample 1
Input
decide_agent_next_step(["add_sleep_2s"])Output
"resteer"Example 2
Input
decide_agent_next_step(["add_sleep_2s", "wrap_assertion_in_retry_loop"])Output
"take_over"Example 3
Input
decide_agent_next_step(["await_ready_signal"])Output
"accept"