Fix the evidence check behind a dead code claim

Review the AI's codeEasy10 min

Your task

You asked an AI to trace your /checkout endpoint, and it said the legacy CheckoutV1 module is dead code you can ignore. Your team only accepts a dead code claim when the evidence backs it. So you classify each module from a repo-wide reference count and its live traffic.

An assistant wrote classify_dead_code(module_names, static_refs, request_counts, window_days). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • module_names: the module names, in order.
  • static_refs: for the module at the same index, how many references a repo-wide search found, including config, route tables and dependency injection wiring. The list can be shorter than module_names. A negative value means the search failed.
  • request_counts: for the module at the same index, how many requests it served in the traffic window. The list can be shorter than module_names. A negative value means the metric is missing.
  • window_days: how many days of traffic request_counts covers.
  • Return one string per module, in input order: the name, then =, then the verdict.

Rules the tests check:

  • A module's verdict is the first of these that applies:
    1. unproven when static_refs or request_counts has no value at its index, or either value is negative.
    2. live when its request count is above 0.
    3. referenced when its reference count is above 0.
    4. unproven when window_days is under 30.
    5. dead otherwise.
  • An empty module_names returns an empty list.

Examples

classify_dead_code(module_names: list[str], static_refs: list[int], request_counts: list[int], window_days: int) -> list[str]
Example 1
Inputclassify_dead_code(["CheckoutV1", "CheckoutV2", "LegacyPromo"], [0, 5, 0], [0, 0, 3], 60)
Output["CheckoutV1=dead", "CheckoutV2=referenced", "LegacyPromo=live"]
Example 2
Inputclassify_dead_code(["CheckoutV1"], [0], [0], 29)
Output["CheckoutV1=unproven"]