Fix the effect count for a widened retry
Your task
An agent refactored your Python retry helper "for clarity". The old version retried only TimeoutError. The new one also retries ConnectionError, and the tests still pass. But some connection errors happen after the server has already applied the request, and retrying those applies it twice. To show the change, you count how many times a call's effect lands.
An assistant wrote applied_effect_count(attempt_outcomes, retry_connection_errors, max_attempts). It is in the editor. It has a bug. Find it and fix it.
Input and output:
attempt_outcomes: what each attempt does, in order.retry_connection_errors: true for the new policy, false for the old one.max_attempts: the most attempts the helper makes.- Return how many times the server applied the request.
Rules the tests check:
- Make attempts in order, at most
max_attemptsof them, and only while outcomes are left. - Read each outcome with whitespace trimmed from both ends, ignoring case:
ok: the call succeeded and its effect applied once. Stop.timeout: nothing reached the server. Retry.dropped-after-send: the server applied the request, then the connection died. The effect counts once. Retry only whenretry_connection_errorsis true. Otherwise stop.refused: the connection never opened, so nothing applied. Retry only whenretry_connection_errorsis true. Otherwise stop.- Anything else: nothing applied. Stop.
Examples
applied_effect_count(attempt_outcomes: list[str], retry_connection_errors: bool, max_attempts: int) -> intExample 1
Input
applied_effect_count(["dropped-after-send", "ok"], False, 3)Output
1Example 2
Input
applied_effect_count(["dropped-after-send", "ok"], True, 3)Output
2Example 3
Input
applied_effect_count(["timeout", "timeout", "ok"], True, 5)Output
1