Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f27cbdb
fix(judge): keep judgements by the job they judge, not by the workspace
harenome Nov 24, 2026
6ac66a1
fix(judge): read the judgements workspaces kept without writing, and …
harenome Nov 24, 2026
bfdfeb0
docs(judge): name the job identity, the task and deleted-workspace st…
harenome Nov 24, 2026
6de0625
fix(settings): lay the move judgements row out on one line
harenome Nov 24, 2026
90e639e
fix(judge): move a workspace's judgements only when each has one job,…
harenome Nov 24, 2026
112b807
fix(runs): decide a deleted launch's judgements from fresh files and …
harenome Nov 24, 2026
0ed3e9a
fix(judge): keep a try's judgement under its attempt's name, told apa…
harenome Nov 25, 2026
294fd95
fix(execution): remove a deleted launch's judgements only once its ru…
harenome Nov 25, 2026
3c3112f
fix(judge): copy a workspace's older judgements only to the one job t…
harenome Nov 25, 2026
077c051
fix(workspaces): keep a workspace whose imports cannot all be listed
harenome Nov 25, 2026
d246c17
fix(execution): keep a deleted launch's judgements while a copy's ide…
harenome Nov 25, 2026
e2ed1a5
fix(judge): copy an older judgement on a save only when no job spelt …
harenome Nov 25, 2026
177fcd5
fix(judge): save a batch's judgements with the workspace asked and a …
harenome Nov 25, 2026
2da00ac
fix(judge): show a try's judgement only when its start matches, where…
harenome Nov 25, 2026
e211ee4
fix(judge): keep a workspace's moved mark with its folder, and refuse…
harenome Nov 25, 2026
e05e303
fix(web): close a deleted workspace only once it is gone
harenome Nov 25, 2026
59907fc
fix(judge): refuse a job with no identity yet before the judge is asked
harenome Nov 25, 2026
4253c46
fix(judge): give a job with no identity and no dataset no task key
harenome Nov 25, 2026
49fa64d
fix(workspaces): keep a workspace whose root is there but cannot be l…
harenome Nov 25, 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) 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
28 changes: 19 additions & 9 deletions app/nullius/judge/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,30 @@ 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) is refused
before the judge is asked: its record could not be kept."""
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 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