fix(orchestrator): keep installs off a running hub row and fail orphaned jobs

The runner records the hub row it runs in runner-job.json of the hub
state directory (new --state flag, set by the runner unit) and drops it
when the row ends. orchestrator.sh idle exits 1 with the row's task and
job id while that file names a live pid; install, stop, runner and the
home install.sh check it first, because stopping the runner would kill
the row. A starting runner posts /api/runner/restart, and the hub fails
every job an earlier runner left running, closing its row like a failed
run with the reason that the runner restarted.

🎯 Fix: 92 %
💥 Break: 4 %
💸 Tokens: 100 %
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 88
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-27 10:44:15 +00:00
1 parent 0f8cb32198
commit 30862411f3
15 files changed
+411 -56

No files matched your search

+27
View File
@@ -165,6 +165,33 @@ class TestHubConsole(HubCase):
])
self.assertNotIn("token-42", json.dumps(self.scripts.calls))
def test_a_runner_restart_fails_every_running_job_and_closes_its_row_like_a_failed_run(self):
self.register("queued")
now = time.time()
fields = {"task": "operator/greet", "command": COMMAND, "directory": str(self.outside), "sha256": DIGEST, "proof": None, "code": None, "output": "line 1\n", "created_ts": now, "finished": None, "dismissed": False}
command = self.httpd.hub.jobs.add({**fields, "status": "running", "started": now})
gate = self.httpd.hub.jobs.add({**fields, "status": "running", "started": now, "kind": "gate", "argv": []})
queued = self.httpd.hub.jobs.add({**fields, "status": "queued", "started": None})
done = self.httpd.hub.jobs.add({**fields, "status": "done", "code": 0, "started": now, "finished": now})
self.assertEqual(self.post_json("/api/runner/restart", {}, self.guard(self.host))[0], 403)
self.assertEqual(self.post_json("/api/runner/restart", {}, {"Host": self.host})[0], 403)
self.assertEqual(self.scripts.calls, [])
status, answer = self.runner("/api/runner/restart", {})
self.assertEqual((status, sorted(answer["failed"])), (200, sorted([command["id"], gate["id"]])))
for job in (command, gate):
with self.subTest(job=job["id"]):
stored = self.httpd.hub.jobs.get(job["id"])
self.assertEqual((stored["status"], stored["code"], stored["output"]), ("failed", None, jobs.RESTARTED))
self.assertGreaterEqual(stored["finished"], now)
self.assertEqual([self.httpd.hub.jobs.get(job["id"])["status"] for job in (queued, done)], ["queued", "done"])
shown = ["greet", f"--command={COMMAND}", f"--dir={self.outside}"]
where = f"--where=the console of hub job {command['id']} under the row in Waits on Operator"
self.assertEqual(self.scripts.calls, [(skill_scripts.OPERATOR_SCRIPT, ["failed", *shown, "--why", jobs.RESTARTED, where])])
stored = json.loads((self.state / "jobs.json").read_text(encoding="utf-8"))
self.assertEqual({stored[job["id"]]["status"] for job in (command, gate)}, {"failed"})
self.assertEqual(self.runner("/api/runner/restart", {}), (200, {"failed": []}))
self.assertEqual(len(self.scripts.calls), 1)
def test_a_ran_the_installed_operator_refuses_never_falls_back_to_done(self):
self.register("queued")
fields = {"task": "operator/greet", "command": COMMAND, "directory": str(self.outside), "sha256": DIGEST, "status": "running", "proof": None}