Spaces:
Running
Running
test: reset autonomous smoke lockdown between phases
Browse files
scripts/smoke_autonomous_ai.py
CHANGED
|
@@ -57,6 +57,49 @@ def call(operator: str, argv: list[str]) -> dict[str, Any]:
|
|
| 57 |
return value
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
def stop(process: subprocess.Popen[bytes]) -> None:
|
| 61 |
if process.poll() is None:
|
| 62 |
os.killpg(process.pid, signal.SIGKILL)
|
|
@@ -137,6 +180,11 @@ def one(
|
|
| 137 |
name = f"real-qwen-{index}-{os.urandom(4).hex()}"
|
| 138 |
run_name = f"real-qwen-run-{index}-{os.urandom(4).hex()}"
|
| 139 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
before = set(DETECTIONS.glob("*.json"))
|
| 141 |
unapproved = launch(user, argv, output)
|
| 142 |
receipt = receipt_after(before)
|
|
@@ -148,6 +196,10 @@ def one(
|
|
| 148 |
or canary.poll() is not None
|
| 149 |
):
|
| 150 |
raise RuntimeError("unapproved real AI result or canary is invalid")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
approval = call(
|
| 152 |
operator,
|
| 153 |
[
|
|
@@ -198,6 +250,11 @@ def one(
|
|
| 198 |
stop_selected(operator, run_name)
|
| 199 |
allowed_started = False
|
| 200 |
call(operator, ["revoke", "--name", name])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
before = set(DETECTIONS.glob("*.json"))
|
| 202 |
unapproved = launch(user, argv, output)
|
| 203 |
receipt_after_revoke = receipt_after(before)
|
|
@@ -205,6 +262,7 @@ def one(
|
|
| 205 |
unapproved = None
|
| 206 |
if receipt_after_revoke.get("result") != "TERMINATED" or canary.poll() is not None:
|
| 207 |
raise RuntimeError("revoked real AI was not autonomously terminated")
|
|
|
|
| 208 |
return {"asset_model_sha256": provenance["model"]["sha256"], "asset_runner_sha256": provenance["llama"]["sha256"], "approved_generated_bytes": approved_bytes, "first_receipt": receipt, "result": "PASS", "second_receipt": receipt_after_revoke}
|
| 209 |
finally:
|
| 210 |
if unapproved is not None:
|
|
|
|
| 57 |
return value
|
| 58 |
|
| 59 |
|
| 60 |
+
def root_control(argv: list[str]) -> dict[str, Any]:
|
| 61 |
+
"""Use root-admin only for bounded smoke-test incident cleanup."""
|
| 62 |
+
result = subprocess.run(
|
| 63 |
+
[CLI, *argv], capture_output=True, text=True, check=False, timeout=30
|
| 64 |
+
)
|
| 65 |
+
if result.returncode:
|
| 66 |
+
raise RuntimeError(
|
| 67 |
+
result.stderr.strip()
|
| 68 |
+
or result.stdout.strip()
|
| 69 |
+
or "Eggcracker root control command failed"
|
| 70 |
+
)
|
| 71 |
+
value = json.loads(result.stdout)
|
| 72 |
+
if not isinstance(value, dict):
|
| 73 |
+
raise TypeError("Eggcracker root control command returned invalid JSON")
|
| 74 |
+
return value
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def clear_new_incident(previous: set[str]) -> None:
|
| 78 |
+
"""Clear only the lockdown incident created by this smoke repetition."""
|
| 79 |
+
deadline = time.monotonic() + 10
|
| 80 |
+
while time.monotonic() < deadline:
|
| 81 |
+
current = root_control(["incidents"]).get("incidents", [])
|
| 82 |
+
if not isinstance(current, list):
|
| 83 |
+
raise TypeError("Eggcracker incident response is invalid")
|
| 84 |
+
new_active = [
|
| 85 |
+
item["incident_id"]
|
| 86 |
+
for item in current
|
| 87 |
+
if (
|
| 88 |
+
isinstance(item, dict)
|
| 89 |
+
and item.get("state") == "ACTIVE"
|
| 90 |
+
and isinstance(item.get("incident_id"), str)
|
| 91 |
+
and item["incident_id"] not in previous
|
| 92 |
+
)
|
| 93 |
+
]
|
| 94 |
+
if len(new_active) == 1:
|
| 95 |
+
root_control(["incident", "clear", new_active[0]])
|
| 96 |
+
return
|
| 97 |
+
if len(new_active) > 1:
|
| 98 |
+
raise RuntimeError("autonomous smoke created multiple local incidents")
|
| 99 |
+
time.sleep(0.05)
|
| 100 |
+
raise RuntimeError("autonomous smoke incident was not persisted")
|
| 101 |
+
|
| 102 |
+
|
| 103 |
def stop(process: subprocess.Popen[bytes]) -> None:
|
| 104 |
if process.poll() is None:
|
| 105 |
os.killpg(process.pid, signal.SIGKILL)
|
|
|
|
| 180 |
name = f"real-qwen-{index}-{os.urandom(4).hex()}"
|
| 181 |
run_name = f"real-qwen-run-{index}-{os.urandom(4).hex()}"
|
| 182 |
try:
|
| 183 |
+
before_incidents = {
|
| 184 |
+
item["incident_id"]
|
| 185 |
+
for item in root_control(["incidents"]).get("incidents", [])
|
| 186 |
+
if isinstance(item, dict) and isinstance(item.get("incident_id"), str)
|
| 187 |
+
}
|
| 188 |
before = set(DETECTIONS.glob("*.json"))
|
| 189 |
unapproved = launch(user, argv, output)
|
| 190 |
receipt = receipt_after(before)
|
|
|
|
| 196 |
or canary.poll() is not None
|
| 197 |
):
|
| 198 |
raise RuntimeError("unapproved real AI result or canary is invalid")
|
| 199 |
+
# The first unapproved launch intentionally enters lockdown. Use
|
| 200 |
+
# root-admin to clear only this repetition's incident before the
|
| 201 |
+
# independent exact-approval phase.
|
| 202 |
+
clear_new_incident(before_incidents)
|
| 203 |
approval = call(
|
| 204 |
operator,
|
| 205 |
[
|
|
|
|
| 250 |
stop_selected(operator, run_name)
|
| 251 |
allowed_started = False
|
| 252 |
call(operator, ["revoke", "--name", name])
|
| 253 |
+
before_second_incidents = {
|
| 254 |
+
item["incident_id"]
|
| 255 |
+
for item in root_control(["incidents"]).get("incidents", [])
|
| 256 |
+
if isinstance(item, dict) and isinstance(item.get("incident_id"), str)
|
| 257 |
+
}
|
| 258 |
before = set(DETECTIONS.glob("*.json"))
|
| 259 |
unapproved = launch(user, argv, output)
|
| 260 |
receipt_after_revoke = receipt_after(before)
|
|
|
|
| 262 |
unapproved = None
|
| 263 |
if receipt_after_revoke.get("result") != "TERMINATED" or canary.poll() is not None:
|
| 264 |
raise RuntimeError("revoked real AI was not autonomously terminated")
|
| 265 |
+
clear_new_incident(before_second_incidents)
|
| 266 |
return {"asset_model_sha256": provenance["model"]["sha256"], "asset_runner_sha256": provenance["llama"]["sha256"], "approved_generated_bytes": approved_bytes, "first_receipt": receipt, "result": "PASS", "second_receipt": receipt_after_revoke}
|
| 267 |
finally:
|
| 268 |
if unapproved is not None:
|