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:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-22 22:50:16 +00:00
1 parent 20b1500b80
commit a4f7017691
10 files changed
+209 -67

No files matched your search

+36 -4
View File
@@ -107,22 +107,54 @@ class TestHubExecutors(HubCase):
self.approvers.unlink()
job = {"task": "operator/greet", "command": command, "directory": str(self.outside), "proof": proof}
self.assertIn("no key is pinned", runner.refusal(job, self.trust("other"), time.time()))
reports = []
self.assertEqual(runner.execute({"command": "exit 3", "directory": str(self.outside)}, reports.append), 3)
reports, host = [], runner.Host(shell=str(self.shell), operator=None, council=None)
self.assertEqual(runner.execute({"command": "exit 3", "directory": str(self.outside)}, host, reports.append), 3)
self.assertEqual(reports[-1], {"output": "", "code": 3, "refused": False})
self.assertEqual(runner.execute({"command": "true", "directory": str(self.outside)}, host, reports.append), 0)
self.assertEqual(reports[-1], {"output": "", "code": 0, "refused": False, "checked": None})
self.assertEqual(runner.execute({"command": "true", "directory": str(self.outside)}, host._replace(shell=str(self.outside)), reports.append), 127)
def test_the_runner_keeps_a_row_open_whose_check_fails_on_the_host_after_exit_0(self):
command = "echo pushed"
register = {"operator/push": {"title": command, "workdir": str(self.outside), "description": "push", "check": f"absent:{self.outside}", "status": "queued", "roles": {}}}
self.write_council({"rasci.json": register})
digest = hashlib.sha256(command.encode()).hexdigest()
signer = self.pin()
push = [self.entry("operator", "operator/push", "", digest)]
with mock.patch.object(batches, "UNDO", 0.05):
self.assertEqual(self.approve(push, self.signed(push, signer))[0], 202)
self.settle(lambda: self.runner_jobs() != [])
self.run_runner()
job = self.snapshot()["jobs"][-1]
self.assertEqual((job["status"], job["code"], job["output"]), ("done", 0, "pushed\n"))
self.assertEqual(self.scripts.calls[-1], (skill_scripts.OPERATOR_SCRIPT, ["ran", "push", f"--command={command}", f"--dir={self.outside}", "--check-failed"]))
host = runner.Host(shell=str(self.shell), operator=hub_support.OPERATOR, council=self.council)
self.assertIs(runner.checked({"task": "operator/push"}, host), False)
self.assertIsNone(runner.checked({"task": "operator/missing"}, host))
self.assertIsNone(runner.checked({"task": "operator/push"}, host._replace(shell=str(self.outside / "no-shell"))))
marking = self.outside / "marking-shell"
marking.write_text('#!/bin/sh\ntouch "$0.ran"\n', encoding="utf-8")
marking.chmod(0o700)
for task in ("operator/x\\'\"; id #", "operator/Push", "review/push", "push", None):
with self.subTest(task=task):
self.assertIsNone(runner.checked({"task": task}, host._replace(shell=str(marking))))
self.assertFalse(marking.with_name("marking-shell.ran").exists())
self.write_council({"rasci.json": {"operator/push": {**register["operator/push"], "check": "manual"}}})
self.assertIs(runner.checked({"task": "operator/push"}, host), True)
def test_the_runner_closes_the_output_pipe_on_every_path(self):
popen, spawned = subprocess.Popen, []
job = {"command": "echo hi; sleep 0.3", "directory": str(self.outside)}
host = runner.Host(shell=str(self.shell), operator=None, council=None)
def spawn(*args: object, **kwargs: object) -> subprocess.Popen:
spawned.append(popen(*args, **kwargs))
return spawned[-1]
with mock.patch.object(subprocess, "Popen", spawn), mock.patch.object(runner, "BEAT", 0.05):
self.assertEqual(runner.execute(job, [].append), 0)
self.assertEqual(runner.execute(job, host, [].append), 0)
self.assertTrue(spawned[0].stdout.closed)
self.assertRaises(RuntimeError, runner.execute, job, mock.Mock(side_effect=RuntimeError("the hub is gone")))
self.assertRaises(RuntimeError, runner.execute, job, host, mock.Mock(side_effect=RuntimeError("the hub is gone")))
self.settle(lambda: spawned[1].stdout.closed)
self.assertEqual(spawned[1].wait(10), 0)