diff --git a/app/nullius/execution.py b/app/nullius/execution.py index 2e0d91d5..bcb809a1 100644 --- a/app/nullius/execution.py +++ b/app/nullius/execution.py @@ -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) diff --git a/app/nullius/progress.py b/app/nullius/progress.py index 8aa2d26c..0f940157 100644 --- a/app/nullius/progress.py +++ b/app/nullius/progress.py @@ -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*)') diff --git a/app/nullius/standard/runner/run.py b/app/nullius/standard/runner/run.py index 802433fc..eacf6226 100644 --- a/app/nullius/standard/runner/run.py +++ b/app/nullius/standard/runner/run.py @@ -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 []) @@ -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) @@ -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: diff --git a/app/site/diagrams.py b/app/site/diagrams.py index 7126545f..afbb03ce 100644 --- a/app/site/diagrams.py +++ b/app/site/diagrams.py @@ -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') @@ -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') @@ -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-.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') diff --git a/app/static/runs/live-board.js b/app/static/runs/live-board.js index 07f396f3..5dda0e4e 100644 --- a/app/static/runs/live-board.js +++ b/app/static/runs/live-board.js @@ -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)); diff --git a/app/tests/test_execution.py b/app/tests/test_execution.py index 71ee84ad..dad1c853 100644 --- a/app/tests/test_execution.py +++ b/app/tests/test_execution.py @@ -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") diff --git a/app/tests/test_progress.py b/app/tests/test_progress.py index 4df04980..b752e1f8 100644 --- a/app/tests/test_progress.py +++ b/app/tests/test_progress.py @@ -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")), \ @@ -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 diff --git a/app/ui_tests/test_live_board.py b/app/ui_tests/test_live_board.py index 7dccbc47..9e8e82cd 100644 --- a/app/ui_tests/test_live_board.py +++ b/app/ui_tests/test_live_board.py @@ -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: diff --git a/app/ui_tests/test_run_routes.py b/app/ui_tests/test_run_routes.py index 498852a3..cd25e91f 100644 --- a/app/ui_tests/test_run_routes.py +++ b/app/ui_tests/test_run_routes.py @@ -173,15 +173,15 @@ 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 @@ -189,6 +189,16 @@ def test_the_run_opens_runs_by_launch_and_its_job_page_before_harbor_writes_the_ 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 diff --git a/app/web/execute.py b/app/web/execute.py index 264c92dd..7cc557df 100644 --- a/app/web/execute.py +++ b/app/web/execute.py @@ -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/") diff --git a/docs/diagrams/builder-run.svg b/docs/diagrams/builder-run.svg index 738e5cb5..14ae2085 100644 --- a/docs/diagrams/builder-run.svg +++ b/docs/diagrams/builder-run.svg @@ -66,8 +66,8 @@ SSH: DOCKER, UV · THE RUNNER SENT RUN-<PART>.SH DETACHED · PID, EXIT FILE - -EVERY 10 S: LOG TAIL, RSYNC JOBS/ + +1 S PAUSE: LOG TAIL, RSYNC JOBS/ PAUSE: CONTINUE OR STOP diff --git a/docs/diagrams/path-run-here.svg b/docs/diagrams/path-run-here.svg index a68946cc..78e6ba76 100644 --- a/docs/diagrams/path-run-here.svg +++ b/docs/diagrams/path-run-here.svg @@ -67,8 +67,8 @@ RUN-PART.SH MODEL CALLS - -JOBS/, EVERY 10 S + +JOBS/, 1 S PAUSE JOB PAGE · LIVE diff --git a/docs/diagrams/path-run-host.svg b/docs/diagrams/path-run-host.svg index cc5407d2..3643a2c6 100644 --- a/docs/diagrams/path-run-host.svg +++ b/docs/diagrams/path-run-host.svg @@ -1,6 +1,6 @@ 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. +Execution probes the host, sends the part and the key, starts it detached, then tails the log and pulls the jobs back, pausing one second between looks. of`) | -| A run on a host | Runs the running backend and effective catalogue: source edits, user entries and catalogue-local dataset files are included, configuration and credential stores excluded; needs `python3`, `git` and, for the container backend, Docker or Podman; `uv` is installed when missing. On the local backend a host without `npm` is refused. The job is mirrored back every 10 s | +| A run on a host | Runs the running backend and effective catalogue: source edits, user entries and catalogue-local dataset files are included, configuration and credential stores excluded; needs `python3`, `git` and, for the container backend, Docker or Podman; `uv` is installed when missing. On the local backend a host without `npm` is refused. The job is mirrored back with a 1 s pause between looks | | Agents and Capabilities tabs | Each definition's ports proven and the benchmarks it runs; *Prove its ports* runs `cli conform --from-run` here, with local processes or a container, and updates its proofs | | A benchmark's page | Its proofs per dataset; *Run control checks* runs `cli prove --from-run` here, handed no key unless the benchmark is judged. A failed check is kept under `proven..failed` until it passes |