Capture and replay real PR runs

Production debugging on this kind of pipeline is painful when the only repro is a customer PR you cannot share. The fix is to capture every input and output as JSONL, then replay it through the same code path locally. The bug becomes deterministic and the fix lands faster.

capture.py
python
import json, time, uuid, pathlib

CAPTURE_DIR = pathlib.Path(".captures")

def capture(event: str, payload: dict, run_id: str) -> None:
    """Append one structured line per event in the review pipeline."""
    CAPTURE_DIR.mkdir(exist_ok=True)
    line = {"ts": time.time(), "run_id": run_id, "event": event, "payload": payload}
    (CAPTURE_DIR / f"{run_id}.jsonl").open("a").write(json.dumps(line) + "\n")

def replay(run_id: str):
    """Walk a captured run and re-emit the same events to the inspector."""
    for line in (CAPTURE_DIR / f"{run_id}.jsonl").read_text().splitlines():
        yield json.loads(line)

Each run gets a UUID and one JSONL file. fetch_pr_diff, review_pr, and post_review_comments all call capture() with their inputs and outputs.

One privacy rule. Captures contain real PR diffs, which often contain proprietary code. Keep the capture directory in a developer-only path, scrub access tokens before writing, and never commit captures to git. The .gitignore for the workshop already excludes the capture folder.

Quiz: Quiz

Loading practice…