Show CodeQL in the bug and security benchmark tables

#32
Files changed (2) hide show
  1. README.md +7 -23
  2. tradeoff.py +38 -16
README.md CHANGED
@@ -28,7 +28,7 @@ Pairs come from open-source projects in Rust, JavaScript, TypeScript, Python, Go
28
 
29
  Each line shows how many issues a model finds and what percentage of clean methods it wrongly flags as its score cutoff changes. Higher and farther left is better.
30
 
31
- The tables use each run's recorded alert settings. A value of 20% under ‘Clean methods wrongly flagged’ means one in five clean methods received an alert. Models are ranked by recall minus that percentage. Bold marks the best displayed value in each column; cost compares priced runs captured here.
32
 
33
  ## Bugs
34
 
@@ -47,6 +47,9 @@ The tables use each run's recorded alert settings. A value of 20% under ‘Clean
47
  | [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 25.3% | 22.6% | 2.7% | **$0.182** |
48
  | [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 4.1% | **2.5%** | 1.6% | Free tier |
49
  | [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **81.9%** | 80.9% | 1.0% | ~$0.210 |
 
 
 
50
 
51
  ### Private — 498 pairs
52
 
@@ -75,9 +78,12 @@ The tables use each run's recorded alert settings. A value of 20% under ‘Clean
75
  | [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 55.6% | 46.8% | 8.8% | Free tier |
76
  | [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 33.1% | 25.8% | 7.3% | **$0.208** |
77
  | [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 21.0% | **17.2%** | 3.9% | $0.251 |
 
78
  | [SemiF](https://github.com/TheoLeeCJ/SemIf) | **100.0%** | 99.9% | 0.1% | **$0.208** |
79
  | [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **100.0%** | 100.0% | 0.0% | ~$1.432 |
80
 
 
 
81
  ### Private — 439 pairs
82
 
83
  | Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
@@ -132,28 +138,6 @@ Inference costs cover scoring the method sides in each table. Jev costs are esti
132
 
133
  JevLike (192-byte input), Laya (512-token input), and Kev (packed-branch limit) could not score every full-context method. NanoJev was unavailable on Beam. They are excluded rather than ranked on partial results.
134
 
135
- ## CodeQL comparison
136
-
137
- [CodeQL](https://codeql.github.com/) and Jev were evaluated on the same public method sides in a separate cohort. CodeQL analyzed full repository snapshots; Jev used its saved Perch inputs and recorded alert settings. A CodeQL finding counts when its primary location falls inside the labelled method. The matched set contains 52 bug pairs and 70 security pairs.
138
-
139
- ### Bugs: 52 pairs
140
-
141
- | Tool | TP | FP | FN | Precision | Recall | F1 | False-positive rate |
142
- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
143
- | CodeQL | 0 | 0 | 21 | — (0 alerts) | 0.0% | 0.0% | 0.0% |
144
- | Jev | 6 | 8 | 15 | 42.9% | 28.6% | 34.3% | 9.6% |
145
-
146
- ### Security: 70 pairs
147
-
148
- | Tool | TP | FP | FN | Precision | Recall | F1 | False-positive rate |
149
- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
150
- | CodeQL | 1 | 0 | 26 | 100.0% (1 alert) | 3.7% | 7.1% | 0.0% |
151
- | Jev | 8 | 12 | 19 | 40.0% | 29.6% | 34.0% | 10.6% |
152
-
153
- TP is a finding on a labelled issue, FP is a finding on a labelled clean method, and FN is a missed issue. False-positive rate is FP divided by clean methods: 83 for bugs and 113 for security. CodeQL found an [OpenJPEG integer-overflow cast](https://github.com/uclouvain/openjpeg/commit/ef01f18dfc6780b776d0674ed3e7415c6ef54d24) in `opj_pi_create_decode` before the repair; Jev did not alert on that pair.
154
-
155
- The [CodeQL protocol](CODEQL.md), [runner](codeql_compare.py), [matched method decisions](codeql-comparison/), and [cohort list](codeql-cohort.json) are published here. Four selected bug pairs and three security pairs were excluded because a source snapshot could not be analyzed. CodeQL returns findings rather than probabilities, so these rows have no average-precision score or threshold curve.
156
-
157
  ## Files and reproduction
158
 
159
  - [`results-current.jsonl`](https://huggingface.co/datasets/perchscan/benchmark-results/blob/main/results-current.jsonl): current-pack aggregate results for public and private splits; no private pair data.
 
28
 
29
  Each line shows how many issues a model finds and what percentage of clean methods it wrongly flags as its score cutoff changes. Higher and farther left is better.
30
 
31
+ The tables use each run's recorded alert settings. A value of 20% under ‘Clean methods wrongly flagged’ means one in five clean methods received an alert. Models are ranked by recall minus that percentage. Bold marks the best full-set value in each column; cost compares priced runs captured here.
32
 
33
  ## Bugs
34
 
 
47
  | [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 25.3% | 22.6% | 2.7% | **$0.182** |
48
  | [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 4.1% | **2.5%** | 1.6% | Free tier |
49
  | [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **81.9%** | 80.9% | 1.0% | ~$0.210 |
50
+ | [CodeQL](https://codeql.github.com/) (52 pairs) | 0.0% | 0.0% | 0.0% | — |
51
+
52
+ CodeQL scored 52 of the 2,220 public pairs; other models scored all pairs. Its [method decisions](codeql-comparison/) and [evaluation protocol](CODEQL.md) are available here.
53
 
54
  ### Private — 498 pairs
55
 
 
78
  | [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 55.6% | 46.8% | 8.8% | Free tier |
79
  | [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 33.1% | 25.8% | 7.3% | **$0.208** |
80
  | [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 21.0% | **17.2%** | 3.9% | $0.251 |
81
+ | [CodeQL](https://codeql.github.com/) (70 pairs) | 3.7% | 0.0% | 3.7% | — |
82
  | [SemiF](https://github.com/TheoLeeCJ/SemIf) | **100.0%** | 99.9% | 0.1% | **$0.208** |
83
  | [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **100.0%** | 100.0% | 0.0% | ~$1.432 |
84
 
85
+ CodeQL scored 70 of the 1,311 public pairs; other models scored all pairs. Its [method decisions](codeql-comparison/) and [evaluation protocol](CODEQL.md) are available here.
86
+
87
  ### Private — 439 pairs
88
 
89
  | Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
 
138
 
139
  JevLike (192-byte input), Laya (512-token input), and Kev (packed-branch limit) could not score every full-context method. NanoJev was unavailable on Beam. They are excluded rather than ranked on partial results.
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  ## Files and reproduction
142
 
143
  - [`results-current.jsonl`](https://huggingface.co/datasets/perchscan/benchmark-results/blob/main/results-current.jsonl): current-pack aggregate results for public and private splits; no private pair data.
tradeoff.py CHANGED
@@ -110,6 +110,8 @@ def money(row: dict) -> str:
110
 
111
 
112
  def model_link(model: str) -> str:
 
 
113
  name, url = NAMES[model]
114
  return f"[{name}]({url})"
115
 
@@ -119,12 +121,14 @@ def percent(value: float) -> str:
119
 
120
 
121
  def results_table(rows: list[dict]) -> str:
122
- ordered = sorted(rows, key=lambda row: (-operating_metrics(row)[2], ORDER.index(row["model_id"])))
 
123
  metrics = {row["model_id"]: operating_metrics(row) for row in ordered}
124
- best_recall = max(round(value[0] * 100, 1) for value in metrics.values())
125
- best_false_positive_rate = min(round(value[1] * 100, 1) for value in metrics.values())
126
- best_net_recall = max(round(value[2] * 100, 1) for value in metrics.values())
127
- priced_costs = [round(row["inference_cost_usd"], 3) for row in ordered if row.get("inference_cost_usd") is not None]
 
128
  best_priced_cost = min(priced_costs) if priced_costs else None
129
 
130
  def mark(value: str, winner: bool) -> str:
@@ -135,12 +139,16 @@ def results_table(rows: list[dict]) -> str:
135
  for row in ordered:
136
  recall, false_positive_rate, j = metrics[row["model_id"]]
137
  cost = row.get("inference_cost_usd")
 
 
 
 
138
  table.append("| " + " | ".join((
139
- model_link(row["model_id"]),
140
- mark(percent(recall), round(recall * 100, 1) == best_recall),
141
- mark(percent(false_positive_rate), round(false_positive_rate * 100, 1) == best_false_positive_rate),
142
- mark(percent(j), round(j * 100, 1) == best_net_recall),
143
- mark(money(row), cost is not None and round(cost, 3) == best_priced_cost),
144
  )) + " |")
145
  return "\n".join(table)
146
 
@@ -196,10 +204,11 @@ def svg(domain: str, curves: dict[str, tuple[list[tuple[int, int]], int, int]],
196
  output.write_text("\n".join(out) + "\n")
197
 
198
 
199
- def render_sections(results: list[dict], curves_by_domain: dict[str, dict], output_dir: Path) -> str:
 
200
  sections = ["## Reading the results", "",
201
  "Each line shows how many issues a model finds and what percentage of clean methods it wrongly flags as its score cutoff changes. Higher and farther left is better.", "",
202
- "The tables use each run's recorded alert settings. A value of 20% under ‘Clean methods wrongly flagged’ means one in five clean methods received an alert. Models are ranked by recall minus that percentage. Bold marks the best displayed value in each column; cost compares priced runs captured here.", ""]
203
  for domain in ("bug", "security", "lint"):
204
  title = {"bug": "Bugs", "security": "Security", "lint": "Perch Lint Bench"}[domain]
205
  link = {"bug": "bug-pairs-public", "security": "security-pairs-public", "lint": "perch-lint-bench-public"}[domain]
@@ -207,13 +216,25 @@ def render_sections(results: list[dict], curves_by_domain: dict[str, dict], outp
207
  private = [r for r in results if r["domain"] == domain and r["track"] == "private"]
208
  if set(r["model_id"] for r in public) != set(ORDER) or set(r["model_id"] for r in private) != set(ORDER):
209
  raise ValueError(f"Unexpected models in {domain} results")
 
 
 
 
 
 
 
 
 
210
  image = output_dir / f"{domain}-tradeoff.svg"
211
  svg(domain, curves_by_domain[domain], image)
212
  sections += [f"## {title}", "", f"[Public pairs](https://huggingface.co/datasets/perchscan/{link})", "",
213
  f"![{title} recall versus false alerts](assets/{domain}-tradeoff.svg)", "",
214
  f"### Public — {public[0]['benchmark_pairs']:,} pairs", "",
215
- results_table(public), "",
216
- f"### Private — {private[0]['benchmark_pairs']:,} pairs", "",
 
 
 
217
  results_table(private), ""]
218
  return "\n".join(sections)
219
 
@@ -224,6 +245,7 @@ def main() -> None:
224
  parser.add_argument("--check", action="store_true", help="Check generated card and SVGs without writing")
225
  args = parser.parse_args()
226
  results = lines(ROOT / "results-current.jsonl")
 
227
  curves_by_domain = {}
228
  for domain in ("bug", "security", "lint"):
229
  labels = labels_for(domain, dataset(domain, args.dataset_root))
@@ -247,13 +269,13 @@ def main() -> None:
247
  end += len(end_marker)
248
  if args.check:
249
  with TemporaryDirectory() as temporary:
250
- content = render_sections(results, curves_by_domain, Path(temporary))
251
  for domain in DATASET_URLS:
252
  name = f"{domain}-tradeoff.svg"
253
  if (Path(temporary) / name).read_bytes() != (ROOT / "assets" / name).read_bytes():
254
  raise SystemExit(f"assets/{name} is not up to date; run python3 tradeoff.py")
255
  else:
256
- content = render_sections(results, curves_by_domain, ROOT / "assets")
257
  updated = (original[:start].rstrip("\n") + "\n\n" + start_marker + "\n\n" + content
258
  + "\n" + end_marker + "\n\n" + original[end:].lstrip("\n"))
259
  if args.check and original != updated:
 
110
 
111
 
112
  def model_link(model: str) -> str:
113
+ if model == "codeql":
114
+ return "[CodeQL](https://codeql.github.com/)"
115
  name, url = NAMES[model]
116
  return f"[{name}]({url})"
117
 
 
121
 
122
 
123
  def results_table(rows: list[dict]) -> str:
124
+ ordered = sorted(rows, key=lambda row: (-operating_metrics(row)[2],
125
+ ORDER.index(row["model_id"]) if row["model_id"] in ORDER else len(ORDER)))
126
  metrics = {row["model_id"]: operating_metrics(row) for row in ordered}
127
+ full_rows = [row for row in ordered if row["model_id"] != "codeql"]
128
+ best_recall = max(round(metrics[row["model_id"]][0] * 100, 1) for row in full_rows)
129
+ best_false_positive_rate = min(round(metrics[row["model_id"]][1] * 100, 1) for row in full_rows)
130
+ best_net_recall = max(round(metrics[row["model_id"]][2] * 100, 1) for row in full_rows)
131
+ priced_costs = [round(row["inference_cost_usd"], 3) for row in full_rows if row.get("inference_cost_usd") is not None]
132
  best_priced_cost = min(priced_costs) if priced_costs else None
133
 
134
  def mark(value: str, winner: bool) -> str:
 
139
  for row in ordered:
140
  recall, false_positive_rate, j = metrics[row["model_id"]]
141
  cost = row.get("inference_cost_usd")
142
+ is_codeql = row["model_id"] == "codeql"
143
+ name = model_link(row["model_id"])
144
+ if is_codeql:
145
+ name += f" ({row['benchmark_pairs']:,} pairs)"
146
  table.append("| " + " | ".join((
147
+ name,
148
+ mark(percent(recall), not is_codeql and round(recall * 100, 1) == best_recall),
149
+ mark(percent(false_positive_rate), not is_codeql and round(false_positive_rate * 100, 1) == best_false_positive_rate),
150
+ mark(percent(j), not is_codeql and round(j * 100, 1) == best_net_recall),
151
+ "—" if is_codeql else mark(money(row), cost is not None and round(cost, 3) == best_priced_cost),
152
  )) + " |")
153
  return "\n".join(table)
154
 
 
204
  output.write_text("\n".join(out) + "\n")
205
 
206
 
207
+ def render_sections(results: list[dict], curves_by_domain: dict[str, dict], output_dir: Path,
208
+ codeql_results: dict) -> str:
209
  sections = ["## Reading the results", "",
210
  "Each line shows how many issues a model finds and what percentage of clean methods it wrongly flags as its score cutoff changes. Higher and farther left is better.", "",
211
+ "The tables use each run's recorded alert settings. A value of 20% under ‘Clean methods wrongly flagged’ means one in five clean methods received an alert. Models are ranked by recall minus that percentage. Bold marks the best full-set value in each column; cost compares priced runs captured here.", ""]
212
  for domain in ("bug", "security", "lint"):
213
  title = {"bug": "Bugs", "security": "Security", "lint": "Perch Lint Bench"}[domain]
214
  link = {"bug": "bug-pairs-public", "security": "security-pairs-public", "lint": "perch-lint-bench-public"}[domain]
 
216
  private = [r for r in results if r["domain"] == domain and r["track"] == "private"]
217
  if set(r["model_id"] for r in public) != set(ORDER) or set(r["model_id"] for r in private) != set(ORDER):
218
  raise ValueError(f"Unexpected models in {domain} results")
219
+ if domain in ("bug", "security"):
220
+ comparison = codeql_results[domain]
221
+ if comparison["pairs"] > public[0]["benchmark_pairs"]:
222
+ raise ValueError(f"CodeQL cohort exceeds public {domain} pairs")
223
+ counts = comparison["models"]["codeql"]
224
+ if sum(counts[key] for key in ("tp", "fp", "fn", "tn")) != 2 * comparison["pairs"]:
225
+ raise ValueError(f"CodeQL {domain} counts do not match its paired cohort")
226
+ public.append({"model_id": "codeql", "benchmark_pairs": comparison["pairs"],
227
+ "confusion": counts})
228
  image = output_dir / f"{domain}-tradeoff.svg"
229
  svg(domain, curves_by_domain[domain], image)
230
  sections += [f"## {title}", "", f"[Public pairs](https://huggingface.co/datasets/perchscan/{link})", "",
231
  f"![{title} recall versus false alerts](assets/{domain}-tradeoff.svg)", "",
232
  f"### Public — {public[0]['benchmark_pairs']:,} pairs", "",
233
+ results_table(public), ""]
234
+ if domain in ("bug", "security"):
235
+ sections += [f"CodeQL scored {comparison['pairs']:,} of the {public[0]['benchmark_pairs']:,} public pairs; other models scored all pairs. "
236
+ "Its [method decisions](codeql-comparison/) and [evaluation protocol](CODEQL.md) are available here.", ""]
237
+ sections += [f"### Private — {private[0]['benchmark_pairs']:,} pairs", "",
238
  results_table(private), ""]
239
  return "\n".join(sections)
240
 
 
245
  parser.add_argument("--check", action="store_true", help="Check generated card and SVGs without writing")
246
  args = parser.parse_args()
247
  results = lines(ROOT / "results-current.jsonl")
248
+ codeql_results = json.loads((ROOT / "codeql-comparison" / "results.json").read_text())
249
  curves_by_domain = {}
250
  for domain in ("bug", "security", "lint"):
251
  labels = labels_for(domain, dataset(domain, args.dataset_root))
 
269
  end += len(end_marker)
270
  if args.check:
271
  with TemporaryDirectory() as temporary:
272
+ content = render_sections(results, curves_by_domain, Path(temporary), codeql_results)
273
  for domain in DATASET_URLS:
274
  name = f"{domain}-tradeoff.svg"
275
  if (Path(temporary) / name).read_bytes() != (ROOT / "assets" / name).read_bytes():
276
  raise SystemExit(f"assets/{name} is not up to date; run python3 tradeoff.py")
277
  else:
278
+ content = render_sections(results, curves_by_domain, ROOT / "assets", codeql_results)
279
  updated = (original[:start].rstrip("\n") + "\n\n" + start_marker + "\n\n" + content
280
  + "\n" + end_marker + "\n\n" + original[end:].lstrip("\n"))
281
  if args.check and original != updated: