Bound semantic worker storage and add verified evidence closeout
This commit is contained in:
@@ -9,6 +9,7 @@ import time
|
||||
from pathlib import Path
|
||||
|
||||
from core_client import CoreRequestRejected
|
||||
from evidence_closeout import canonical, closeout, usage
|
||||
from infrastructure_containers import cleanup, docker, run_container
|
||||
from infrastructure_gaussian_sources import prepare_native
|
||||
from infrastructure_pipeline import MODULE, run_pipeline
|
||||
@@ -84,9 +85,24 @@ def reconcile(client, marker, hello=None):
|
||||
)
|
||||
record.pop("completion")
|
||||
write_json(marker, record)
|
||||
registered_request(
|
||||
client, endpoint, dict(action="release", previous_owner=record["owner"]), hello=hello
|
||||
)
|
||||
if not record.get("released"):
|
||||
registered_request(
|
||||
client, endpoint, dict(action="release", previous_owner=record["owner"]), hello=hello
|
||||
)
|
||||
record["released"] = True
|
||||
write_json(marker, record)
|
||||
retention = record.get("retention")
|
||||
if retention:
|
||||
# Retain this durable marker across restart until archival and unlink
|
||||
# finish. Core ACK alone must never discard the cleanup obligation.
|
||||
closeout(
|
||||
Path(retention["root"]),
|
||||
Path(retention["archive_root"]),
|
||||
record["key"],
|
||||
keep=("urban-map.json", "publication-request.json", "failure.json"),
|
||||
limit=retention["archive_limit"],
|
||||
reserve=retention["reserve"],
|
||||
)
|
||||
marker.unlink()
|
||||
|
||||
|
||||
@@ -112,18 +128,36 @@ def prepare_infrastructure(client, row, state, marker, hello=None):
|
||||
if row["identity"]["provider_sha256"] != provider_identity():
|
||||
raise ValueError("Infrastructure provider changed")
|
||||
runtime = state.parent
|
||||
output = Path(profile["job_root"]) / row["key"]
|
||||
output = canonical(Path(profile["job_root"]) / row["key"])
|
||||
existing = output.exists() and any(output.iterdir())
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
write_json(marker, dict(key=row["key"], owner=client.instance, containers=[]))
|
||||
retention = None
|
||||
if not existing and profile.get("archive_root"):
|
||||
retention = dict(
|
||||
root=str(output),
|
||||
archive_root=profile["archive_root"],
|
||||
archive_limit=profile["archive_limit_gib"] * 1024**3,
|
||||
reserve=profile["minimum_free_gib"] * 1024**3,
|
||||
)
|
||||
write_json(
|
||||
marker, dict(key=row["key"], owner=client.instance, containers=[], retention=retention)
|
||||
)
|
||||
endpoint = "/worker/infrastructure-analysis/" + row["key"]
|
||||
last_pulse = -float("inf")
|
||||
connected = True
|
||||
last_storage_check = -float("inf")
|
||||
phase = dict(phase="preparing", completed=0, total=0)
|
||||
|
||||
def pulse():
|
||||
nonlocal last_pulse, phase, connected
|
||||
nonlocal last_pulse, phase, connected, last_storage_check
|
||||
if time.monotonic() - last_pulse < 3:
|
||||
return
|
||||
if time.monotonic() - last_storage_check >= 20 and profile.get("maximum_job_gib"):
|
||||
if usage(output) > profile["maximum_job_gib"] * 1024**3:
|
||||
raise RuntimeError("Infrastructure job storage limit reached")
|
||||
if shutil.disk_usage(output).free < profile["minimum_free_gib"] * 1024**3:
|
||||
raise RuntimeError("Infrastructure storage reserve reached")
|
||||
last_storage_check = time.monotonic()
|
||||
progress = output / "progress.json"
|
||||
if progress.exists():
|
||||
with contextlib.suppress(ValueError, OSError):
|
||||
@@ -139,6 +173,23 @@ def prepare_infrastructure(client, row, state, marker, hello=None):
|
||||
last_pulse = time.monotonic()
|
||||
|
||||
try:
|
||||
if existing:
|
||||
raise RuntimeError(
|
||||
"Existing infrastructure output is immutable; use a new job identity"
|
||||
)
|
||||
if profile.get("maximum_jobs_gib"):
|
||||
reserved = profile["maximum_job_gib"] * 1024**3
|
||||
if usage(output.parent) + reserved > profile["maximum_jobs_gib"] * 1024**3:
|
||||
raise RuntimeError("Infrastructure jobs storage quota reached")
|
||||
archive_root = Path(profile["archive_root"])
|
||||
archive_root.mkdir(parents=True, exist_ok=True)
|
||||
if usage(archive_root) + reserved > profile["archive_limit_gib"] * 1024**3:
|
||||
raise RuntimeError("Infrastructure archive quota reached")
|
||||
if (
|
||||
shutil.disk_usage(archive_root).free
|
||||
< reserved + profile["minimum_free_gib"] * 1024**3
|
||||
):
|
||||
raise RuntimeError("Infrastructure archive reserve reached")
|
||||
if shutil.disk_usage(output).free < profile["minimum_free_gib"] * 1024**3:
|
||||
raise RuntimeError("Insufficient space for Gaussian analysis results")
|
||||
pulse()
|
||||
@@ -182,7 +233,13 @@ def prepare_infrastructure(client, row, state, marker, hello=None):
|
||||
write_json(marker, record)
|
||||
except Exception as exc:
|
||||
logging.exception("Infrastructure analysis failed")
|
||||
write_json(output / "failure.json", dict(type=type(exc).__name__, message=str(exc)))
|
||||
failure = dict(type=type(exc).__name__, message=str(exc))
|
||||
if existing:
|
||||
record = read_json(marker)
|
||||
record["rejected_existing_output"] = failure
|
||||
write_json(marker, record)
|
||||
else:
|
||||
write_json(output / "failure.json", failure)
|
||||
try:
|
||||
registered_request(client, endpoint, dict(action="fail"), hello=hello)
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user