HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
environments: a build that stopped without recording its end reads as failed (#514)
github-actions[bot]b1c2724061d3
diff --git a/runner/environments.py b/runner/environments.pyindex e6f5d4f2..ac4426d8 100644--- a/runner/environments.py+++ b/runner/environments.py@@ -719,13 +719,35 @@ def build_record(env_id: str, n: int) -> dict | None:return None+def _build_running(env_id: str, n: int) -> bool:+ with _builds_lock:+ t = _builds.get(f"{env_id}:{int(n)}")+ return bool(t and t.is_alive())+++def _as_read(env_id: str, n: int, rec: dict) -> dict:+ """A record that says building with no build thread behind it is a build that stopped. The+ record is the build's only report, and the thread that writes it is gone: its last write failed+ (a full disk; _build swallows that one) or the runner restarted under it. Read as it lies, it+ said building to every read for good, and the gateway, which takes the environment's status+ from versions(), showed it building for good too. Both reads answer it as failed."""+ if rec.get("status") != "building" or _build_running(env_id, n):+ return rec+ try:+ stopped = int(os.path.getmtime(version_dir(env_id, n) / ".hr-build.json"))+ except OSError:+ stopped = int(time.time())+ return {**rec, "status": "failed", "stage": "", "finished_at": stopped,+ "error": "the build stopped before it recorded its end"}++def versions(env_id: str) -> list[dict]:root = env_dir(env_id) / "versions"out = []if root.is_dir():for e in sorted(root.iterdir(), key=lambda x: int(x.name) if x.name.isdigit() else 0):if e.name.isdigit():- rec = build_record(env_id, int(e.name)) or {"version": int(e.name), "status": "unknown"}+ rec = _as_read(env_id, int(e.name), build_record(env_id, int(e.name)) or {"version": int(e.name), "status": "unknown"})out.append({k: rec.get(k) for k in ("version", "status", "started_at", "finished_at", "error", "files", "bytes")} | {"packages": len(rec.get("packages") or [])})return out@@ -1261,7 +1283,7 @@ def r_build_status(env_id: str, version: int) -> dict:rec = build_record(env_id, int(version))if not rec:raise HTTPException(404, "no such build")- return rec+ return _as_read(env_id, int(version), rec)@router.get("/environments/{env_id}/versions")diff --git a/runner/tests/test_environments.py b/runner/tests/test_environments.pyindex 5822a99a..669b6788 100644--- a/runner/tests/test_environments.py+++ b/runner/tests/test_environments.py@@ -332,6 +332,35 @@ def test_a_build_whose_last_write_fails_leaves_the_active_version_as_it_was(storassert _wait("henv_n", 1)["status"] == "failed" and E.active_version("henv_n") is None+def test_a_build_that_stopped_without_recording_its_end_reads_as_failed(store, monkeypatch):+ """The record is the build's only report. When its last write fails (_build swallows that one)+ or the runner restarts under a build, the record says building with no thread behind it, and+ every read said building for good. The build's own read and the versions, which the gateway+ takes the environment's status from, answer it as failed; a build still running is building."""+ E.write_file("henv_s", "setup.sh", b"#!/bin/sh\necho preparing\nexit 3\n")+ real = E._write_record+ monkeypatch.setattr(E, "_write_record", lambda dst, rec: (_ for _ in ()).throw(OSError("no space left on device"))+ if rec.get("status") == "failed" else real(dst, rec))+ E.start_build("henv_s", 1, "stopped")+ for _ in range(960):+ with E._builds_lock:+ if "henv_s:1" not in E._builds:+ break+ time.sleep(0.25)+ assert E.build_record("henv_s", 1)["status"] == "building" # what the disk still says+ rec = E.r_build_status("henv_s", 1)+ assert rec["status"] == "failed" and rec["error"] == "the build stopped before it recorded its end"+ assert rec["stage"] == "" and rec["finished_at"] >= rec["started_at"]+ assert [(v["version"], v["status"]) for v in E.versions("henv_s")] == [(1, "failed")]++ class Alive:+ def is_alive(self):+ return True+ monkeypatch.setitem(E._builds, "henv_s:1", Alive()) # the same record while a build runs+ assert E.r_build_status("henv_s", 1)["status"] == "building"+ assert E.versions("henv_s")[0]["status"] == "building"++def test_the_turn_gets_the_path_the_variables_and_the_instructions(store):E.write_file("henv_t", "requirements.txt", b"")E.write_file("henv_t", "package.json", json.dumps({"name": "p", "version": "1.0.0", "private": True}).encode())