Fix the decision rule for an AI fix loop

Review the AI's codeEasy10 min

Your task

You asked an AI to fix a failing TypeScript test. Its first fix did not work, and its second made a different test fail. Instead of prompting until something sticks, your team uses a rule that reads the failing tests after each fix and picks the next step.

An assistant wrote next_ai_fix_action(rounds). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • rounds: lists of failing test names. rounds[0] is what failed before any AI fix, and each later entry is what failed after the next fix. So the number of AI fixes so far is one less than the number of rounds.
  • Return one of "accept", "reprompt_with_context", "reprompt_with_all_tests" and "debug_yourself".

Rules the tests check. Return the first that applies:

  1. "reprompt_with_context" when there are no rounds.
  2. "accept" when the last round has no failing tests.
  3. "reprompt_with_context" when there is only one round, so the AI has not tried yet.
  4. "debug_yourself" when the AI has made 2 or more fixes.
  5. "reprompt_with_all_tests" when a test fails in the last round that did not fail in the round before it. That is a regression.
  6. "reprompt_with_context" otherwise.

Test names match exactly, and a name repeated within a round counts once.

Examples

next_ai_fix_action(rounds: list[list[str]]) -> str
Example 1
Inputnext_ai_fix_action([["test_parse_amount"], ["test_parse_amount"], ["test_render_total"]])
Output"debug_yourself"
Example 2
Inputnext_ai_fix_action([["test_parse_amount"], []])
Output"accept"
Example 3
Inputnext_ai_fix_action([["test_parse_amount"], ["test_render_total"]])
Output"reprompt_with_all_tests"