Fix the merge gate for AI-written unsafe Rust

Review the AI's codeEasy10 minAnthropic and OpenAI style

Your task

Your team mostly writes Python, and an AI agent rewrote a hot data path component in Rust for speed. It uses unsafe blocks, which switch off the compiler's memory safety checks, and nobody on the team can audit them. Before anything merges, a gate decides what the change needs next.

An assistant wrote assess_unsafe_merge(unsafe_blocks, qualified_reviewers, sanitizers_run, fuzz_hours), the gate. It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • unsafe_blocks: how many unsafe blocks the change has.
  • qualified_reviewers: how many people can review this Rust code, unsafe blocks included.
  • sanitizers_run: the sanitizers CI ran, by name. Sanitizers are tools such as Miri, ASan and TSan that catch memory and threading errors while the code runs.
  • fuzz_hours: hours of fuzzing (testing with random inputs) behind the change.
  • Return one verdict string.

Rules the tests check. Return the first that applies:

  1. unsafe_blocks, qualified_reviewers or fuzz_hours is negative: invalid_input.
  2. No unsafe blocks and at least 1 reviewer: merge.
  3. No unsafe blocks and no reviewer: needs_review.
  4. Unsafe blocks and no reviewer: rewrite_in_safe_rust.
  5. sanitizers_run is missing any of miri, asan and tsan: run_sanitizers. An entry matches when it equals the name, ignoring the case of ASCII letters. Other entries and repeats do not matter.
  6. Fewer than 8 fuzz hours: extend_fuzzing.
  7. Otherwise: merge_after_audit.

Examples

assess_unsafe_merge(unsafe_blocks: int, qualified_reviewers: int, sanitizers_run: list[str], fuzz_hours: int) -> str
Example 1
Inputassess_unsafe_merge(3, 0, ["asan", "miri", "tsan"], 24)
Output"rewrite_in_safe_rust"
Example 2
Inputassess_unsafe_merge(3, 1, ["asan", "miri"], 24)
Output"run_sanitizers"