mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-17 12:09:27 +00:00
bench(valid): a training freeze may cap the history walk at the newest N first-parent commits
ordinary_history(limit=) walks only the newest commits; assemble.freeze(history_limit=) and --history-limit pass it through and the record carries it. The held-out benchmark passes none. Reason: trigger.dev's 7,109-commit walk runs for hours at the per-commit cost of the function and generated checks; the training freeze now walks its newest 1,500. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
6f9613329e
commit
1d1c87f63b
@@ -486,9 +486,15 @@ def _history_cache(git, cache_dir: Path | None):
|
||||
yield cached, handle
|
||||
|
||||
|
||||
def ordinary_history(git, head: str, *, cache_dir: Path | None = None) -> list[dict]:
|
||||
"""Read first-parent history, optionally reusing completed rows from this clone."""
|
||||
raw = git.run("log", "--first-parent", "--format=%H%x00%P%x00%ct%x00%an%x00%B%x1e", head)
|
||||
def ordinary_history(git, head: str, *, cache_dir: Path | None = None, limit: int | None = None) -> list[dict]:
|
||||
"""Read first-parent history, optionally reusing completed rows from this clone.
|
||||
|
||||
``limit`` walks only the newest ``limit`` first-parent commits (a training freeze's cap; the held-out
|
||||
benchmark passes none)."""
|
||||
if limit is not None and (type(limit) is not int or limit < 1):
|
||||
raise ValueError("history limit must be a positive integer")
|
||||
count = () if limit is None else ("-n", str(limit))
|
||||
raw = git.run("log", "--first-parent", *count, "--format=%H%x00%P%x00%ct%x00%an%x00%B%x1e", head)
|
||||
rows = []
|
||||
with _history_cache(git, cache_dir) as (cached, handle):
|
||||
for entry in raw.split("\x1e"):
|
||||
|
||||
@@ -54,13 +54,16 @@ def freeze(
|
||||
history_cache: Path | None = None,
|
||||
fix_index: dict | None = None,
|
||||
floor: int = extract.ORDINARY_FLOOR,
|
||||
history_limit: int | None = None,
|
||||
) -> dict:
|
||||
"""Freeze accepted positives with ``ratio`` ordinary pushes per fix commit from the same repositories.
|
||||
|
||||
``floor`` is the eligible-commit count a repository needs before its ordinary pushes are drawn. The
|
||||
held-out benchmark keeps the shipped 40; a training freeze may lower it (never below the ratio) so small
|
||||
repositories with 20 eligible commits still contribute, and the record carries the floor used.
|
||||
``history_cache`` reuses completed per-commit history rows across freezes of the same clone."""
|
||||
``history_cache`` reuses completed per-commit history rows across freezes of the same clone. ``history_limit``
|
||||
caps the walk at the newest first-parent commits for a training freeze and is recorded; the held-out benchmark
|
||||
passes none."""
|
||||
if type(ratio) is not int or ratio < 20:
|
||||
raise ValueError("ordinary ratio must be at least 20")
|
||||
if type(floor) is not int or floor < ratio:
|
||||
@@ -94,6 +97,8 @@ def freeze(
|
||||
head = (history_heads or {}).get(repo) or git.run("rev-parse", "HEAD").strip()
|
||||
heads[repo] = head
|
||||
history_options = {"cache_dir": history_cache} if history_cache is not None else {}
|
||||
if history_limit is not None:
|
||||
history_options["limit"] = history_limit
|
||||
history = sorted(extract.ordinary_history(git, head, **history_options), key=lambda row: row["head"])
|
||||
# Ratio is per positive CHANGE (a fix commit), not per accepted function. Several
|
||||
# accepted functions in one fix collapse to one vulnerability change below, so the
|
||||
@@ -156,6 +161,7 @@ def freeze(
|
||||
ordinary_exclusions=draws,
|
||||
negative_ratio=ratio,
|
||||
ordinary_floor=floor,
|
||||
history_limit=history_limit,
|
||||
label_check_counts={"confirmed": sum(len(v) for v in retained.values()), "unchecked": 0, "unclear": 0, "refactor": 0},
|
||||
)
|
||||
payloads = [
|
||||
@@ -181,6 +187,7 @@ def main(argv=None):
|
||||
parser.add_argument("--out", type=Path, required=True)
|
||||
parser.add_argument("--seed", type=int, default=0)
|
||||
parser.add_argument("--history-cache", type=Path, help="Directory for per-clone commit history caches")
|
||||
parser.add_argument("--history-limit", type=int, default=None, help="Training only: walk the newest N first-parent commits")
|
||||
args = parser.parse_args(argv)
|
||||
result = freeze(
|
||||
args.out,
|
||||
@@ -190,6 +197,7 @@ def main(argv=None):
|
||||
used=json.loads(args.used.read_text()),
|
||||
seed=args.seed,
|
||||
history_cache=args.history_cache,
|
||||
history_limit=args.history_limit,
|
||||
)
|
||||
print(json.dumps(result, sort_keys=True))
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user