Fix the next-step rule for a flaky test agent

Review the AI's codeEasy10 min

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, like add_sleep_2s or await_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, poll or backoff, or when the tag is empty. Those only add waiting. The text wait alone is not a marker: await_ready_signal is 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]) -> str
Example 1
Inputdecide_agent_next_step(["add_sleep_2s"])
Output"resteer"
Example 2
Inputdecide_agent_next_step(["add_sleep_2s", "wrap_assertion_in_retry_loop"])
Output"take_over"
Example 3
Inputdecide_agent_next_step(["await_ready_signal"])
Output"accept"