Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e64b548
fix(judge): keep judgements by the job they judge, not by the workspace
harenome Nov 24, 2026
511a511
fix(judge): read the judgements workspaces kept without writing, and …
harenome Nov 24, 2026
5792790
docs(judge): name the job identity, the task and deleted-workspace st…
harenome Nov 24, 2026
86ffc3c
fix(settings): lay the move judgements row out on one line
harenome Nov 24, 2026
0e709f8
fix(judge): move a workspace's judgements only when each has one job,…
harenome Nov 24, 2026
2df7abd
fix(runs): decide a deleted launch's judgements from fresh files and …
harenome Nov 26, 2026
ce06dfe
fix(judge): keep a try's judgement under its attempt's name, told apa…
harenome Nov 25, 2026
44902ea
fix(execution): remove a deleted launch's judgements only once its ru…
harenome Nov 25, 2026
34d5948
fix(judge): copy a workspace's older judgements only to the one job t…
harenome Nov 25, 2026
be2d521
fix(workspaces): keep a workspace whose imports cannot all be listed
harenome Nov 25, 2026
22e8bcb
fix(execution): keep a deleted launch's judgements while a copy's ide…
harenome Nov 25, 2026
66d09a1
fix(judge): copy an older judgement on a save only when no job spelt …
harenome Nov 25, 2026
c7ff190
fix(judge): save a batch's judgements with the workspace asked and a …
harenome Nov 25, 2026
7b76023
fix(judge): show a try's judgement only when its start matches, where…
harenome Nov 25, 2026
5d06c72
fix(judge): keep a workspace's moved mark with its folder, and refuse…
harenome Nov 25, 2026
1575d34
fix(web): close a deleted workspace only once it is gone
harenome Nov 25, 2026
7b83c38
fix(judge): refuse a job with no identity yet before the judge is asked
harenome Nov 25, 2026
a180dad
fix(judge): give a job with no identity and no dataset no task key
harenome Nov 25, 2026
ed0c270
fix(workspaces): keep a workspace whose root is there but cannot be l…
harenome Nov 25, 2026
377c069
fix(execution): keep a deleted launch's judgements while a copy's fol…
harenome Nov 25, 2026
9fef503
fix(judge): copy no older judgement to a job whose identity cannot be…
harenome Nov 25, 2026
560d4b9
fix(judge): match every retried try by its start, and show its newest…
harenome Nov 25, 2026
976acab
fix(workspaces): refuse to delete a workspace holding judgements whil…
harenome Nov 25, 2026
00e7f34
fix(judge): keep a folded run's side judgement under its own shard's …
harenome Nov 26, 2026
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
83 changes: 65 additions & 18 deletions app/nullius/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

from nullius import hosts, ondisk, paths, prices as price_list, progress, providers, redact, secrets, settings, workspace
from nullius.judge import store as judgements
from nullius.runs import parse
from nullius.runs import parse, uid as job_uid
from nullius.harbor import source as harbor_source
from nullius.standard.backends import container
from nullius.standard.runner import payload as standard_payload
Expand Down Expand Up @@ -1830,34 +1830,73 @@ def deletable(names: List[str], root: Optional[str] = None) -> None:
_deletable(n, root)


