Fix the stage finder for a SQL pipeline incident
Your task
A reporting pipeline your team generated with AI agents has produced a wrong number in production. The pipeline is a chain of SQL stages, each feeding the next, so one bad stage throws off every stage after it. You have the expected and actual row count for each stage, and whether the stage's owner can explain its logic.
An assistant wrote bisect_pipeline_divergence(stage_names, expected_rows, actual_rows, owner_can_explain). It is in the editor. It has a bug. Find it and fix it.
Input and output:
stage_names,expected_rows,actual_rows,owner_can_explain: four lists of the same length, one entry per stage, in pipeline order.- Return
[], or a list naming the stage where the problem starts.
Rules the tests check:
- The problem starts at the first stage, in pipeline order, whose actual count differs from its expected count. Only that stage has its own cause: later gaps are carried down from it.
- If every stage matches, return
[]. - Otherwise return
[name, "delta=<d>"], wheredis actual minus expected for that stage, written as a plain whole number (a minus sign when negative, no plus sign). - If
owner_can_explainis false for that stage, add a third element,"comprehension-debt".
Examples
bisect_pipeline_divergence(stage_names: list[str], expected_rows: list[int], actual_rows: list[int], owner_can_explain: list[bool]) -> list[str]Example 1
Input
bisect_pipeline_divergence(["source", "filter_cte", "window_cte", "final"], [1000, 900, 900, 900], [1000, 860, 860, 860], [True, False, True, True])Output
["filter_cte", "delta=-40", "comprehension-debt"]Example 2
Input
bisect_pipeline_divergence(["a", "b"], [1, 2], [1, 2], [True, True])Output
[]Example 3
Input
bisect_pipeline_divergence(["a"], [5], [7], [True])Output
["a", "delta=2"]