Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/architecture/08-crosscutting-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ 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/`:

- 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 |
|---|---|---|
| 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 |
Expand Down
2 changes: 1 addition & 1 deletion docs/journeys/prepare/register-a-hypothesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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) |
20 changes: 15 additions & 5 deletions tests/efficacy/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down
146 changes: 145 additions & 1 deletion tests/efficacy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@
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 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
Expand Down Expand Up @@ -1038,6 +1047,51 @@ 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 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
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


def reaches(root):
"""Every scorable trial's transcript scan, as name and hits.

Expand Down Expand Up @@ -2624,6 +2678,83 @@ def lost_checks():
and "no run record" in unrecorded_row[0]["reason"])]


def registration_checks():
"""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)
repository = os.path.join(scratch, "repository")
os.makedirs(os.path.join(repository, "docs"))
registration = "docs/round.md"
path = os.path.join(repository, *registration.split("/"))
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)
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}]}, handle)
return root

def problem(root):
return registration_problem(root, registration, repository)

# 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)
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)
shutil.rmtree(scratch, ignore_errors=True)
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),
("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),
("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():
"""A record scanned under an earlier rule is read again from its
transcript."""
Expand Down Expand Up @@ -3405,6 +3536,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,)))
Expand Down Expand Up @@ -3458,6 +3590,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.
Expand Down
8 changes: 4 additions & 4 deletions tests/efficacy/reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"))
Expand Down
Loading