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

+60 -11
View File
@@ -13,12 +13,22 @@
--gates: the installed gates script, e.g.
~/.claude/skills/kvb-check-gate/scripts/gates.py; optional, gate
changes need it.
--operator: the installed operator script, e.g.
~/.claude/skills/kvb-org-operator/scripts/operator.py; optional,
without it no row closes done after exit 0.
--once: handle the queued jobs once and exit.
Environment:
SHELL: the operator's shell, else the login shell of the runner's uid.
Returns:
Runs as the operator, outside any sandbox, every operator command a
pinned passkey signed in the Agent Orchestrator: exactly the signed text, with bash
in the signed directory, each signature once and before its expiry.
pinned passkey signed in the Agent Orchestrator: exactly the signed
text, as `$SHELL -ic <text>` like `operator.py run`, in the signed
directory, each signature once and before its expiry. After exit 0 it
runs `operator.py checked <slug>` the same way and reports whether the
row's check passes on this host; the hub keeps the row open unless it
does.
Runs every signed task change (priority pin, status, dependency or WSJF
estimate; a board batch is one job per change) as
`python3 -I -B <rasci> <argv>` from / without a shell, after checking the
@@ -45,6 +55,8 @@ import collections
import contextlib
import json
import os
import pwd
import shlex
import signal
import stat
import subprocess
@@ -72,6 +84,7 @@ SAFE_PATH = "/usr/bin:/bin"
TASK_JOB = "task"
TASK_LIMIT = 30.0
GATE_JOB = "gate"
OPERATOR = "operator/"
REFUSED = "refused: no valid operator signature for this command"
UNREGISTERED = "refused: this runner was started without --rasci and --council; reinstall its unit with make orchestrator-runner"
UNGATED = "refused: this runner was started without --gates; reinstall its unit with make orchestrator-runner"
@@ -82,6 +95,12 @@ class Register(NamedTuple):
council: Path
class Host(NamedTuple):
shell: str
operator: Path | None
council: Path | None
def call(base: str, path: str, payload: dict | None) -> dict:
headers = dict(hub_api.GUARD)
data = None
@@ -229,16 +248,44 @@ def council_refusal(council: Path) -> str | None:
return None
def execute(job: dict, report: Callable[[dict], None]) -> int:
def checked(job: dict, host: Host) -> bool | None:
"""Args:
job: the claimed and verified job with command and directory.
report: called with {"output", "code", "refused"}; code None while
the command runs.
job: an operator command that exited 0, its task operator/<slug>.
host: the operator's shell, operator.py and council.
Returns:
The exit code.
Whether the row's check passes on this host, from `operator.py
checked <slug>` in the operator's shell as `operator.py run` sees it;
None without --operator, for a task whose slug signing.TASK does not
match, or when that call cannot tell.
"""
return spawn(["bash", "-c", job["command"]], job["directory"], None, report)
task = job.get("task")
if host.operator is None or not isinstance(task, str) or not task.startswith(OPERATOR) or not signing.TASK.fullmatch(task.removeprefix(OPERATOR)):
return None
council = [f"AGENTS_COUNCIL_ROOT={host.council}"] if host.council else []
command = shlex.join(["env", *council, sys.executable, "-I", "-B", str(host.operator), "checked", task.removeprefix(OPERATOR)])
try:
code = subprocess.run([host.shell, "-ic", command], cwd="/", stdin=subprocess.DEVNULL, capture_output=True, timeout=TASK_LIMIT, check=False, start_new_session=True).returncode
except (OSError, subprocess.TimeoutExpired):
return None
return {0: True, 1: False}.get(code)
def execute(job: dict, host: Host, report: Callable[[dict], None]) -> int:
"""Args:
job: the claimed and verified job with task, command and directory.
host: the operator's shell, operator.py and council.
report: called with {"output", "code", "refused"}; code None while
the command runs; after exit 0 also "checked" from checked().
Returns:
The exit code of `$SHELL -ic <command>` in the signed directory.
"""
def final(result: dict) -> None:
report({**result, "checked": checked(job, host)} if result["code"] == 0 else result)
return spawn([host.shell, "-ic", job["command"]], job["directory"], None, final)
def change(job: dict, register: Register, report: Callable[[dict], None]) -> int:
@@ -338,7 +385,7 @@ def sender(base: str, job_id: str) -> Callable[[dict], None]:
return send
def cycle(base: str, trust: verifier.Trust, register: Register | None, gates: Path | None = None) -> None:
def cycle(base: str, trust: verifier.Trust, register: Register | None, gates: Path | None, host: Host) -> None:
for job in call(base, "/api/runner/jobs", None)["jobs"]:
try:
claimed = call(base, f"/api/runner/{job['id']}/claim", {})
@@ -359,7 +406,7 @@ def cycle(base: str, trust: verifier.Trust, register: Register | None, gates: Pa
elif kind == GATE_JOB:
gate(claimed, gates, send)
else:
execute(claimed, send)
execute(claimed, host, send)
def main() -> int:
@@ -371,11 +418,13 @@ def main() -> int:
parser.add_argument("--rasci", type=Path)
parser.add_argument("--council", type=Path)
parser.add_argument("--gates", type=Path)
parser.add_argument("--operator", type=Path)
parser.add_argument("--once", action="store_true")
args = parser.parse_args()
base = hub_api.base_url(args.port)
trust = verifier.Trust(approvers=args.approvers, replay=args.replay, origin=signing.origin_of(args.port))
register = Register(rasci=args.rasci, council=args.council) if args.rasci and args.council else None
host = Host(shell=os.environ.get("SHELL") or pwd.getpwuid(os.geteuid()).pw_shell, operator=args.operator, council=args.council)
rules, told = staged_diff.rules_root(), ""
while True:
try:
@@ -386,7 +435,7 @@ def main() -> int:
print(f"runner: no merge previews: {error}", file=sys.stderr)
told = str(error)
try:
cycle(base, trust, register, args.gates)
cycle(base, trust, register, args.gates, host)
except (OSError, ValueError, KeyError, TypeError):
pass
if args.once: