import json from pathlib import Path import subprocess import gradio as gr from metric_audit import MAX_SNIPPET_BYTES, run_snippet EVIDENCE_PATH = Path(__file__).with_name("evidence.json") REPORT_PATH = EVIDENCE_PATH.with_name("REPORT.md") EVIDENCE = json.loads(EVIDENCE_PATH.read_text(encoding="utf-8")) RULES = [("197 rules · scb-check 0.1.3", "current"), ("137 rules · historical", "legacy")] PATCHES = [ ("Original source", "control"), ("A · Leading newline", "A"), ("B · Layout boundaries", "B"), ("C · Nested parbox commands", "C"), ("A + B", "AB"), ("A + C", "AC"), ("B + C", "BC"), ("A + B + C", "ABC"), ] PATCH_RESULTS = { (row["checkpoint"], row["suite"], row["patch"]): row for row in EVIDENCE["ablation"] } TEST_RESULTS = { (row["checkpoint"], row["suite"]): row["cases"] for row in EVIDENCE["test_outcomes"] } CAUSES = { "body_opening_newline": "Removed leading newline", "layout_boundary_newlines": "Extra layout boundary newlines", "nested_parbox_commands": "Skipped nested parbox commands", "empty_admonition": "Extra newline in empty Docusaurus blocks", } TIERS = ("Hobby", "Niche", "Established", "Major") EXAMPLE = Path(__file__).with_name("example.py").read_text(encoding="utf-8") def sample_row(label, sample): return [ label, sample["n"], *(f"{sample[metric]['mean']:.3f} ± {sample[metric]['sd']:.3f}" for metric in ("verbosity", "erosion")), ] def table2_rows(): rows = [] for cohort in ("human", "agent", *TIERS): n, verbosity, verbosity_sd, erosion, erosion_sd = EVIDENCE["paper"][cohort] rows.append([f"Paper · {cohort.title()}", n, f"{verbosity:.3f} ± {verbosity_sd:.3f}", f"{erosion:.3f} ± {erosion_sd:.3f}"]) group = EVIDENCE["human_tiers"] if cohort in TIERS else EVIDENCE["cohorts"] rows.append(sample_row(f"Audit · {cohort.title()}", group[cohort])) return rows def rule_result(version): paired = EVIDENCE["paired"][version] ratio = paired["agent"]["verbosity"]["mean"] / paired["human"]["verbosity"]["mean"] rows = [sample_row(cohort.title(), paired[cohort]) for cohort in ("human", "agent")] return f"### {ratio:.2f}×\nAgent-to-human mean verbosity", rows def paired_ratio_chart(): rows = [] for label, version in RULES: pair = EVIDENCE["paired"][version] ratio = pair["agent"]["verbosity"]["mean"] / pair["human"]["verbosity"]["mean"] rows.append( f'
{label}' f'
' f'{ratio:.2f}×
' ) return '
' + "".join(rows) + "
" def patch_result(checkpoint, suite, patch): result = PATCH_RESULTS[checkpoint, suite, patch] summary = ( f"### {result['passed']}/{result['total']} passed\n" f"**{len(result['recovered'])}** recovered · **{len(result['regressed'])}** new failures" ) return summary, [[change, case] for change, cases in ( ("New failure", result["regressed"]), ("Recovered", result["recovered"]), ) for case in cases] def cohort_cases(cause="all"): return [[suite, case, CAUSES[mechanism], {True: "Same HTML", False: "Different HTML", None: "Outside rendering study"}[same]] for case, suite, mechanism, same in EVIDENCE["diagnoses"] if cause == "all" or cause == mechanism] def suite_transitions(suite, before, after): baseline = TEST_RESULTS[before, suite] selected = TEST_RESULTS[after, suite] if baseline.keys() != selected.keys(): raise gr.Error("These checkpoints have different case lists.") return [[case, first, selected[case]] for case, first in baseline.items() if first != selected[case]] def snippet_result(source): try: report = run_snippet(source) except subprocess.TimeoutExpired: raise gr.Error("The static scorer timed out. Try a shorter snippet.") from None except (OSError, ValueError) as error: raise gr.Error(str(error)) from None rows = [] for key in ("current", "legacy"): bundle = report["bundles"][key] score = bundle["score"] rows.append([bundle["rule_count"], f"{score['verbosity']:.4f}", f"{score['erosion']:.4f}", score["verbosity_flagged_loc"], score["total_loc"]]) changed_rules = [ [report["bundles"][key]["rule_count"], rule, line, end_line, count] for key, hits in report["rule_hits_only_in"].items() for rule, _, line, end_line, _, _, count in hits ] changed_lines = [ [report["bundles"][key]["rule_count"], number] for key, lines in report["counted_lines_only_in"].items() for _, number in lines ] return rows, changed_lines, changed_rules, report CSS = """ gradio-app { overflow-x: clip; } .gradio-container { max-width: 1060px !important; margin-inline: auto !important; } #intro { border-top: 5px solid #36a3a1; padding: 1.25rem 0 .5rem; } #intro h1 { font-size: clamp(2.5rem, 7vw, 4.125rem); letter-spacing: -.055em; } .measure h3 { font-size: 2rem; } .ratio-chart { display: grid; gap: .65rem; max-width: 700px; margin-block: .5rem; } .ratio-row { display: grid; grid-template-columns: minmax(0, 1fr) 1fr 3.5rem; align-items: center; gap: .55rem; } .ratio-track { border-radius: .2rem; background: var(--background-fill-secondary); height: .7rem; } .ratio-track span { display: block; height: 100%; border-radius: inherit; background: #36a3a1; } """ RESPONSIVE_HEAD = """ """ THEME = gr.themes.Soft(primary_hue="teal", neutral_hue="slate", font=["Inter", "sans-serif"]) SCORE_COLUMNS = ["Cohort", "n", "Verbosity", "Structural erosion"] ratio = EVIDENCE["ratios"] causes = EVIDENCE["cause_counts"] rendered = EVIDENCE["renderers"]["markdown-it-py (CommonMark)"] changes = EVIDENCE["rule_differences"] initial_patch, initial_transitions = patch_result(3, 3, "A") with gr.Blocks(title="Beyond Pass Rates", analytics_enabled=False) as demo: gr.Markdown( "# Beyond Pass Rates\n" "Explore how scoring rules and shared defects shape a coding agent’s benchmark results.", elem_id="intro", ) with gr.Tab("Table 2 audit"): gr.Markdown( "### Verdict · Inconclusive\n" f"Agent snapshots had **{ratio['verbosity']:.2f}×** the mean verbosity and " f"**{ratio['erosion']:.2f}×** the mean structural erosion of the substitute " "human repositories. The paper’s original sample list " "and scoring configuration remain unavailable." ) gr.Dataframe(value=table2_rows(), headers=SCORE_COLUMNS, interactive=False) gr.Dataframe( value=[sample_row("Independent published scores", EVIDENCE["cohorts"]["public"])], headers=SCORE_COLUMNS, interactive=False, ) gr.Markdown("The published scores have their own sample and scoring provenance.") gr.Markdown( "Verbosity measures the share of lines flagged for patterns such as redundancy " "or duplication. Structural erosion measures how much code complexity is " "concentrated in functions with high cyclomatic complexity. Values show mean ± SD." ) gr.Markdown( "[Paper v2](https://arxiv.org/abs/2603.24755v2) · " "[Official claim](https://huggingface.co/datasets/Neurips-2026-MLIntern-Repro/papers/raw/main/site/p/2603.24755.json)" ) with gr.Tab("Scoring rules"): gr.Markdown( "Switch rule sets to compare scores on the same 12 human repositories and " "13 Agent snapshots. The scoring engine stays fixed. This comparison covers " "the selected samples." ) gr.HTML(paired_ratio_chart()) rules = gr.Radio(RULES, value="current", label="AST-Grep rule set") initial_ratio, initial_rows = rule_result("current") measured_ratio = gr.Markdown(initial_ratio, elem_classes="measure") cohort_table = gr.Dataframe(value=initial_rows, headers=SCORE_COLUMNS, interactive=False) rules.change(rule_result, rules, [measured_ratio, cohort_table], api_name="rule_result") with gr.Accordion("Rule IDs and changes", open=False): gr.Markdown( f"The bundles share **{changes['shared']}** IDs. " f"**{len(changes['matching_logic_changed'])}** shared rules changed matching logic." ) gr.Dataframe( value=[[label, name] for label, names in ( ("Only in 137", changes["old_only"]), ("Only in 197", changes["new_only"]), ("Matching logic changed", changes["matching_logic_changed"]), ) for name in names], headers=["Change", "Rule ID"], interactive=False, max_height=290, ) with gr.Tab("Checkpoint tests"): gr.Markdown( "Each row runs the five official test suites on one saved checkpoint from a " "single LaTeX-to-Markdown agent run. Cells show tests passed / total." ) gr.Dataframe( value=EVIDENCE["matrix"], headers=["Source checkpoint", *(f"Suite {index}" for index in range(1, 6))], interactive=False, ) with gr.Accordion("Compare test outcomes across checkpoints", open=False): with gr.Row(): compare_suite = gr.Dropdown(list(range(1, 6)), value=4, label="Test suite") compare_before = gr.Dropdown(list(range(1, 6)), value=3, label="Baseline source") compare_after = gr.Dropdown(list(range(1, 6)), value=4, label="Comparison source") matrix_changes = gr.Dataframe( value=suite_transitions(4, 3, 4), headers=["Test", "Baseline", "Comparison"], interactive=False, max_height=300, ) gr.on( [compare_suite.change, compare_before.change, compare_after.change], suite_transitions, [compare_suite, compare_before, compare_after], matrix_changes, api_name="suite_transitions", ) gr.Markdown( f"Suite 3 stayed at **6/49** from checkpoints 3 to 5. Three Markdown " f"renderers agreed that **{rendered['equal']}/{rendered['total']}** " "expected and actual output pairs produced identical HTML." ) gr.Dataframe( value=[[name, causes[key]] for key, name in CAUSES.items()], headers=["Source mechanism", "Persistent failures attributed"], interactive=False, ) gr.Markdown( "The four mechanisms account for 50 initially failing tests that stayed failed " "through checkpoint 5 in this trajectory. HTML equivalence covers Suite 3." ) cause = gr.Dropdown([("All mechanisms", "all"), *((name, key) for key, name in CAUSES.items())], value="all", label="Filter persistent failures") cases = gr.Dataframe(value=cohort_cases(), headers=["Suite", "Test", "Mechanism", "Rendering"], interactive=False, max_height=340) cause.change(cohort_cases, cause, cases, api_name="persistent_cases") with gr.Tab("Patch interactions"): gr.Markdown( "Compare recorded counterfactual repairs with the original source at the same " "checkpoint. Recovered tests changed from fail to pass. New failures changed " "from pass to fail." ) with gr.Row(): checkpoint = gr.Dropdown([3, 4, 5], value=3, label="Source checkpoint") suite = gr.Dropdown(list(range(1, 6)), value=3, label="Test suite") patch = gr.Radio(PATCHES, value="A", label="Source patches") result = gr.Markdown(initial_patch, elem_classes="measure") transitions = gr.Dataframe(value=initial_transitions, headers=["Result", "Test"], interactive=False, max_height=340) gr.on( [checkpoint.change, suite.change, patch.change], patch_result, [checkpoint, suite, patch], [result, transitions], api_name="patch_result", ) with gr.Tab("Score Python"): gr.Markdown( "Paste up to 64 KiB or 1,200 lines of Python for a static comparison. " "Use the local command line for entire repositories or private source." ) source = gr.Textbox(value=EXAMPLE, lines=10, max_lines=20, label="Python source") run = gr.Button("Score both rule sets", variant="primary") scores = gr.Dataframe( headers=["Rules", "Verbosity", "Structural erosion", "Counted lines", "Source lines"], interactive=False, ) lines = gr.Dataframe( headers=["Rule set", "Source line"], label="Lines counted by only one bundle", interactive=False, max_height=320, ) hits = gr.Dataframe( headers=["Rule set", "Rule ID", "Start line", "End line", "Occurrences"], label="Rule hits unique to one bundle", interactive=False, max_height=320, ) with gr.Accordion("Full score report", open=False): full_report = gr.JSON(label="Audit JSON") run.click(snippet_result, source, [scores, lines, hits, full_report], concurrency_limit=1, api_name="score_python") with gr.Row(): gr.DownloadButton("Download evidence (JSON)", value=EVIDENCE_PATH) gr.DownloadButton("Download research report", value=REPORT_PATH) if __name__ == "__main__": demo.queue(max_size=16) demo.launch(theme=THEME, css=CSS, head=RESPONSIVE_HEAD, share=False, max_file_size=MAX_SNIPPET_BYTES, enable_monitoring=False, blocked_paths=[str(EVIDENCE_PATH.parent / "metric_rules")])