diff --git a/.agents/skills/label-benchmark/SKILL.md b/.agents/skills/label-benchmark/SKILL.md index 307b3f0f8..fbf4a73b1 100644 --- a/.agents/skills/label-benchmark/SKILL.md +++ b/.agents/skills/label-benchmark/SKILL.md @@ -58,11 +58,22 @@ Read the terms before the first `units` listing: it writes task text. A canary o reported and changes nothing below: task ids and labels are not the data. Gated data, data its authors ask not to reshare, or records about real people (patients, clients): propose -`units.redistribute: false` in the benchmark's definition, as a ```diff block for the user. With it, proposed or already set, no task id goes anywhere: -not into `labels.json`, the report or a model. Skip both steps. Write dataset rules alone (no `tasks`), each from the -benchmark's own statement in its README, paper or dataset description: the one domain it defines the dataset as, or a -capability it says every task of the dataset is graded on. Never your reading of what a dataset is about. Such a rule -labels the dataset in every release the second command lists it in: the statement must hold for each. Then hand over. +`units.redistribute: false` in the benchmark's definition, as a ```diff block for the user. Where the upstream +repository itself publishes every task id (task files or folders, an id list, tracked at the pinned commit, not a +gated download), propose `units.public_ids` in the same diff: the path where it does. + +- With `public_ids`: both steps run and `labels.json` may name tasks, but a state holds only what the upstream + publishes openly: what its repository tracks at the pinned commit, or a file its README links that downloads with + no login and that the definition pins by `sha256`. Never a record fetched behind a gate or a credential. Apply the + diff in the checkout, then, before the proposal is shown, this must exit 0; it prints counts, never an id: + ```bash + PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY + ``` +- Without it, proposed or already set: no task id goes anywhere, not into `labels.json`, the report or a model. Skip + both steps. Write dataset rules alone (no `tasks`), each from the benchmark's own statement in its README, paper or + dataset description: the one domain it defines the dataset as, or a capability it says every task of the dataset is + graded on. Never your reading of what a dataset is about. Such a rule labels the dataset in every release the + second command lists it in: the statement must hold for each. Then hand over. ## The format @@ -74,7 +85,8 @@ labels the dataset in every release the second command lists it in: the statemen ]} ``` -- Under `units.redistribute: false`, dataset rules instead, never both: `{"dataset": "retail", "axes": ["Shopping"]}`. +- Under `units.redistribute: false` with no `units.public_ids`, dataset rules instead, never both: + `{"dataset": "retail", "axes": ["Shopping"]}`. - A rule selects the whole benchmark (no `dataset`), one dataset, or the listed `tasks` of one dataset. A task's axes are the union of its rules' `axes`, minus their `not`. No other key, no prefix, no pattern. - `dataset` is a dataset of the definition, never a cut of another (`subset_of`): name the dataset it is cut from. @@ -212,7 +224,8 @@ PYTHONPATH=REPO/app python3 -c 'import json; from nullius.standard.contract impo Then report in a few lines, in `WORK/report.md` and to the user: -- the terms read, and `units.redistribute` as proposed; calls and cost, every run counted; +- the terms read, `units.redistribute` and `units.public_ids` as proposed, and `public_ids.py`'s counts; calls and + cost, every run counted; - per rule: the step or statement that gave it, and for step 2 the models and how many pairs agreed; - per axis: tasks labelled, disagreements left unlabelled, conflicts with a rule kept; the option values left out; labels proposed outside `labels.AXES`, written nowhere. diff --git a/.agents/skills/label-benchmark/scripts/public_ids.py b/.agents/skills/label-benchmark/scripts/public_ids.py new file mode 100644 index 000000000..43d78d3b9 --- /dev/null +++ b/.agents/skills/label-benchmark/scripts/public_ids.py @@ -0,0 +1,135 @@ +"""Check every task id ENTRY/labels.json names, before the file is committed, for a benchmark whose data may not be +redistributed (``units.redistribute: false``). + + PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY + +Such a benchmark's labels may name tasks only under ``units.public_ids``, the path in the upstream repository where +it publishes the ids, and only ids that are, at each version a rule is ``checked`` at: +- listed by ``units`` for that dataset (the listing Nullius cached when the skill listed it); +- published: the upstream fetched at its pinned commit over HTTPS, with no credential, no user configuration and an + empty home (a private repository fails here), and the id found under that path as a tracked file or folder name + or a whole string value of a tracked ``.json`` or ``.jsonl`` file. Untracked files, a gated download among them, + prove nothing. +The file must also have no ``labels.check`` problem, and the definition on disk must be the one proposed. + +Prints counts, never an id. Exit 0: every id passes, or the benchmark's ids may be named anyway; 1: refused. +""" +import json +import os +import subprocess +import sys +import tempfile + +from nullius.leaderboard import labels +from nullius.standard.contract import definitions +from nullius.standard.runner import units + + +def refusals(document, versions, listed, published) -> list: + """Why the ids of ``document`` may not be named; [] when they may. ``versions``: the benchmark at each version; + ``listed``: {(version, dataset): ids or None}; ``published``: {version: ids}. Counts, never an id.""" + if not versions: + return ["the benchmark: no version of it loads from ENTRY"] + problems = list(labels.check(document, versions).problems) + if problems: + return [f"labels.check: {len(problems)} problems; run the hand-over check"] + unit = versions[0].get("units") or {} + if unit.get("redistribute") is not False: + return [] + rules = [r for r in document["labels"] if "tasks" in r] + if rules and not unit.get("public_ids"): + return ["units.public_ids: not set, so no task id may be named"] + out = [] + for v in sorted({v for r in rules for v in r["checked"]}): + for ds in sorted({r["dataset"] for r in rules if v in r["checked"]}): + ids = {t for r in rules if v in r["checked"] and r["dataset"] == ds for t in r["tasks"]} + there = listed.get((v, ds)) + if there is None: + out.append(f"{v} {ds}: no cached listing; list its units first") + continue + if ids - set(there): + out.append(f"{v} {ds}: {len(ids - set(there))} of {len(ids)} ids not listed") + if ids - published.get(v, set()): + out.append(f"{v} {ds}: {len(ids - published.get(v, set()))} of {len(ids)} ids not published under {unit['public_ids']}") + return out + + +def _strings(value): + if isinstance(value, str): + yield value + elif isinstance(value, dict): + for k, x in value.items(): + yield k + yield from _strings(x) + elif isinstance(value, list): + for x in value: + yield from _strings(x) + + +def published(repository, commit, path) -> set: + """Every name and JSON string the repository tracks under ``path`` at ``commit``, fetched with no credential.""" + if not repository.startswith("https://"): + sys.exit(f"{repository}: an https repository is needed, so that no credential is used") + with tempfile.TemporaryDirectory() as here, tempfile.TemporaryDirectory() as home: + env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "HOME": home, "XDG_CONFIG_HOME": home, + "GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": os.devnull, "GIT_TERMINAL_PROMPT": "0", + "GIT_ASKPASS": "true", "SSH_ASKPASS": "true", "GIT_LFS_SKIP_SMUDGE": "1"} + git = lambda *a: subprocess.run(["git", "-c", "credential.helper=", *a], cwd=here, env=env, + capture_output=True, timeout=900, check=True).stdout + git("init", "--quiet") + try: + git("fetch", "--quiet", "--depth", "1", "--no-recurse-submodules", repository, commit) + except subprocess.CalledProcessError: + sys.exit(f"{repository} at {commit}: not fetched without credentials, so not public") + entries = [e.split(b"\t", 1) for e in git("ls-tree", "-r", "-z", "FETCH_HEAD", "--", path).split(b"\0") if e] + files = [name.decode() for meta, name in entries if meta.split()[1] == b"blob"] + if not files: + sys.exit(f"units.public_ids: {path} tracks no file at {commit}") + found = {part for f in files for part in f.split("/")} + for f in files: + if f.endswith((".json", ".jsonl")): + text = git("show", f"FETCH_HEAD:{f}").decode("utf-8", errors="replace") + try: + docs = [json.loads(text)] if f.endswith(".json") else [json.loads(x) for x in text.splitlines() if x.strip()] + except ValueError: + continue + for doc in docs: + found.update(_strings(doc)) + return found + + +def main(): + if len(sys.argv) != 2: + sys.exit("usage: public_ids.py ENTRY") + entry = os.path.abspath(sys.argv[1]) + key = os.path.basename(entry) + versions = [b for b in definitions.load("benchmark", os.path.dirname(os.path.dirname(entry)), every=True)[0] if b["key"] == key] + with open(os.path.join(entry, "labels.json"), encoding="utf-8") as f: + document = json.load(f) + by = {definitions.version_identity(b): b for b in versions} + rules = [r for r in document.get("labels") or [] if isinstance(r, dict) and "tasks" in r] + unit = (versions[0].get("units") or {}) if versions else {} + listed, seen = {}, {} + if versions and not labels.check(document, versions).problems and unit.get("redistribute") is False and unit.get("public_ids"): + for v in {v for r in rules for v in r["checked"]}: + b = by[v] + for ds in {r["dataset"] for r in rules if v in r["checked"]}: + d = next(x for x in b["datasets"] if x["id"] == ds) + try: + with open(units.cache_path(b, d, units.option_values(b, ds)), encoding="utf-8") as f: + listed[v, ds] = [t["id"] for t in json.load(f)["tasks"]] + except (OSError, ValueError, KeyError, TypeError, units.Refused): + listed[v, ds] = None + where = (b["upstream"]["repository"], b["upstream"]["tested"], unit["public_ids"]) + seen[v] = published(*where) + out = refusals(document, versions, listed, seen) + ids = sum(len(r["tasks"]) for r in rules if isinstance(r.get("tasks"), list)) + if not out and unit.get("redistribute") is not False: + print("units.redistribute is not false in ENTRY: its ids may be named; apply a proposed change first") + else: + print("\n".join(out) or f"{ids} named ids: every one listed and published") + sys.exit(1 if out else 0) + + +if __name__ == "__main__": + main() diff --git a/app/nullius/leaderboard/labels.py b/app/nullius/leaderboard/labels.py index 4ceb6cbc4..0fb6dcdb4 100644 --- a/app/nullius/leaderboard/labels.py +++ b/app/nullius/leaderboard/labels.py @@ -95,7 +95,7 @@ def _rule(rule, shapes, task_ids): if "tasks" not in rule: return "checked: only with tasks" if "checked" in rule else Rule(frozenset(rule.get("axes", [])), frozenset(rule.get("not", [])), dataset) if not task_ids: - return "tasks: this benchmark's ids may not be redistributed (units.redistribute); dataset rules only" + return "tasks: this benchmark's ids may not be redistributed (units.redistribute, no units.public_ids); dataset rules only" if not _names(rule["tasks"]): return "tasks: a list of task ids, never empty" if not dataset: @@ -120,7 +120,8 @@ def check(document, versions) -> Labels: for b in versions: cuts = {d["id"]: d["subset_of"] for d in b.get("datasets") or [] if d.get("subset_of")} shapes[definitions.version_identity(b)] = ({d["id"] for d in b.get("datasets") or []} - set(cuts), cuts) - task_ids = all((b.get("units") or {}).get("redistribute") is not False for b in versions) + task_ids = all((b.get("units") or {}).get("redistribute") is not False or (b.get("units") or {}).get("public_ids") + for b in versions) rules, problems = [], [] for i, rule in enumerate(document["labels"]): got = _rule(rule, shapes, task_ids) diff --git a/app/nullius/standard/contract/definitions.py b/app/nullius/standard/contract/definitions.py index 900b95acb..bdff8ea59 100644 --- a/app/nullius/standard/contract/definitions.py +++ b/app/nullius/standard/contract/definitions.py @@ -1742,6 +1742,11 @@ def problems(d: dict, kind: str) -> List[str]: bad.append("units: {noun, nouns}") if "redistribute" in u and not isinstance(u["redistribute"], bool): bad.append("units.redistribute: false when the data may not be redistributed") + if "public_ids" in u: + if not (isinstance(u["public_ids"], str) and _RELATIVE.match(u["public_ids"])): + bad.append("units.public_ids: the path in the upstream repository where it publishes the task ids") + elif u.get("redistribute") is not False or not (d.get("upstream") or {}).get("repository"): + bad.append("units.public_ids: only with units.redistribute: false and an upstream repository") cats = u.get("categories", {}) if not isinstance(cats, dict) or not all( isinstance(c, dict) and set(c) <= {"label", "names"} and isinstance(c.get("label", ""), str) diff --git a/app/tests/test_leaderboard_labels.py b/app/tests/test_leaderboard_labels.py index cddc57f2d..26c97be50 100644 --- a/app/tests/test_leaderboard_labels.py +++ b/app/tests/test_leaderboard_labels.py @@ -67,6 +67,35 @@ def test_ids_that_may_not_ship_get_dataset_rules_only(self): closed = [dict(b, units=dict(b["units"], redistribute=False)) for b in BENCH] got = labels.check({"schema": 1, "labels": RULES}, closed) self.assertEqual((got.rules, len(got.problems)), (GOOD.rules[:2], 2)) + public = [dict(b, units=dict(b["units"], public_ids="tasks")) for b in closed] + self.assertEqual(labels.check({"schema": 1, "labels": RULES}, public), GOOD) + one = [public[0], closed[1]] # a version without it still names none + self.assertEqual(len(labels.check({"schema": 1, "labels": RULES}, one).problems), 2) + + def test_the_label_skill_names_only_ids_listed_and_published(self): + """``public_ids.py``'s verdict, the fetch aside: every named id listed and published, or a refusal that + names none of them.""" + import importlib.util + path = os.path.join(os.path.dirname(__file__), "..", "..", ".agents", "skills", "label-benchmark", "scripts", "public_ids.py") + if not os.path.isfile(path): + self.skipTest("no label skill in this checkout") + spec = importlib.util.spec_from_file_location("public_ids", path) + script = importlib.util.module_from_spec(spec) + spec.loader.exec_module(script) + public = [dict(b, units=dict(b["units"], redistribute=False, public_ids="tasks")) for b in BENCH] + doc = {"schema": 1, "labels": RULES} + listed, seen = {("v1", "retail"): ["a", "b", "c"]}, {"v1": {"a", "b", "README.md"}} + self.assertEqual(script.refusals(doc, public, listed, seen), []) + self.assertEqual(script.refusals(doc, BENCH, {}, {}), []) # ids that may ship need nothing + refused = [script.refusals(doc, public, listed, {"v1": {"a"}}), # b unpublished + script.refusals(doc, public, {("v1", "retail"): ["a"]}, seen), # b unlisted + script.refusals(doc, public, {("v1", "retail"): None}, seen), + script.refusals(doc, [dict(b, units=dict(b["units"], redistribute=False)) for b in BENCH], listed, seen), + script.refusals({"schema": 1, "labels": [dict(RULES[2], tasks="ab")]}, public, listed, seen), + script.refusals(doc, [], listed, seen)] + for got in refused: + self.assertTrue(got) + self.assertFalse(any(f"'{t}'" in g or f" {t} " in g for g in got for t in "ab"), got) def test_a_file_that_does_not_read_labels_nothing(self): import tempfile diff --git a/app/tests/test_standard_controls.py b/app/tests/test_standard_controls.py index 15d12060d..9db96271a 100644 --- a/app/tests/test_standard_controls.py +++ b/app/tests/test_standard_controls.py @@ -57,6 +57,17 @@ def test_units_that_may_not_be_redistributed_say_so_with_a_boolean(self): self.assertIn("units.redistribute: false when the data may not be redistributed", definitions.problems(dict(self.b, units=dict(units, redistribute="no")), "benchmark")) + def test_public_ids_name_a_path_of_a_repository_whose_data_may_not_be_redistributed(self): + b = dict(self.b, upstream={"repository": "https://example.org/up", "tested": "a" * 40, "license": "MIT"}) + named = lambda **u: definitions.problems(dict(b, units=dict(self.b["units"], **u)), "benchmark") + self.assertEqual(named(redistribute=False, public_ids="data/tasks.json"), []) + for path in ("", "/etc/tasks", "../tasks", ".", "./tasks", ":/", "a b", True): + self.assertIn("units.public_ids: the path in the upstream repository where it publishes the task ids", + named(redistribute=False, public_ids=path)) + held = "units.public_ids: only with units.redistribute: false and an upstream repository" + self.assertIn(held, named(public_ids="tasks")) + self.assertIn(held, definitions.problems(dict(self.b, units=dict(self.b["units"], redistribute=False, public_ids="tasks")), "benchmark")) + def test_an_agent_cannot_take_a_controls_name(self): a = definitions.get("agent", "fake", FIX) self.assertIn("key: nop is the word for a benchmark's control", definitions.problems(dict(a, key="nop"), "agent")) diff --git a/docs/standard.md b/docs/standard.md index 68f67b788..b8a26d287 100644 --- a/docs/standard.md +++ b/docs/standard.md @@ -464,6 +464,7 @@ An `answer` or `score` error that begins `EnvironmentSetupError: `, `VerifierErr | `limits.retries` | The upstream's own retries of a failed unit (0 to 9): a run's `--retries` when none is given | | `limits.scored_cuts` | The cuts after which an agent's unit is still scored: `time`, `calls`, `end` ([a unit cut at a limit](cli/run.md#a-unit-cut-at-a-limit)) | | `units.redistribute` | `false` when the data may not be redistributed: `cli prove` then records no unit id | +| `units.public_ids` | With `redistribute: false`: the path in the upstream repository where it publishes the unit ids. `labels.json` may then name units; the data stays unshared | | `units.categories` | `{FIELD: {label, names: {VALUE: name}}}`: how `describe`'s categories read on a listing; `--category` still takes the value | !!! note "Call the upstream, never copy it"