def _run_deletion(name: str, home: str, root: Optional[str], holding: Callable, ends: dict) -> dict:
def _run_deletion(name: str, home: str, root: Optional[str], holding: Callable, ends: dict, final: bool = False) -> dict:
"""What deleting the run *name* removes. Its judgements are counted, the
older records its workspaces kept included, nothing written; *final* (the
delete itself) copies in first those older records one of its jobs alone
owns (`judgements.adopt_owned`), and names their folders (``judged``) to remove with it.
``uids``: its jobs' identities and where each came from (``Job.uid_source``),
whose judgements ``delete`` keeps when a copy is found elsewhere."""
path, rec = _deletable(name, root)
plan = rec.get("plan") or {}
# a run refused at the name check never made the host folder: one of that name there is not its own
host = hosts.parse(plan["host"]) if plan.get("host") and (rec.get("launched") or rec.get("step") not in ("connect", "name")) else None
held = []
held, olds = [], []
for ws, roots in holding(path):
dirs = parse.find_job_dirs(roots)
ids = [j.job_id for j in workspace.load_jobs(ws, roots, ends)]
# a job of the same id from another root shares these judgements: they stay
others = {e.get("job_id") for d, e in workspace.job_index(ws).items() if d not in dirs}
judged = judgements.job_dirs(ws.dir, [i for i in ids if i.split("~")[0] not in others])
held.append({"ws": ws, "roots": roots, "jobs": dirs,
"judged": judged, "judgements": sum(len(os.listdir(d)) for d in judged)})
return {"name": name, "dir": path, "bytes": size_of(path), "host": host, "workspaces": held,
"judgements": sum(w["judgements"] for w in held)}
jobs = workspace.load_jobs(ws, roots, ends)
judged = []
if final: # the workspace's records from before: those of its jobs alone copied in
done = judgements.adopt_owned(ws, dirs=set(dirs)) or set()
judged = [d for d in judgements.job_dirs(ws.dir, [j.job_id for j in jobs])
if all(os.path.join(d, n) in done for n in os.listdir(d) if n.endswith(".json"))]
else: # else counted as they are
olds += [judgements.overlay(ws.dir, j) for j in jobs]
held.append({"ws": ws, "roots": roots, "jobs": dirs, "judged": judged})
uids = {j.uid: j.uid_source for j in (parse.parse_job(d, trials=False) for d in parse.find_job_dirs([os.path.join(path, "jobs")]))
if j.uid}
return {"name": name, "dir": path, "bytes": size_of(path), "host": host, "workspaces": held, "uids": uids,
"judged": judgements.job_dirs(judgements.home(), sorted(uids)),
"judgements": judgements.records_of(judgements.home(), uids, olds)}


def _judged_elsewhere(home: str, paths: list, uids: set) -> set:
"""Which of the jobs *uids* of the run folders *paths*, deleted together,
keep their judgements: those with another folder of the same identity
outside them - a copy - under a root of any workspace or another run, read
afresh, never from a cache; all of them when one of those roots cannot be
read, since who owns them is then unknown."""
try:
return _copies(home, paths, uids)
except OSError:
return set(uids)


def _copies(home: str, paths: list, uids: set) -> set:
outside = lambda d: all(os.path.commonpath([os.path.realpath(d), p]) != p for p in paths)
roots = []
for ws in workspace.list_all(home):
if not all(os.path.isdir(r) for r in ws.job_roots or ws.roots):
return set(uids)
roots += ws.job_roots or ws.roots
roots += [j for parent in {os.path.dirname(p) for p in paths} for e in os.scandir(parent)
if e.is_dir(follow_symlinks=False) and e.path not in paths and os.path.isdir(j := os.path.join(e.path, "jobs"))]
return {job_uid.strict(d) for d in parse.find_job_dirs(roots, strict=lambda name: True) if outside(d)} & uids


