Fix the deploy matcher for a latency incident

Review the AI's codeEasy10 minAnthropic and OpenAI style

Your task

At 02:14 UTC the p99 latency of your Go search service tripled. Nobody deployed by hand overnight, but several pull requests from an AI agent merged on their own after passing CI. The first step is to match the onset against the deploy log and find which deploy could have caused it.

An assistant wrote find_suspect_deploy(deploy_minutes, deploy_shas, onset_minute, window_minutes). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • deploy_minutes and deploy_shas: each deploy's time in minutes since midnight UTC, and the commit SHA it shipped, at the same index. 02:14 is minute 134.
  • onset_minute: the minute the latency spike began.
  • window_minutes: how long before the onset a deploy can still explain it.
  • Return the suspect's SHA, or none, ambiguous or invalid.

Rules the tests check:

  • Return invalid if the two lists differ in length, if window_minutes is negative, or if any SHA is empty.
  • A deploy is a suspect when its minute is from onset_minute - window_minutes to onset_minute, both included.
  • No suspects: none. More than one: ambiguous. Exactly one: its SHA.

Examples

find_suspect_deploy(deploy_minutes: list[int], deploy_shas: list[str], onset_minute: int, window_minutes: int) -> str
Example 1
Inputfind_suspect_deploy([60, 132, 200], ["a1", "b2", "c3"], 134, 30)
Output"b2"
Example 2
Inputfind_suspect_deploy([110, 132, 200], ["a1", "b2", "c3"], 134, 30)
Output"ambiguous"