The 401 Retry Bug: Auditing an Agent-Written Backoff Loop With a Fake Server
说明与用途
问题:代理生成的指数退避循环错误地在所有异常上重试,忽略状态码,并静默返回 None,可能破坏后续调用。解决方案:识别 diff 中的缺陷,运行轻量级伪服务器记录时间戳,并编写单元测试以断言正确的时间和行为。
问题
A pull request added an exponential backoff loop that retries a 401 response six times, sleeping about 63 seconds, but the retry logic contains multiple defects: it catches all Exceptions, retries on non‑auth errors, ignores Retry‑After headers, and silently returns None.
结果
The review uncovered that the agent‑written backoff loop incorrectly retries on all Exceptions, ignores status filtering, and silently returns None, potentially corrupting downstream callers. A minimal fake server and unit tests were used to validate timing and expose the defects.
工作流
- Read the diff and identify retry smells
- Stand up a fake server that records timestamps
- Write unit tests that assert timing and behavior
证据
It also retries a 401 six times. Along the way it sleeps about 63 seconds.
The first smell is except Exception. It catches KeyError from a bug in the caller. It catches programming errors and network errors with the same hand.
The second smell is the missing status filter. A 400 and a 503 produce identical behavior. Authentication failures get retried, which is pure latency with no upside.
The third smell is return None. A silent None corrupts every downstream caller.
- 记录日期: 2026-10-26T12:26:16.712Z