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
2 changes: 1 addition & 1 deletion app/nullius/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
# The line the launcher's stdin ends with, after the key and the endpoint:
# either may be empty, so only this line says the two arrived whole.
STDIN_END = "@end"
SYNC_EVERY = 10.0 # seconds between looks at a running part (mirror, log, exit)
SYNC_EVERY = 1.0 # seconds between looks at a running part (mirror, log, exit)
STOP_POLL = 0.5 # how often a running command looks for a Stop
STOP_WAIT = 20.0 # seconds a Stop's own commands on the target take at most: the kill and the last copy back, together
LAUNCH_GRACE = 5.0 # seconds a restart waits for a part a launcher claimed to start (_settle)
Expand Down
2 changes: 1 addition & 1 deletion app/nullius/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

# What the page calls each stage. One not here is shown by its own name.
LABELS = {"connect": "Connect", "uv": "uv", "tasks": "Send the tasks", "app": "Send app/", "harbor": "Harbor",
"image": "Base image", "environment": "Environment", "upstream": "Benchmark source", "dataset": "Dataset",
"models": "Check models", "requirements": "Check requirements", "image": "Base image", "environment": "Environment", "upstream": "Benchmark source", "dataset": "Dataset",
"driver": "Driver environment", "install": "Install", "runtime": "Agent runtime", "units": "Units"}