def deletion(names: List[str], home: str, root: Optional[str] = None, holding: Optional[Callable] = None) -> dict:
def deletion(names: List[str], home: str, root: Optional[str] = None, holding: Optional[Callable] = None,
final: bool = False) -> dict:
"""What deleting the runs *names* of one launch removes: per run (``runs``)
its folder and size, the host copy that is its own, and per workspace that
holds it its roots, parsed jobs and judgement folders; the totals, and the
number of copies per host. ValueError when any of them is alive or is not
a run: nothing goes then. ``holding``: a run folder's ``workspace.holding``,
when the caller has it already."""
when the caller has it already. Its judgement folders in the user's store
(``judged``) are those of every job of the runs; ``delete`` decides which
go once the runs went."""
holding = holding or (lambda path: workspace.holding(home, path))
ends = run_ends()
runs = [_run_deletion(n, home, root, holding, ends) for n in dict.fromkeys(names)]
runs = [_run_deletion(n, home, root, holding, ends, final) for n in dict.fromkeys(names)]
copies: Dict[str, int] = {}
for r in runs:
if r["host"]:
Expand All @@ -1872,21 +1911,23 @@ def delete(names: List[str], home: str, root: Optional[str] = None, copies=(), r
in every workspace, and its copy on its host when that host's label is in
*copies*. Returns ``deletion``'s answer, with ``stays``: the runs whose
folder could not go (they keep everything else), and ``kept``: one line
per thing that stays."""
gone = deletion(names, home, root)
per thing that stays. The judgements of the user's store go last, once
every folder went or stayed: those of a job no folder of which is left."""
gone = deletion(names, home, root, final=True)
gone["stays"], gone["kept"] = [], []
went = []
for r in gone["runs"]:
try:
shutil.rmtree(r["dir"])
except OSError as e:
gone["stays"].append(r["name"])
gone["kept"].append(f"{r['name']} stays in {r['dir']}: {e.strerror or e}")
continue
went.append(r)
for key in [k for k, e in EXECUTIONS.items() if os.path.realpath(e.dir) == r["dir"]]:
del EXECUTIONS[key]
for w in r["workspaces"]:
for d in w["judged"]:
shutil.rmtree(d, ignore_errors=True)
judgements.forget(w["ws"].dir, w["judged"])
# read again: another run of the launch may have left this workspace already
ws = workspace.load(home, w["ws"].name)
if ws is not None:
Expand All @@ -1896,4 +1937,10 @@ def delete(names: List[str], home: str, root: Optional[str] = None, copies=(), r
rc, out = (run or subprocess_run)(host.argv(f"rm -rf {_rq(REMOTE_HOME + '/runs/' + r['name'])}", timeout=15), 60)
if rc != 0:
gone["kept"].append(f"the copy of {r['name']} on {host.label} stays: " + redact.redact(out.strip()[-200:]))
# a run that stayed, even in part, keeps its jobs' identities as they were read before the delete
uids = {u for r in went for u in r["uids"]} - {u for r in gone["runs"] if r not in went for u in r["uids"]}
if uids and judgements.job_dirs(judgements.home(), sorted(uids)):
uids -= _judged_elsewhere(home, [r["dir"] for r in went], uids)
for d in judgements.job_dirs(judgements.home(), sorted(uids)):
judgements.remove(d)
return gone
30 changes: 21 additions & 9 deletions app/nullius/judge/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,32 @@ def ask_states(states: dict, key: str, post: Optional[Callable] = None, calibrat
return merged


def ask_and_store(ws_dir: str, job_id: str, trial_name: str, states: dict, key, post: Optional[Callable] = None,
calibration: Optional[dict] = None, started: Optional[str] = None) -> Optional[dict]:
def ask_and_store(base: str, job_id: str, trial_name: str, states: dict, key, post: Optional[Callable] = None,
calibration: Optional[dict] = None, started: Optional[str] = None,
lane: Optional[str] = None, old: Optional[dict] = None, job_dir: Optional[str] = None,
strict: bool = False) -> Optional[dict]:
"""`ask_states`, then the merged record saved under the trial's key -
its answers over the version's earlier ones. Returns the record as
stored. The pre-flight reads the workspace's own calibration unless one
is given. `started`: the trial's own
start, which the record keeps (`store.save`)."""
its answers over the version's earlier ones - in the store at `base`
(`store.home`). Returns the record as stored. The pre-flight reads the
job's own calibration unless one is given. `started`: the trial's own
start, which the record keeps (`store.save`). `lane`: where it is kept,
the judge's own lane unless named (`store.TASKS`). `old`: the job's
older records (`store.overlay`), the file's copied in by the save. `job_dir`: the
job's folder, nothing saved once it is deleted (`store.Gone`). `strict`: an
attempt with several tries (`store.save`). A job with no identity yet (pending), or such a try
with no start, is refused before the judge is asked: its record could not be kept, or shown."""
if not job_id:
raise client.JudgeError(0, "this job has no identity until its result is written, so it is not judged yet")
if strict and not started:
raise client.JudgeError(0, "this try has no start, so its judgement could not be told from another try's")
if calibration is None:
calibration = store.calibration(ws_dir)
calibration = store.calibration(base, [job_id])
rec = ask_states(states, key, post=post, calibration=calibration)
if rec is not None:
# the LLM judge's records apart from Decision's; a call over some of the kinds keeps the
# earlier readings for the others, as the answers are kept (`store.save`), and returns them
lane = getattr(key, "lane", "decision")
lane = lane or getattr(key, "lane", "decision")
rec.setdefault("hygiene", {})
rec["hygiene"] = store.save(ws_dir, job_id, trial_name, rec, lane=lane, started=started)["hygiene"]
rec["hygiene"] = store.save(base, job_id, trial_name, rec, lane=lane, started=started, old=old, job_dir=job_dir,
strict=strict)["hygiene"]
return rec
Loading
Loading