The scheduler ran 'experiments run/adjudicate' but nothing registered the five experiments/*.json into the experiments table, so on a fresh DB the harness replayed over an empty set and the ledger stayed empty forever (owner hit this on first deploy). registry.register_cohort() registers every cohort JSON idempotently (skips already-registered, tolerates a malformed file); 'run' calls it at startup so a fresh deployment self-bootstraps with no manual register step. +test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
"""CLI: ``python -m research.experiments {register|run|adjudicate} [args]``.
|
|
|
|
Thin wrapper. Builds ONE EventStore (its Postgres connection is shared for the
|
|
experiment tables) and dispatches. Deferred imports so each subcommand only
|
|
pulls what it needs. NEVER run against the production DB from a test — the
|
|
harness's real verdict lands when the owner first schedules it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def _store():
|
|
from storage.event_store import EventStore
|
|
return EventStore(os.environ.get("WATCHER_EVENT_DB_PATH", "momentum"))
|
|
|
|
|
|
def main(argv=None) -> int:
|
|
argv = list(sys.argv[1:] if argv is None else argv)
|
|
if not argv:
|
|
print("usage: python -m research.experiments {register <json>|run|adjudicate}")
|
|
return 2
|
|
cmd, rest = argv[0], argv[1:]
|
|
|
|
if cmd == "register":
|
|
if not rest:
|
|
print("usage: python -m research.experiments register <json_path>")
|
|
return 2
|
|
from research.experiments import registry
|
|
store = _store()
|
|
try:
|
|
registry.apply_schema(store.con)
|
|
exp_id = registry.register(store.con, rest[0])
|
|
print(f"registered {exp_id}")
|
|
finally:
|
|
store.close()
|
|
return 0
|
|
|
|
if cmd == "run":
|
|
from research.experiments import registry, replay
|
|
store = _store()
|
|
try:
|
|
# self-bootstrap: register the declared cohort (idempotent) so a fresh
|
|
# DB replays the experiments instead of silently running over nothing.
|
|
newly = registry.register_cohort(store.con)
|
|
if newly:
|
|
print(f"registered cohort: {', '.join(newly)}")
|
|
n = replay.run(store)
|
|
print(f"experiments run: {n} new run rows")
|
|
finally:
|
|
store.close()
|
|
return 0
|
|
|
|
if cmd == "adjudicate":
|
|
from research.experiments import adjudicate
|
|
store = _store()
|
|
try:
|
|
verdicts = adjudicate.adjudicate(store)
|
|
for v in verdicts:
|
|
print(f"{v['experiment_id']}: {v['verdict']} (n={v['n']})")
|
|
finally:
|
|
store.close()
|
|
return 0
|
|
|
|
print(f"unknown command: {cmd}")
|
|
return 2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|