_WORD = re.compile(r'([A-Za-z_][A-Za-z0-9_]*)=("(?:[^"\\]|\\.)*"|\S*)')
Expand Down
15 changes: 9 additions & 6 deletions app/nullius/standard/runner/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def _start(self, lck, mine) -> str:
HELD[lck] = held
self.say(f"job {self.job_dir}")
p, control = self.progress, self.other["_kind"] == "control"
p.emit("plan", stages=",".join((["image"] if self.backend == "container" or self.relay_container or self.container_check else [])
p.emit("plan", stages=",".join((["models"] if self.base else []) + ["requirements"] + (["image"] if self.backend == "container" or self.relay_container or self.container_check else [])
+ (["upstream"] if install.upstream_dir(self.bench) else [])
+ (["dataset"] if self.ds.get("url") else [])
+ (["driver"] if install.driver_dir(self.bench) else [])
Expand All @@ -859,7 +859,9 @@ def _start(self, lck, mine) -> str:
if self.cap_dropped:
self.say(f"warning: {self.cap_dropped} ({self.cap_why})")
try:
self.known_models()
if self.base:
with p.stage("models", start="checking the provider’s model list"):
self.known_models()
self.ready()
except Refused as e:
# said in the job, which holds nothing else: the runs list reads why there (progress.refusal)
Expand Down Expand Up @@ -1177,11 +1179,12 @@ def ready(self) -> None:
when it declares one (``driver.install``), the agent's or capability's
packages. Refused when one cannot be had."""
from ..requirements import network_requirements
why = network_requirements.check(self.bench, self.other)
if why:
raise BenchmarkRefused("; ".join(why))
p = self.progress
self.scope_limits = self.scope_ready(limits.scoped(self.constraints), refuse=self.backend == "local")
with p.stage("requirements", start="checking network access and machine limits"):
why = network_requirements.check(self.bench, self.other)
if why:
raise BenchmarkRefused("; ".join(why))
self.scope_limits = self.scope_ready(limits.scoped(self.constraints), refuse=self.backend == "local")
owns = any(definitions.own_image(e) for e in (self.bench.get("environments") or {}).values())
if self.backend == "container" or self.relay_container or self.container_check:
try:
Expand Down
8 changes: 4 additions & 4 deletions app/site/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def path_run_here() -> Figure:
f.self_message(exe, 224, 'RUN.JSON · KEY', room=84)
f.message(exe + 4, hbr - 4, 320, 'RUN-PART.SH')
f.message(hbr + 4, llm, 360, 'MODEL CALLS')
f.message(hbr - 4, exe + 4, 400, 'JOBS/, EVERY 10 S', 'dashed')
f.message(hbr - 4, exe + 4, 400, 'JOBS/, 1 S PAUSE', 'dashed')
f.message(exe - 4, you, 464, 'JOB PAGE · LIVE', 'accent', at=260)
f.actor(you, 24, 'You', kind='input')
f.actor(bld, 24, 'Builder', 'page, recipe core')
Expand All @@ -335,13 +335,13 @@ def path_run_here() -> Figure:
def path_run_host() -> Figure:
f = Figure('path-run-host', 640, 416, 'Path 3: the same on an SSH host',
'Execution probes the host, sends the part and the key, starts it detached, then tails '
'the log and pulls the jobs back every ten seconds.')
'the log and pulls the jobs back, pausing one second between looks.')
exe, host = 160, 480
for cx in (exe, host):
f.lifeline(cx, 72, 368)
f.activation(exe, 104, 344)
f.activation(host, 184, 344)
f.fragment(136, 224, 368, 120, 'LOOP', '[every 10 s]')
f.fragment(136, 224, 368, 120, 'LOOP', '[1 s pause]')
f.message(exe + 4, host - 4, 112, 'PROBE: DOCKER, UV (INSTALLED IF MISSING)')
f.message(exe + 4, host - 4, 152, 'SEND WHEELS, TASKS, RUN-PART.SH · KEY OVER STDIN')
f.message(exe + 4, host - 4, 192, 'START RUN-PART.SH, DETACHED')
Expand Down Expand Up @@ -423,7 +423,7 @@ def builder_run() -> Figure:
f.self_message(nul, 176, 'RUNNER PREPARED ONCE', room=200)
f.message(nul + 4, tgt - 4, 232, 'SSH: DOCKER, UV · THE RUNNER SENT')
f.message(nul + 4, tgt - 4, 320, 'RUN-<PART>.SH DETACHED · PID, EXIT FILE')
f.self_message(nul, 344, 'EVERY 10 S: LOG TAIL, RSYNC JOBS/', 'dashed', room=200)
f.self_message(nul, 344, '1 S PAUSE: LOG TAIL, RSYNC JOBS/', 'dashed', room=200)
f.message(nul - 4, page, 456, 'PAUSE: CONTINUE OR STOP')
f.message(nul - 4, page, 536, 'JOB PAGE: RUN LOG, THEN LIVE', 'accent')
f.actor(page, 24, 'Page', 'the builder', kind='input')
Expand Down
3 changes: 2 additions & 1 deletion app/static/runs/live-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@
history.replaceState(null, '', u);
}
doc.addEventListener('live-ready', () => {
if (!new URL(location.href).searchParams.has('view')) show('live');
const requested = new URL(location.href).searchParams.get('view');
if (requested !== 'logs' && requested !== 'results') show('live');
});
tabs.forEach(t => {
t.addEventListener('click', () => show(t.dataset.viewTab));
Expand Down
14 changes: 14 additions & 0 deletions app/tests/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,20 @@ def put(path, text, at):
self.assertTrue((trial / "agent" / "trace.json").exists())


class FollowCadence(unittest.TestCase):
def test_remote_updates_are_read_again_within_one_second_of_a_copy(self):
import tempfile
with tempfile.TemporaryDirectory() as root:
ex = execution.Execution(execution.Plan(name="follow", script="true", host=hosts.parse("bench")),
root=root, env={})
with patch.object(ex, "_sh", side_effect=[(0, "\n__nullius__ alive"), (0, "\n__nullius__ 0")]), \
patch.object(ex, "_mirror") as mirror, patch.object(ex._stop, "wait", return_value=False) as wait:
self.assertEqual(ex._follow({"id": "run", "label": "run"}), 0)
self.assertEqual(mirror.call_count, 2)
self.assertEqual(wait.call_count, 1)
self.assertLessEqual(wait.call_args.args[0], 1.0)


class TasksOnHost(unittest.TestCase):
def test_two_folders_of_one_name_never_share_a_copy_and_one_folder_keeps_its_own(self):
a, b = execution._tasks_place("/data/projA/tasks", "r1"), execution._tasks_place("/data/projB/tasks", "r2")
Expand Down
20 changes: 19 additions & 1 deletion app/tests/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ def test_a_run_writes_the_live_feed_its_job_page_folds(self):
names = sorted(d for d in os.listdir(job) if "__u" in d)
self.assertEqual(sorted(t["trial"] for t in snap["trials"]), names) # the trial folders' own names

def test_preflight_checks_are_visible_while_they_block(self):
from nullius.standard.requirements import network_requirements
for stage in ("models", "requirements"):
with self.subTest(stage=stage):
r = self.go(name="check-" + stage)
if stage == "models":
r.base = "https://provider.invalid/v1"
def checking(*args):
self.assertEqual(progress.fold(progress.read(r.job_dir))["current"], stage)
raise run.Refused("check failed")
target, method = (r, "known_models") if stage == "models" else (network_requirements, "check")
with patch.object(target, method, side_effect=checking), self.assertRaises(run.Refused):
r.start()
folded = progress.fold(progress.read(r.job_dir))
self.assertEqual(folded["ended"], "refused")
self.assertEqual(next(s for s in folded["stages"] if s["stage"] == stage)["state"], "failed")

def test_a_refused_run_says_why_in_its_job_and_writes_nothing_else(self):
r = self.go()
with patch.object(install, "upstream_dir", lambda b, home=None: os.path.join(self.tmp, "up")), \
Expand All @@ -223,7 +240,8 @@ def test_a_refused_run_says_why_in_its_job_and_writes_nothing_else(self):
r.start()
events = progress.read(r.job_dir)
self.assertEqual([(e["stage"], e.get("state")) for e in events],
[("plan", None), ("upstream", "start"), ("upstream", "failed"), ("refused", None)])
[("plan", None), ("requirements", "start"), ("requirements", "done"),
("upstream", "start"), ("upstream", "failed"), ("refused", None)])
self.assertIn("git fetch: exit 128", progress.refusal(events))
self.assertFalse(os.path.exists(os.path.join(r.job_dir, "config.json"))) # no job: nothing a runs page would list

Expand Down
32 changes: 32 additions & 0 deletions app/ui_tests/test_live_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,38 @@ def test_launch_logs_precede_the_board_and_remain_selectable(self):
self.assertIn('aria-controls="view-logs" aria-selected="true"', body)
self.assertIn('id="view-live" aria-labelledby="tab-live" hidden', body)

def test_feed_readiness_switches_to_live_unless_another_tab_was_chosen(self):
if not self.node:
self.skipTest("node not available")
script = r"""
const vm = require('vm'), fs = require('fs'), assert = require('assert');
const source = fs.readFileSync(process.argv[1], 'utf8');
for (const query of ['', '?view=live', '?view=logs', '?view=results']) {
for (const click of [null, 'logs', 'results']) {
const panels = {}, events = {};
const tabs = ['live', 'logs', 'results'].map(view => {
panels['view-' + view] = {hidden: view !== (query === '?view=results' ? 'results' : 'logs')};
return {dataset: {viewTab: view}, events: {},
setAttribute() {}, getAttribute() { return 'view-' + view; },
addEventListener(k, f) { this.events[k] = f; }};
});
const location = {href: 'http://localhost/job/demo' + query};
const doc = {readyState: 'complete',
querySelectorAll() { return tabs; },
getElementById(id) { return panels[id] || null; },
addEventListener(k, f) { events[k] = f; }};
vm.runInNewContext(source, {document: doc, URL, location,
history: {replaceState(a, b, url) { location.href = String(url); }}});
if (click) tabs.find(t => t.dataset.viewTab === click).events.click();
events['live-ready']();
const chosen = click || (query === '?view=logs' ? 'logs' : query === '?view=results' ? 'results' : 'live');
assert.equal(panels['view-' + chosen].hidden, false, query + ' click=' + click);
}
}
"""
subprocess.run([self.node, "-e", script, str(APP_DIR / "static/runs/live-board.js")],
capture_output=True, text=True, check=True)

# -- the renderer, executed --------------------------------------------
def render(self, snapshot, **opts):
if not self.node:
Expand Down
18 changes: 14 additions & 4 deletions app/ui_tests/test_run_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,32 @@ def test_a_name_still_running_or_used_before_is_refused_and_nothing_starts(self)
self.assertEqual((dict(execution.EXECUTIONS), self.adopted), ({}, [])) # nothing started, the free name included
self.assertFalse((self.tmp / "runs" / "fresh").exists())

def test_the_run_opens_runs_by_launch_and_its_job_page_before_harbor_writes_the_job(self):
def test_a_single_run_opens_its_job_page_before_harbor_writes_the_job(self):
r = self.post({"name": "tau3-x3", "script": "true", "where": "local", "jobs": [{"name": "tau3-x3", "agent": "oracle", "dataset": "tau3-x3"}]})
self.assertEqual(r.status_code, 200, r.get_data(as_text=True)); self.assertEqual(r.json["open"], "/runs?view=launch")
self.assertEqual(r.status_code, 200, r.get_data(as_text=True)); self.assertEqual(r.json["open"], "/job/tau3-x3")
from nullius import workspace # the run's root, adopted into a workspace
self.stack.enter_context(patch.dict(web.shared.STATE, {"workspace": None, "roots": [], "label": "", "job_roots": []}))
web.shared.open_workspace(workspace.create(str(self.tmp / "ws"), list(self.adopted), label="here"))
runs = self.client.get(r.json["open"]); self.addCleanup(runs.close) # its launch, before any job is written
runs = self.client.get("/runs?view=launch"); self.addCleanup(runs.close) # its launch, before any job is written
self.assertIn('data-launch="run:', runs.get_data(as_text=True)); self.assertIn("tau3-x3", runs.get_data(as_text=True))
page = self.client.get("/job/tau3-x3"); self.addCleanup(page.close) # no job dir yet: the run's own page
page = self.client.get(r.json["open"]); self.addCleanup(page.close) # no job dir yet: the run's own page
html = page.get_data(as_text=True)
self.assertEqual(page.status_code, 200); self.assertIn('id="execution"', html); self.assertIn('data-waiting="yes"', html); self.assertIn("this machine", html)
self.assertEqual(self.client.head("/job/tau3-x3").status_code, 404) # HEAD says whether Harbor's job is there yet
self.wait()
lst = self.client.get("/runs"); self.addCleanup(lst.close)
self.assertEqual(self.client.get("/job/nothing-like-it").status_code, 404)

def test_a_launch_without_one_job_opens_the_launches_list(self):
for jobs in ([], [{"name": "first"}, {"name": "second"}]):
with self.subTest(jobs=jobs):
ex = unittest.mock.Mock()
ex.summary.return_value = {"job_ids": [j["name"] for j in jobs]}
with patch.object(web.execute, "begin", return_value=([ex], "", 200)):
response = self.post({"name": "several", "script": "true", "jobs": jobs})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json["open"], "/runs?view=launch")

def test_the_run_s_page_shows_its_stages_and_its_units(self):
"""What the run said in stages (nullius/progress.py) - done with its
seconds, cached, running, waiting - and its units so far, on the page
Expand Down
4 changes: 3 additions & 1 deletion app/web/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ def _start(plan: execution.Plan):
started, problem, status = begin([plan])
if problem:
return jsonify(ok=False, error=problem), status
return jsonify(ok=True, open=url_for("index", view="launch"), **started[0].summary())
summary, jobs = started[0].summary(), plan.jobs
destination = url_for("job", job_id=str(jobs[0].get("name"))) if len(jobs) == 1 else url_for("index", view="launch")
return jsonify(ok=True, open=destination, **summary)


@app.route("/run/<run_id>")
Expand Down
4 changes: 2 additions & 2 deletions docs/diagrams/builder-run.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/diagrams/path-run-here.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/diagrams/path-run-host.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading