fix(hub): runner runs operator rows in the operator's shell and closes them only when the host check passes
A hub-run operator row ran under bash -c with PATH=/usr/bin:/bin, so a command that works in the operator's terminal (aliases, PATH additions) failed there, and exit 0 closed the row whatever its check, because the hub cannot read the host's repos, PATH and installed dirs. The runner now runs the signed text as $SHELL -ic <text> in the signed directory, like operator.py run (SHELL, else the runner uid's login shell). After exit 0 it runs operator.py checked <slug> the same way and reports checked true, false or null; the hub calls ran without --check-failed only when checked is true, so a row whose check fails on the host stays open with a message like run's.
operator.py: new checked <slug> (exit 0 pass, 1 fail, 2 unknown slug) and ran --check-failed; holds() shares the check with run. jobs.py accepts the optional checked field and drops the old usage-error fallback to done. The runner unit passes --operator with the installed operator.py; without it, or with an older hub or runner on either side, checked stays null and the row stays open (fails closed).
Rebased onto master from its lane base 2754568 with a 3-way apply: all 10 files clean, the staged stat equal to the patch's own (+206/-64), nothing of master reverted.
Tests: test_operator.py ran once on the staged tree (operator-approved run): 52 passed, 61 subtests passed. test_hub_executors and test_hub_console cover checked() and the ran/--check-failed calls; written, not run: the full suite runs once on master after all bundles (operator order). A probe of /bin/bash -ic without a tty, as systemd starts the runner, passes the exit code through (7); the rc file's 56-line banner lands at the head and falls out of the runner's last-lines output tail.
Security: MEDUSA over the staged tree on master: 100, 9 of 10 files covered, 0 open findings, every hit accepted earlier (RH005 after a skeptic review and the operator's accept). The systemd unit is outside MEDUSA's coverage; its one change appends --operator <installed operator.py>.
🎯 Fix: 90 %
💥 Break: 4 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 86
🚦 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:
1 parent
20b1500b80
commit
a4f7017691
10 files changed
+209
-67
No files matched your search
@@ -14,7 +14,6 @@ CONSOLE = ("id", "status", "code", "output", "created_ts", "started", "finished"
|
||||
TASK_JOB = "task"
|
||||
GATE_JOB = "gate"
|
||||
CHANGES = (TASK_JOB, GATE_JOB)
|
||||
USAGE = 2
|
||||
|
||||
|
||||
def runner_job(job: dict) -> dict:
|
||||
@@ -79,11 +78,19 @@ class Jobs:
|
||||
return runner_job(job)
|
||||
|
||||
def report(self, job_id: str, body: bytes) -> dict:
|
||||
"""Args:
|
||||
body: {"output", "code", "refused"}, and "checked" on an operator
|
||||
command's final report after exit 0: whether its row's check
|
||||
passed on the host, null when the runner could not tell.
|
||||
"""
|
||||
payload = decode(body)
|
||||
expect(payload, ("output", "code", "refused"))
|
||||
expect(payload, ("output", "code", "refused", "checked") if "checked" in payload else ("output", "code", "refused"))
|
||||
output, code, refused = bounded(payload, "output", RUN_OUTPUT), payload["code"], payload["refused"]
|
||||
checked = payload.get("checked")
|
||||
if not isinstance(refused, bool) or (code is not None and (isinstance(code, bool) or not isinstance(code, int))):
|
||||
raise ToolError("code must be a whole number or null and refused true or false")
|
||||
if checked is not None and not isinstance(checked, bool):
|
||||
raise ToolError("checked must be true, false or null")
|
||||
record = self.jobs.get(job_id)
|
||||
if record is None:
|
||||
raise Missing(job_id)
|
||||
@@ -96,18 +103,23 @@ class Jobs:
|
||||
job, changed = self.jobs.transition(job_id, "running", {"status": status, "code": code, "output": output, "finished": time.time()})
|
||||
if not changed:
|
||||
raise Conflict({"id": job_id, "status": job["status"]})
|
||||
runs = self.close_row(job, status, code)
|
||||
runs = self.close_row(job, status, code, checked is True)
|
||||
tail = "\n".join(output.splitlines()[-20:])
|
||||
self.log.add({"kind": "run", "title": f"{status}: {job['command'][:200]}", "text": tail, "ref": {"job": job_id, "task": job["task"], "code": code, "status": status}})
|
||||
told = self.tell_applied(job) if job.get("kind") == TASK_JOB else []
|
||||
return {"id": job_id, "status": status, "code": code, "runs": runs, "told": told}
|
||||
|
||||
def close_row(self, job: dict, status: str, code: int | None) -> list[dict]:
|
||||
"""Returns:
|
||||
def close_row(self, job: dict, status: str, code: int | None, checked: bool) -> list[dict]:
|
||||
"""Args:
|
||||
checked: whether the runner saw the row's check pass on the host
|
||||
after exit 0; the hub cannot read the host's repos, PATH and
|
||||
installed dirs itself.
|
||||
|
||||
Returns:
|
||||
The operator.py runs that report the end of an operator command
|
||||
job on its row: `ran` on exit 0, then an older operator.py's
|
||||
`done` when `ran` is its usage error; `failed` on any other exit;
|
||||
none for a refused job or a task or gate change.
|
||||
job on its row: `ran` on exit 0, with --check-failed unless
|
||||
checked, so the row stays open; `failed` on any other exit; none
|
||||
for a refused job or a task or gate change.
|
||||
"""
|
||||
if job.get("kind") in CHANGES or status not in ("done", "failed"):
|
||||
return []
|
||||
@@ -116,7 +128,4 @@ class Jobs:
|
||||
if status == "failed":
|
||||
why = f"killed by signal {-code}" if code < 0 else f"exit {code}"
|
||||
return [self.scripts.run(OPERATOR_SCRIPT, ["failed", *shown, "--why", why])]
|
||||
runs = [self.scripts.run(OPERATOR_SCRIPT, ["ran", *shown])]
|
||||
if runs[0]["code"] == USAGE:
|
||||
runs.append(self.scripts.run(OPERATOR_SCRIPT, ["done", slug]))
|
||||
return runs
|
||||
return [self.scripts.run(OPERATOR_SCRIPT, ["ran", *shown] if checked else ["ran", *shown, "--check-failed"])]
|
||||
Reference in new issue
Block a user