From 60a875372a991e592cb28c3419d41106f343a56f Mon Sep 17 00:00:00 2001 From: Branimir Georgiev <66906831+braboj@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:51:42 +0200 Subject: [PATCH 1/2] feat(efficacy): refuse a round registered after its first trial (#14) The report refuses a round-5 run whose registration was last committed after the first trial started, by committer date, or carries uncommitted changes. A self-test plants both orders, an uncommitted registration, a changed one, and a root with no run record. Closes #14 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DpT5xPB8YTAMW2Msp4aPTX --- docs/architecture/08-crosscutting-concepts.md | 5 + .../journeys/prepare/register-a-hypothesis.md | 2 +- tests/efficacy/report.py | 101 +++++++++++++++++- 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/docs/architecture/08-crosscutting-concepts.md b/docs/architecture/08-crosscutting-concepts.md index d2863f0..bfbb06d 100644 --- a/docs/architecture/08-crosscutting-concepts.md +++ b/docs/architecture/08-crosscutting-concepts.md @@ -14,6 +14,11 @@ The question, the metrics and the rule for reading a result are written down before any trial runs. Nobody can then pick the metric or the threshold that makes the templates look good after seeing the numbers. +From round 5 on, the report holds a round to that order. It refuses a +round whose registration under `docs/rounds/` was last committed after the +round's first trial started, by the committer date, or has changes not yet +committed. + | Setting | Value | Why | |---|---|---| | Unit compared | The difference between two arms' trials in the same block: `full-1` minus `none-1` | The arms in a block meet the same model on the same day | diff --git a/docs/journeys/prepare/register-a-hypothesis.md b/docs/journeys/prepare/register-a-hypothesis.md index 8ac04fd..b428c6e 100644 --- a/docs/journeys/prepare/register-a-hypothesis.md +++ b/docs/journeys/prepare/register-a-hypothesis.md @@ -32,7 +32,7 @@ Assumptions: | # | Finding | Status | | - | ------- | ------ | -| 1 | Nothing in the code checks that a round's hypothesis was committed before its first trial. The order rests on the registration's date line and git history | Open, #14 | +| 1 | Nothing in the code checked that a round's hypothesis was committed before its first trial. The report now refuses a round whose registration was last committed after its first trial started, or has uncommitted changes | Settled in [ch. 8.1.1](../../architecture/08-crosscutting-concepts.md) | | 2 | A hypothesis decides a record in another repository, such as ADR-058 in `solid-ai-templates`. The registration names it, and the record cites the report | Settled in [round 5's registration](../../rounds/round-5.md) | | 3 | A hypothesis on agreement across trials has one value per arm, so no interval. Its result is descriptive | Settled in [round 4's registration, 12.1](../../rounds/round-4.md) | | 4 | Once a round's trial has run, its section may not change | Settled in [round 5's registration, 13.4](../../rounds/round-5.md) | diff --git a/tests/efficacy/report.py b/tests/efficacy/report.py index 5b49cfb..71f92dc 100644 --- a/tests/efficacy/report.py +++ b/tests/efficacy/report.py @@ -36,12 +36,18 @@ from generate_arm import GENERATED, record_path # noqa: E402 from harness import (ARMS, ARMS_DIR, K_CEILING, K_PRIMARY, # noqa: E402 ROUND5_ARMS, ROUND5_K, SCORABLE, TEMPLATES_ENV, VOIDING, - TrialError, canonical, k_ceiling, order, reach, + TrialError, canonical, git, k_ceiling, order, reach, read_transcripts, scoring_area, split_name, templates_root, trial_name) from harness import name_of as trial_of # noqa: E402 HERE = os.path.dirname(os.path.abspath(__file__)) +REPOSITORY = os.path.dirname(os.path.dirname(HERE)) + +# Round 5's registration, relative to this repository. Its hypotheses bind +# only if they were committed before its first trial ran and left unchanged +# after, so a registration last committed later reads the results first. +ROUND5_REGISTRATION = "docs/rounds/round-5.md" # A round's report is its record, kept beside the templates it measured: # under the templates source's docs/audits/. A report written to any such @@ -1038,6 +1044,31 @@ def started(record): return moment.timestamp() +def registration_problem(root, registration, repository=REPOSITORY): + """Why the round's registration does not predate its first trial, or + None when it was committed before that trial and not changed since.""" + first = min(filter(None, map(started, run_records(root))), default=None) + if first is None: + return "no run record under %s says when the first trial ran" % root + if git(repository, "status", "--porcelain", "--", registration): + return "%s has changes that are not committed" % registration + committed = git(repository, "log", "-1", "--format=%cI", "--", + registration) + if not committed: + return "%s is not committed" % registration + + # The committer date, not the author date: a registration counts from when + # it landed, so one written before the first trial but landed after it is + # refused. + landed = datetime.datetime.fromisoformat(committed) + if landed.timestamp() > first: + return ("%s was last committed at %s, after the first trial started " + "at %s" % (registration, committed, + datetime.datetime.fromtimestamp(first) + .isoformat(timespec="seconds"))) + return None + + def reaches(root): """Every scorable trial's transcript scan, as name and hits. @@ -2624,6 +2655,61 @@ def lost_checks(): and "no run record" in unrecorded_row[0]["reason"])] +def registration_checks(): + """A round is refused when its registration was committed after its + first trial, changed and not committed, or never committed.""" + scratch = os.path.join(tempfile.gettempdir(), + "efficacy-report-registration-self-test") + shutil.rmtree(scratch, ignore_errors=True) + repository = os.path.join(scratch, "repository") + os.makedirs(os.path.join(repository, "docs")) + registration = "docs/round.md" + path = os.path.join(repository, *registration.split("/")) + git(repository, "init", "-q") + + def plant_run(name, moment): + root = os.path.join(scratch, name) + os.makedirs(root) + with io.open(os.path.join(root, "run-planted.json"), "w", + encoding="utf-8") as handle: + json.dump({"trials": [{"arm": "none", "trial": 1, + "outcome": "completed", + "started_at": moment.isoformat( + timespec="seconds")}]}, handle) + return root + + def problem(root): + return registration_problem(root, registration, repository) + + # One run that started an hour before the commit, one an hour after it. + now = datetime.datetime.now() + before = plant_run("before", now - datetime.timedelta(hours=1)) + after = plant_run("after", now + datetime.timedelta(hours=1)) + with io.open(path, "w", encoding="utf-8") as handle: + handle.write("# Round\n") + uncommitted = problem(after) + git(repository, "add", registration) + git(repository, "-c", "user.name=self-test", + "-c", "user.email=self-test@example.invalid", + "commit", "-q", "-m", "register the round") + late, early = problem(before), problem(after) + with io.open(path, "a", encoding="utf-8") as handle: + handle.write("A hypothesis added after the first trial.\n") + changed = problem(after) + unrecorded = problem(os.path.join(scratch, "repository")) + shutil.rmtree(scratch, ignore_errors=True) + return [("a registration committed before the first trial passes", + early is None), + ("one committed after the first trial is refused", + late is not None and "after the first trial" in late), + ("one never committed is refused", + uncommitted is not None and "not committed" in uncommitted), + ("one changed and not committed is refused", + changed is not None and "not committed" in changed), + ("a root with no run record is refused", + unrecorded is not None and "no run record" in unrecorded)] + + def rescan_checks(): """A record scanned under an earlier rule is read again from its transcript.""" @@ -3405,6 +3491,7 @@ def self_test(seed): checks.extend((label, ok, ok) for label, ok in reach_checks()) checks.extend((label, ok, ok) for label, ok in lost_checks()) checks.extend((label, ok, ok) for label, ok in rescan_checks()) + checks.extend((label, ok, ok) for label, ok in registration_checks()) for label, ok, got in checks: print(" %-52s %s" % (label, "ok" if ok else "FAILED, got %r" % (got,))) @@ -3458,6 +3545,18 @@ def main(argv): print("refused: %s" % problem) return 2 + # A hypothesis registered or changed after the round's first trial could + # have been written to fit what that trial showed, so the round is refused + # rather than read against it. + if is_round5(trials): + try: + problem = registration_problem(options.root, ROUND5_REGISTRATION) + except TrialError as error: + problem = str(error) + if problem: + print("refused: %s" % problem) + return 2 + # A trial that read past its workspace measures what it read, not its # arm; the harness voids one its own scan catches, and this re-scan, under # the current rule, leaves out any it missed. From 8c16a740a93ddf236693475243102beb2b9af0c4 Mon Sep 17 00:00:00 2001 From: Branimir Georgiev <66906831+braboj@users.noreply.github.com> Date: Wed, 28 Oct 2026 10:03:53 +0200 Subject: [PATCH 2/2] fix(efficacy): read a registration where it landed on main, and order trials by UTC - The check reads main's first-parent history, so a merge counts at the merge, and refuses a registration that differs from main's copy - Trials record started_at with the machine's UTC offset; the check refuses a start with none rather than read it in the reporter's zone - The self-test plants a merge after the trial, an unmerged branch, a UTC trial against a +02:00 commit and a zoneless start Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DpT5xPB8YTAMW2Msp4aPTX --- docs/architecture/08-crosscutting-concepts.md | 15 +- .../journeys/prepare/register-a-hypothesis.md | 2 +- tests/efficacy/harness.py | 20 ++- tests/efficacy/report.py | 137 ++++++++++++------ tests/efficacy/reuse.py | 8 +- 5 files changed, 122 insertions(+), 60 deletions(-) diff --git a/docs/architecture/08-crosscutting-concepts.md b/docs/architecture/08-crosscutting-concepts.md index bfbb06d..ccce6be 100644 --- a/docs/architecture/08-crosscutting-concepts.md +++ b/docs/architecture/08-crosscutting-concepts.md @@ -14,10 +14,17 @@ The question, the metrics and the rule for reading a result are written down before any trial runs. Nobody can then pick the metric or the threshold that makes the templates look good after seeing the numbers. -From round 5 on, the report holds a round to that order. It refuses a -round whose registration under `docs/rounds/` was last committed after the -round's first trial started, by the committer date, or has changes not yet -committed. +From round 5 on, the report holds a round to that order. It refuses a round +whose registration under `docs/rounds/`: + +- landed on `main` after the round's first trial started, read on `main`'s + first-parent line so a merge counts at the merge +- differs from `main`'s copy, or has changes not yet committed + +Trials record their start with its UTC offset, so the order holds on any +machine; a start with no offset is refused rather than guessed. A +fast-forward pushed from a clone keeps its branch commit's date, so +registrations land through a pull request's squash or rebase merge. | Setting | Value | Why | |---|---|---| diff --git a/docs/journeys/prepare/register-a-hypothesis.md b/docs/journeys/prepare/register-a-hypothesis.md index b428c6e..5b1bada 100644 --- a/docs/journeys/prepare/register-a-hypothesis.md +++ b/docs/journeys/prepare/register-a-hypothesis.md @@ -32,7 +32,7 @@ Assumptions: | # | Finding | Status | | - | ------- | ------ | -| 1 | Nothing in the code checked that a round's hypothesis was committed before its first trial. The report now refuses a round whose registration was last committed after its first trial started, or has uncommitted changes | Settled in [ch. 8.1.1](../../architecture/08-crosscutting-concepts.md) | +| 1 | Nothing in the code checked that a round's hypothesis was committed before its first trial. The report now refuses a round whose registration landed on `main` after its first trial started, or differs from `main`'s copy | Settled in [ch. 8.1.1](../../architecture/08-crosscutting-concepts.md) | | 2 | A hypothesis decides a record in another repository, such as ADR-058 in `solid-ai-templates`. The registration names it, and the record cites the report | Settled in [round 5's registration](../../rounds/round-5.md) | | 3 | A hypothesis on agreement across trials has one value per arm, so no interval. Its result is descriptive | Settled in [round 4's registration, 12.1](../../rounds/round-4.md) | | 4 | Once a round's trial has run, its section may not change | Settled in [round 5's registration, 13.4](../../rounds/round-5.md) | diff --git a/tests/efficacy/harness.py b/tests/efficacy/harness.py index 63e7b48..bb2dea2 100644 --- a/tests/efficacy/harness.py +++ b/tests/efficacy/harness.py @@ -441,10 +441,20 @@ def assert_no_ambient_context(workspace, home): % ", ".join(found)) -def git(workspace, *args): +def now(): + """The time now, with this machine's UTC offset.""" + + # A record is read on whatever machine writes the report, so a time + # without its offset would be read in that machine's zone, and could + # order wrongly against a commit's date. + return datetime.datetime.now().astimezone() + + +def git(workspace, *args, env=None): """Run git in the workspace, raising on a non-zero status.""" proc = subprocess.run(["git", "-C", workspace] + list(args), - capture_output=True, text=True, encoding="utf-8") + capture_output=True, text=True, encoding="utf-8", + env=env) if proc.returncode != 0: raise TrialError("git %s failed in %s: %s" % (" ".join(args), workspace, proc.stderr.strip())) @@ -1511,7 +1521,7 @@ def run_agent(workspace, name, prompt, record, root, home, options): "environment_removed": {"names": inherited_names(os.environ), "path": interpreter_directories(os.environ)}, "templates_tree": lib.tree_id(), - "started_at": datetime.datetime.now().isoformat(timespec="seconds"), + "started_at": now().isoformat(timespec="seconds"), }) if options.dry_run: record["outcome"] = "dry-run" @@ -1707,7 +1717,7 @@ def in_flight(arm, trial): when.""" return {"arm": arm, "trial": trial, "outcome": "running", "harness_pid": os.getpid(), - "started_at": datetime.datetime.now().isoformat(timespec="seconds")} + "started_at": now().isoformat(timespec="seconds")} def harness_alive(pid, table): @@ -3112,7 +3122,7 @@ def main(argv): return 1 print("the agent sees the skills arm's %d skills" % len(seen)) - started_at = datetime.datetime.now() + started_at = now() run_file = os.path.join( work, "run-%s.json" % started_at.strftime("%Y-%m-%dT%H-%M-%S")) records = [] diff --git a/tests/efficacy/report.py b/tests/efficacy/report.py index 71f92dc..5aba73b 100644 --- a/tests/efficacy/report.py +++ b/tests/efficacy/report.py @@ -45,10 +45,13 @@ REPOSITORY = os.path.dirname(os.path.dirname(HERE)) # Round 5's registration, relative to this repository. Its hypotheses bind -# only if they were committed before its first trial ran and left unchanged -# after, so a registration last committed later reads the results first. +# only if they landed on the main branch before its first trial ran and stayed +# unchanged after, so a registration that landed later read the results first. ROUND5_REGISTRATION = "docs/rounds/round-5.md" +# A registration counts once it is on this branch, not on a branch of its own. +REGISTRATION_BRANCH = "main" + # A round's report is its record, kept beside the templates it measured: # under the templates source's docs/audits/. A report written to any such # directory needs the round archived as it stands; anywhere else it is a @@ -1046,26 +1049,46 @@ def started(record): def registration_problem(root, registration, repository=REPOSITORY): """Why the round's registration does not predate its first trial, or - None when it was committed before that trial and not changed since.""" - first = min(filter(None, map(started, run_records(root))), default=None) - if first is None: + None when it landed on the main branch before that trial and is + unchanged since.""" + moments = [] + for record in run_records(root): + try: + moment = datetime.datetime.fromisoformat(record["started_at"]) + except (KeyError, TypeError, ValueError): + continue + + # A harness from before offsets were recorded wrote local time with no + # zone, which no machine can order against a commit's date for sure. + if moment.tzinfo is None: + return ("trial %s started at %s, which carries no UTC offset, so " + "it cannot be ordered against %s" + % (trial_of(record), record["started_at"], registration)) + moments.append(moment) + if not moments: return "no run record under %s says when the first trial ran" % root + first = min(moments) if git(repository, "status", "--porcelain", "--", registration): return "%s has changes that are not committed" % registration - committed = git(repository, "log", "-1", "--format=%cI", "--", - registration) - if not committed: - return "%s is not committed" % registration - - # The committer date, not the author date: a registration counts from when - # it landed, so one written before the first trial but landed after it is - # refused. - landed = datetime.datetime.fromisoformat(committed) - if landed.timestamp() > first: - return ("%s was last committed at %s, after the first trial started " - "at %s" % (registration, committed, - datetime.datetime.fromtimestamp(first) - .isoformat(timespec="seconds"))) + if git(repository, "diff", "--name-only", REGISTRATION_BRANCH, "--", + registration): + return ("%s differs from %s's copy, so it has not landed; merge it " + "or pull %s" % (registration, REGISTRATION_BRANCH, + REGISTRATION_BRANCH)) + + # The first-parent line is the main branch's own history, so a merge that + # brought the registration in is read at the merge, not at the branch + # commit beneath it. GitHub's squash and rebase merges stamp the commit + # with the merge time; a fast-forward pushed from a clone keeps the + # branch commit's date, which this cannot see past. + landed = git(repository, "log", REGISTRATION_BRANCH, "--first-parent", + "-1", "--format=%cI", "--", registration) + if not landed: + return "%s is not on %s" % (registration, REGISTRATION_BRANCH) + if datetime.datetime.fromisoformat(landed) > first: + return ("%s landed on %s at %s, after the first trial started at %s" + % (registration, REGISTRATION_BRANCH, landed, + first.isoformat())) return None @@ -2656,8 +2679,9 @@ def lost_checks(): def registration_checks(): - """A round is refused when its registration was committed after its - first trial, changed and not committed, or never committed.""" + """A round is refused when its registration landed on the main branch + after its first trial, has not landed, is changed and not committed, or + when a trial's start carries no UTC offset.""" scratch = os.path.join(tempfile.gettempdir(), "efficacy-report-registration-self-test") shutil.rmtree(scratch, ignore_errors=True) @@ -2665,7 +2689,16 @@ def registration_checks(): os.makedirs(os.path.join(repository, "docs")) registration = "docs/round.md" path = os.path.join(repository, *registration.split("/")) - git(repository, "init", "-q") + identity = ("-c", "user.name=self-test", + "-c", "user.email=self-test@example.invalid") + + def commit(when, *args): + env = dict(os.environ, GIT_AUTHOR_DATE=when, GIT_COMMITTER_DATE=when) + git(repository, *(identity + args), env=env) + + def write(text): + with io.open(path, "a", encoding="utf-8") as handle: + handle.write(text) def plant_run(name, moment): root = os.path.join(scratch, name) @@ -2674,40 +2707,52 @@ def plant_run(name, moment): encoding="utf-8") as handle: json.dump({"trials": [{"arm": "none", "trial": 1, "outcome": "completed", - "started_at": moment.isoformat( - timespec="seconds")}]}, handle) + "started_at": moment}]}, handle) return root def problem(root): return registration_problem(root, registration, repository) - # One run that started an hour before the commit, one an hour after it. - now = datetime.datetime.now() - before = plant_run("before", now - datetime.timedelta(hours=1)) - after = plant_run("after", now + datetime.timedelta(hours=1)) - with io.open(path, "w", encoding="utf-8") as handle: - handle.write("# Round\n") - uncommitted = problem(after) + # The registration lands at 10:00 UTC, written in a +02:00 zone. A trial + # at 10:30 UTC follows it, though its clock reads earlier than 12:00. + git(repository, "init", "-q", "-b", REGISTRATION_BRANCH) + write("# Round\n") git(repository, "add", registration) - git(repository, "-c", "user.name=self-test", - "-c", "user.email=self-test@example.invalid", - "commit", "-q", "-m", "register the round") - late, early = problem(before), problem(after) - with io.open(path, "a", encoding="utf-8") as handle: - handle.write("A hypothesis added after the first trial.\n") + commit("2026-10-01T12:00:00+02:00", "commit", "-q", "-m", "register") + after = plant_run("after", "2026-10-01T10:30:00+00:00") + before = plant_run("before", "2026-10-01T09:30:00+00:00") + naive = plant_run("naive", "2026-10-01T10:30:00") + early, late, zoneless = problem(after), problem(before), problem(naive) + unrecorded = problem(repository) + + # An amendment committed on a branch at 11:00, before a trial at 12:00, + # and merged into the main branch at 13:00, after it. + merged = plant_run("merged", "2026-10-01T12:00:00+00:00") + git(repository, "switch", "-q", "-c", "amend") + write("A hypothesis.\n") + commit("2026-10-01T11:00:00+00:00", "commit", "-q", "-am", "amend") + unlanded = problem(merged) + git(repository, "switch", "-q", REGISTRATION_BRANCH) + commit("2026-10-01T13:00:00+00:00", "merge", "-q", "--no-ff", "amend", + "-m", "merge the amendment") + merged_late = problem(merged) + write("A hypothesis added after the first trial.\n") changed = problem(after) - unrecorded = problem(os.path.join(scratch, "repository")) shutil.rmtree(scratch, ignore_errors=True) - return [("a registration committed before the first trial passes", - early is None), - ("one committed after the first trial is refused", + return [("a registration landed before the first trial passes, across " + "zones", early is None), + ("one landed after the first trial is refused", late is not None and "after the first trial" in late), - ("one never committed is refused", - uncommitted is not None and "not committed" in uncommitted), - ("one changed and not committed is refused", - changed is not None and "not committed" in changed), + ("a trial start with no UTC offset is refused", + zoneless is not None and "no UTC offset" in zoneless), ("a root with no run record is refused", - unrecorded is not None and "no run record" in unrecorded)] + unrecorded is not None and "no run record" in unrecorded), + ("an amendment on a branch of its own is refused", + unlanded is not None and "has not landed" in unlanded), + ("one merged after the first trial is read at the merge", + merged_late is not None and "T13:00:00" in merged_late), + ("one changed and not committed is refused", + changed is not None and "not committed" in changed)] def rescan_checks(): diff --git a/tests/efficacy/reuse.py b/tests/efficacy/reuse.py index 998a8b1..9a1d19f 100644 --- a/tests/efficacy/reuse.py +++ b/tests/efficacy/reuse.py @@ -25,9 +25,9 @@ import lib # noqa: E402 from harness import (ARMS, PROMPT, TrialError, arm_name, # noqa: E402 - assert_outside_repository, canonical, project_folder, - remove_tree, scorable_trials, scoring_area, spellings, - write_run) + assert_outside_repository, canonical, now, + project_folder, remove_tree, scorable_trials, + scoring_area, spellings, write_run) # The scoring area's per-trial readings, each a JSON file named for the # trial, that a reused trial brings with it. @@ -206,7 +206,7 @@ def reuse(source, target, arms): if labels: write_map(scoring_area(target), mapping) - started_at = datetime.datetime.now() + started_at = now() os.makedirs(target, exist_ok=True) run_file = os.path.join(target, "run-%s-reused.json" % started_at.strftime("%Y-%m-%dT%H-%M-%S"))