diff --git a/app/nullius/runs/cli.py b/app/nullius/runs/cli.py index ec5fe06a..d82549a9 100644 --- a/app/nullius/runs/cli.py +++ b/app/nullius/runs/cli.py @@ -89,6 +89,8 @@ def job_detail(job: parse.Job) -> dict: data = asdict(job) data.update(job_row(job)) data["harbor_label"] = job.harbor_label + data["mean_score"] = job.mean_score + data["mean_score_planned"] = job.mean_score_planned for trial, raw in zip(job.trials, data["trials"]): raw["outcome_label"] = trial.outcome_label raw["is_infra"] = trial.is_infra @@ -269,6 +271,10 @@ def _show(args) -> int: mix = " · ".join(f"{k} {v}" for k, v in row["counts"].items() if v) if mix: print(f" outcomes: {mix}") + if job.mean_score is not None: + planned = job.mean_score_planned + print(f" mean score {job.mean_score:.2f} over the trials scored" + + ("" if planned is None else f" · {planned:.2f} over the {max(job.n_planned, len(job.trials))} planned")) width = max((len(t.trial_name) for t in job.trials), default=0) for t in job.trials: line = f" {t.trial_name:<{width}} {t.outcome}" diff --git a/app/nullius/runs/parse.py b/app/nullius/runs/parse.py index bd6e21c1..16fabbfa 100644 --- a/app/nullius/runs/parse.py +++ b/app/nullius/runs/parse.py @@ -28,7 +28,7 @@ # The shape this module produces. A workspace caches parsed Jobs keyed on it, # so bump it when a Trial or Job field is added, renamed or means something # new — otherwise a cache written by the old parse is read back as current. -SCHEMA = "17" +SCHEMA = "18" # What a rate-limit record in `agent/gateway.log` looks like. The agent's SDK # retries a 429 below the harness, so a limit the run survived leaves nothing in result.json — @@ -317,6 +317,11 @@ class Job: # listing several): each one's {name, model, effort}, which split_agents # turns into one view per agent. [] for a job of one agent. agents: list = field(default_factory=list) + # What tells a Nullius standard run from another, as its records say it (identity_of): the benchmark, its + # version and options, the agent, its version and options, the model, the provider, the serving providers + # pinned and who served, the limits and the caps. A fact the job does not record is not a key. {} for + # every other job. + identity: dict = field(default_factory=dict) @property def agent_label(self) -> str: @@ -426,6 +431,17 @@ def mean_score(self): scored = [(t.score, t.n_parts or 1) for t in self.trials if t.score is not None] return sum(s * n for s, n in scored) / sum(n for _, n in scored) if scored else None + @property + def mean_score_planned(self): + """The mean score over every trial the run planned (``n_planned``), a + trial with no score - one that ended on an error, one never run - + counting 0; each trial contributes its own score regardless of part + counts. ``mean_score`` keeps its part weighting. None when no trial + was scored.""" + if self.mean_score is None: + return None + return sum(t.score for t in self.trials if t.score is not None) / max(self.n_planned, len(self.trials)) + @property def score_by_group(self) -> list: """The mean score by the field the benchmark breaks it down by - a @@ -786,6 +802,7 @@ def harbor_command(cfg: dict, env_type: str = "") -> str: # A launch carries only the name of a value filed under a name like these: it # is a credential, and the record is embedded in the builder's page. _SECRET_KEY = re.compile(r"(?:api[-_]?key|token|password|authorization|credential|secret)", re.I) +_TOKEN_COUNT_KEY = re.compile(r"^(?:(?:(?:max|min|num|n|total|input|output|prompt|completion|new)[-_])+tokens|token[-_](?:count|limit|budget))$", re.I) # What a recipe can say; any other key a config recorded is named, not dropped. _LAUNCH_TOP = {"job_name", "jobs_dir", "quiet", "debug", "agents", "datasets", "tasks", "retry", "n_concurrent_trials", "n_attempts", "timeout_multiplier", "environment", *_PHASE_MULTIPLIERS} @@ -800,7 +817,7 @@ def _scrub(values, at: str = "") -> tuple: kept, secret = {}, [] for key, value in (values if isinstance(values, dict) else {}).items(): name = f"{at}{key}" - if _SECRET_KEY.search(str(key)): + if _SECRET_KEY.search(str(key)) and not _TOKEN_COUNT_KEY.fullmatch(str(key)): secret.append(name) else: kept[str(key)], inner = _scrub_value(value, name) @@ -885,6 +902,76 @@ def _budget(b) -> dict: "shards": num(b.get("shards")) or 0, "shards_stopped": num(b.get("shards_stopped")) or 0} +def _options(values) -> dict: + """A run's options as a page may show them: strings redacted at any depth + (``_scrub``), and an option filed under a credential's name kept by its + name with its value replaced. Token counts are not credentials.""" + out = {} + for key, value in (values if isinstance(values, dict) else {}).items(): + hidden = _SECRET_KEY.search(str(key)) and not _TOKEN_COUNT_KEY.fullmatch(str(key)) + out[str(key)] = "[REDACTED]" if hidden else _scrub_value(value, str(key))[0] + return out + + +def _served(v) -> dict: + """Who served a job's calls (``result.json``'s ``served``): the calls by + serving provider, those that named none, and for each pinned model + whether the pin ``held`` (true, ``unknown``, or null with no call); {} + when the job records none.""" + if not isinstance(v, dict): + return {} + count = lambda n: n if isinstance(n, int) and not isinstance(n, bool) and n >= 0 else None + calls = {redact(str(k)): count(n) for k, n in v["calls"].items() if count(n) is not None} if isinstance(v.get("calls"), dict) else {} + held = {redact(str(m)): h for m, h in v["held"].items() if h is True or h is None or h == "unknown"} if isinstance(v.get("held"), dict) else {} + unnamed = count(v.get("unnamed")) or 0 + if not calls and not unnamed and not held: + return {} + return {"calls": calls, "unnamed": unnamed, **({"held": held} if held else {})} + + +def identity_of(cfg: dict, res: dict, agent_version: str = "") -> dict: + """What tells a Nullius standard run from another, from its ``config.json`` + (``cfg``) and its ``result.json`` (``res``): the benchmark, its version and + options; the agent as the run named it, the version its trials report + (``agent_version``) and its options, defaults included; the model; the + provider; the serving providers pinned by model (``served_by``) and who + served (``served``); and the limits in force: time limits by phase, turns, + model calls, attempts of each unit, retries, units at a time, and the + spending caps and resource constraints. A fact the job does not record is not a key, never an + empty value, and a control that calls no model has no provider. {} for a + job not of the standard. Every string is redacted.""" + std = cfg.get("standard") if isinstance(cfg, dict) and isinstance(cfg.get("standard"), dict) else {} + if not std: + return {} + word = lambda v: redact(v) if isinstance(v, str) else "" + number = lambda v: isinstance(v, (int, float)) and not isinstance(v, bool) and v > 0 + agents = cfg.get("agents") if isinstance(cfg.get("agents"), list) else [] + first = agents[0] if agents and isinstance(agents[0], dict) else {} + out = {"benchmark": word(std.get("benchmark")), "benchmark_version": word(std.get("benchmark_version")), + "benchmark_options": _options(std.get("benchmark_options")), + "agent": word(std.get("plugged")), "agent_version": word(agent_version), + "agent_options": _options(std.get("options")), "model": word(first.get("model_name"))} + # a control asks no model unless it has a judge or a simulated user; the provider it records is then a default + asks = out["model"] or std.get("judge") or std.get("simulator") or std.get("kind") != "control" + out["provider"] = word(std.get("provider")) if asks else "" + pins = std.get("served_by") if isinstance(std.get("served_by"), dict) else {} + out["served_by"] = {redact(str(m)): [word(s) for s in slugs if isinstance(s, str)] + for m, slugs in pins.items() if isinstance(slugs, list) and slugs} + out["served"] = _served(res.get("served") if isinstance(res, dict) else None) + timeouts = std.get("timeouts") if isinstance(std.get("timeouts"), dict) else {} + budget = _budget(res.get("budget") if isinstance(res, dict) else None) + whole = lambda v: v if number(v) and isinstance(v, int) else None + retries = std.get("retries") + limits = {"timeouts": {str(k): v for k, v in timeouts.items() if number(v)}, + "constraints": _options(std.get("constraints")), + "max_turns": whole(std.get("max_turns")), "max_calls": whole(std.get("max_calls")), + "repeat": whole(std.get("repeat")) if (whole(std.get("repeat")) or 0) > 1 else None, + "retries": retries if type(retries) is int and retries >= 0 else None, "concurrency": whole(cfg.get("n_concurrent_trials")), + "max_usd": budget.get("max_usd"), "unit_max_usd": budget.get("unit_max_usd")} + out["limits"] = {k: v for k, v in limits.items() if v is not None and v != {}} + return {k: v for k, v in out.items() if v not in ("", {})} + + def parse_job(job_dir: str, reuse=None, trials: bool = True) -> Job: """One job directory. ``reuse(trial_dir)``: a Trial already parsed from files that have not changed since (a workspace's cache, for a running @@ -965,6 +1052,7 @@ def parse_job(job_dir: str, reuse=None, trials: bool = True) -> Job: merged = std.get("merged_from") job.merged_from = [s["job"] for s in merged if isinstance(s, dict) and isinstance(s.get("job"), str) and s["job"]] if isinstance(merged, list) else [] job.budget = _budget(res.get("budget")) + job.identity = identity_of(cfg, res, job.agent_version) job.standard = bool(std) setup = std.get("setup") if isinstance(std.get("setup"), dict) else {} was = (std.get("benchmark_options") or {}).get("agent") if isinstance(std.get("benchmark_options"), dict) else None diff --git a/app/static/runs/board.css b/app/static/runs/board.css index df7f4bd9..8bbbe5dd 100644 --- a/app/static/runs/board.css +++ b/app/static/runs/board.css @@ -375,7 +375,7 @@ /* Run identity belongs on the full run overview, above its views. */ .run-identity{align-items:center;gap:10px} -.run-identity-card{display:flex;align-items:center;gap:12px;border:1px solid var(--border);border-radius:var(--radius);background:var(--surface);padding:9px 14px;min-width:0;max-width:100%;color:var(--text);line-height:1.5} +.run-identity-card{display:flex;align-items:center;gap:12px;border:1px solid var(--border);border-radius:var(--radius);background:var(--surface);padding:6px 14px;min-height:52px;min-width:0;max-width:100%;color:var(--text);line-height:1.35} .run-identity-card>div{min-width:0;overflow-wrap:anywhere} .run-identity-card .k{display:block;color:var(--text-dim);font-size:.75rem} .run-identity-card .v{display:block;font-weight:500} @@ -383,6 +383,18 @@ .run-identity-mark{width:32px;height:32px;border-radius:8px;background:var(--accent-soft);color:var(--accent);display:grid;place-items:center;font:500 15px/1 var(--mono);flex:none;padding:6px} .run-identity-mark:has(.agent-logo){padding:4px;background:color-mix(in srgb,var(--text) 8%,transparent);color:var(--text)} .run-identity-model{display:block;font-size:.8rem;color:var(--text-dim);overflow-wrap:anywhere} +/* A card with more to say opens it beneath itself, over the page; the row keeps its height. */ +.run-identity-more{position:relative;min-width:0;max-width:100%} +.run-identity-more>summary{cursor:pointer;list-style:none} +.run-identity-more>summary::-webkit-details-marker{display:none} +.run-identity-more[open]>summary{border-color:var(--text-faint)} +.run-identity-more .dd-chev{color:var(--text-dim)} +.run-identity-more[open] .dd-chev{transform:rotate(180deg)} +.run-identity-details{position:absolute;z-index:6;left:0;top:calc(100% + 6px);display:grid;grid-template-columns:auto minmax(0,auto);gap:4px 24px;margin:0;padding:10px 16px;width:max-content;max-width:min(36rem,calc(100vw - 32px));border:1px solid var(--border);border-radius:var(--radius);background:var(--surface-2);box-shadow:var(--shadow);font-size:14px;line-height:1.5} +.run-identity-details dt{color:var(--text-dim)} +.run-identity-details dd{margin:0;color:var(--text);overflow-wrap:anywhere} +/* on a narrow screen it opens in the page's flow and pushes the cards below it down */ +@media(max-width:640px){.run-identity{align-items:flex-start}.run-identity-more>summary{width:fit-content;max-width:100%}.run-identity-details{position:static;margin-top:6px;max-width:100%}} .run-runner-logo{width:32px;height:32px;flex:none;color:var(--text)} /* the Filtered score under the adjusted rate: a switch per kind of flag, and the rate without those tasks */ diff --git a/app/static/runs/board.js b/app/static/runs/board.js index 249a53d1..2872b5c3 100644 --- a/app/static/runs/board.js +++ b/app/static/runs/board.js @@ -66,9 +66,11 @@ facets.forEach(paint); sync(); } + // what lies open over the page: its own menus, and the header's cards above it + const opened = () => [...$$('.facet details[open], .pop[open]', page), ...$$('.run-identity-more[open]')]; // a legend row or segment sets the outcome; a cause outcome + cause + status; a flag line the flag. Pressed again: off. document.addEventListener('click', e => { - $$('.facet details[open], .pop[open]', page).forEach(d => { if (!d.contains(e.target)) d.open = false; }); + opened().forEach(d => { if (!d.contains(e.target)) d.open = false; }); const el = e.target.closest && e.target.closest('.fx'); if (!el || !page.contains(el)) return; e.preventDefault(); const ks = KEYS.filter(k => k in el.dataset), menu = el.closest('details'); @@ -137,7 +139,7 @@ // ---- Esc closes what is open, else clears the filters ---- document.addEventListener('keydown', e => { if (e.key !== 'Escape') return; - const open = $$('.facet details[open], .pop[open]', page); + const open = opened(); if (open.length) { open.forEach(d => { d.open = false; }); hide(); $('summary', open[0]).focus(); return; } if (tipFor) { hide(); return; } if (KEYS.some(k => st[k])) { KEYS.forEach(k => { st[k] = ''; }); apply(); light(null); } diff --git a/app/templates/runs/index.html b/app/templates/runs/index.html index 83e63f2f..51a2c7b1 100644 --- a/app/templates/runs/index.html +++ b/app/templates/runs/index.html @@ -42,6 +42,7 @@