An open-source, faster Devin alternative
TypeScript
fix(deploy): prove builds through long exec sessions
Igor Zalutskibc8366848e07
diff --git a/ci/flue-builder-substrate-probe.py b/ci/flue-builder-substrate-probe.pyindex 35e47d0c..777e4a30 100755--- a/ci/flue-builder-substrate-probe.py+++ b/ci/flue-builder-substrate-probe.py@@ -235,6 +235,88 @@ class LiveProbe:delay = min(delay * 2, 2.0)raise ProbeError("async exec result exceeded the bounded client wait")+ def exec_long(+ self,+ sandbox_id: str,+ command: str,+ args: list[str] | None = None,+ envs: dict[str, str] | None = None,+ timeout: int = 600,+ ) -> dict[str, Any]:+ """Run via the public long-lived exec-session/list contract.++ The result-handle API is suitable for short commands, but production+ workers may forget a handle during a long build. Exec sessions are the+ public reattachable/background surface; this probe needs only the exit+ code, so it polls the session list without transporting output.+ """+ body: dict[str, Any] = {+ "cmd": command,+ "args": args or [],+ "timeout": timeout,+ "maxRunAfterDisconnect": timeout + 90,+ }+ if envs is not None:+ body["envs"] = envs+ quoted = parse.quote(sandbox_id, safe="")+ _, started = self.call(+ "POST",+ f"/sandboxes/{quoted}/exec",+ body,+ allowed_statuses={200, 201, 202},+ timeout=60,+ )+ if not isinstance(started, dict) or not isinstance(started.get("sessionID"), str):+ raise ProbeError("long exec response is missing sessionID")+ session_id = started["sessionID"]+ deadline = time.monotonic() + timeout + 90+ delay = 0.2+ seen = False+ while time.monotonic() < deadline:+ _, sessions = self.call(+ "GET",+ f"/sandboxes/{quoted}/exec",+ allowed_statuses={200},+ timeout=30,+ )+ if not isinstance(sessions, list):+ raise ProbeError("long exec session list is invalid")+ current = next(+ (+ item for item in sessions+ if isinstance(item, dict) and item.get("sessionID") == session_id+ ),+ None,+ )+ if current is not None:+ seen = True+ if not isinstance(current.get("running"), bool):+ raise ProbeError("long exec session state is invalid")+ if not current["running"]:+ if not isinstance(current.get("exitCode"), int):+ raise ProbeError("long exec session is missing exitCode")+ return {+ "exitCode": current["exitCode"],+ "stdout": "",+ "stderr": "",+ }+ elif seen:+ raise ProbeError("long exec session disappeared")+ time.sleep(delay)+ delay = min(delay * 2, 2.0)+ try:+ encoded = parse.quote(session_id, safe="")+ self.call(+ "POST",+ f"/sandboxes/{quoted}/exec/{encoded}/kill",+ {"signal": 9},+ allowed_statuses={200, 204},+ timeout=30,+ )+ except ProbeError:+ pass+ raise ProbeError("long exec session exceeded the bounded client wait")+def read_guest_file(self, sandbox_id: str, path: str, max_bytes: int = 512 * 1024) -> bytes:quoted_id = parse.quote(sandbox_id, safe="")quoted_path = parse.quote(path, safe="")@@ -328,7 +410,7 @@ test "$(git -C "$root" rev-parse HEAD)" = "$2"}self.expect_success("pinned public starter checkout",- self.exec(+ self.exec_long(sandbox_id,"/bin/bash",["-c", prepare, "probe", STARTER_REPO, STARTER_REF],@@ -338,7 +420,7 @@ test "$(git -C "$root" rev-parse HEAD)" = "$2")self.expect_success("public npm install",- self.exec(+ self.exec_long(sandbox_id,"/bin/bash",["-c", "cd /workspace/flue-builder-probe && npm ci --no-audit --no-fund"],@@ -348,7 +430,7 @@ test "$(git -C "$root" rev-parse HEAD)" = "$2")self.expect_success("golden Flue artifact build",- self.exec(+ self.exec_long(sandbox_id,"/bin/bash",[diff --git a/ci/test_flue_builder_substrate_probe.py b/ci/test_flue_builder_substrate_probe.pyindex 9248ce52..67213e48 100644--- a/ci/test_flue_builder_substrate_probe.py+++ b/ci/test_flue_builder_substrate_probe.py@@ -156,6 +156,63 @@ class SandboxProbeTest(unittest.TestCase):],)+ def test_long_exec_uses_the_public_reattachable_session_contract(self) -> None:+ live = PROBE.LiveProbe.__new__(PROBE.LiveProbe)+ calls: list[tuple[str, str, object]] = []+ responses = iter(+ [+ (201, {"sessionID": "session-long"}),+ (200, [{"sessionID": "session-long", "running": True}]),+ (+ 200,+ [{"sessionID": "session-long", "running": False, "exitCode": 0}],+ ),+ ]+ )++ def fake_call(+ method: str,+ path: str,+ body: object = None,+ allowed_statuses: set[int] | None = None,+ timeout: float = 60,+ ) -> tuple[int, object]:+ calls.append((method, path, body))+ return next(responses)++ live.call = fake_call+ with mock.patch.object(PROBE.time, "sleep"):+ result = live.exec_long(+ "sb-test",+ "/bin/sh",+ ["-c", "long-build"],+ {"CI": "1"},+ timeout=600,+ )++ self.assertEqual(result["exitCode"], 0)+ self.assertEqual(+ calls[0],+ (+ "POST",+ "/sandboxes/sb-test/exec",+ {+ "cmd": "/bin/sh",+ "args": ["-c", "long-build"],+ "timeout": 600,+ "maxRunAfterDisconnect": 690,+ "envs": {"CI": "1"},+ },+ ),+ )+ self.assertEqual(+ [call[:2] for call in calls[1:]],+ [+ ("GET", "/sandboxes/sb-test/exec"),+ ("GET", "/sandboxes/sb-test/exec"),+ ],+ )+def test_destroy_attempts_every_created_sandbox(self) -> None:live = PROBE.LiveProbe.__new__(PROBE.LiveProbe)live.sandboxes = ["sb-one", "sb-two"]diff --git a/deploy/flue-builder/README.md b/deploy/flue-builder/README.mdindex 2646755f..4e68975c 100644--- a/deploy/flue-builder/README.md+++ b/deploy/flue-builder/README.md@@ -114,7 +114,9 @@ The guarded live probe:3. verifies the exact Node, npm, and `oc` versions/digests and a writable`/workspace`;4. fetches the pinned public starter;-5. runs `npm ci` through the public asynchronous exec/result contract;+5. runs `npm ci` and the golden build through the public long-lived+ exec-session/list contract, while short attestation commands use the public+ asynchronous result contract;6. reproduces the golden Flue artifact with the pinned `oc`; and7. confirms coordinator credential sentinels were not passed into the sandbox.