chore(storage): bound build retention, caches and test resources

Track build ownership, qualified pins and bounded cache/log lifecycles. Move Vite fixtures to a job-owned server helper and preserve private outputs outside Git.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:09:58 +03:00
parent 55f64f195b
commit 70ef3f9f1c
119 changed files with 3128 additions and 331 deletions
+35 -23
View File
@@ -18,6 +18,7 @@ import rerun as rr
from rerun.components import FillMode
from k1link.artifacts import write_json_atomic
from k1link.cache_budget import cache_publication, require_cache_room
from k1link.sessions import SessionIntegrityError
from .jobs import CameraComputeJob, validate_camera_compute_job
@@ -104,31 +105,43 @@ class RecordedCalibratedFusionStore:
cached = _read_cache(output, sidecar, fusion, recording_id)
if cached is not None:
return cached
require_cache_room(
self.cache_root,
65536,
kind="calibrated-fusion-overlays",
error_type=RecordedPerceptionOverlayError,
)
payload = _render_fusion(
fusion,
application_id=application_id,
recording_id=recording_id,
)
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
try:
with temporary.open("xb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.chmod(temporary, 0o600)
os.replace(temporary, output)
write_json_atomic(
sidecar,
{
"schema_version": "missioncore.calibrated-fusion-overlay-cache/v1",
"fusion_id": fusion.fusion_id,
"recording_id": recording_id,
"byte_length": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
finally:
temporary.unlink(missing_ok=True)
with cache_publication(
self.cache_root,
len(payload) + 65536,
kind="calibrated-fusion-overlays",
error_type=RecordedPerceptionOverlayError,
):
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
try:
with temporary.open("xb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.chmod(temporary, 0o600)
os.replace(temporary, output)
write_json_atomic(
sidecar,
{
"schema_version": "missioncore.calibrated-fusion-overlay-cache/v1",
"fusion_id": fusion.fusion_id,
"recording_id": recording_id,
"byte_length": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
finally:
temporary.unlink(missing_ok=True)
return payload
def _latest(self, session_id: str) -> RecordedCalibratedFusion | None:
@@ -540,9 +553,8 @@ def _read_labels(path: Path) -> list[str]:
value = json.loads(path.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
raise SessionIntegrityError("calibrated fusion labels are unavailable") from exc
if (
not isinstance(value, list)
or any(not isinstance(item, str) or not 1 <= len(item) <= 256 for item in value)
if not isinstance(value, list) or any(
not isinstance(item, str) or not 1 <= len(item) <= 256 for item in value
):
raise SessionIntegrityError("calibrated fusion labels are invalid")
return value
+56 -39
View File
@@ -28,6 +28,7 @@ from k1link.artifact_gateway import (
ArtifactStoreUnavailable,
)
from k1link.artifacts import write_json_atomic
from k1link.cache_budget import CacheCapacityError, cache_publication, require_cache_room
from k1link.sessions import SessionIntegrityError
from .jobs import CameraComputeJob, validate_camera_compute_job
@@ -498,6 +499,12 @@ class IntegratedPerceptionOverlayStore:
)
return cached
self._set_status(key, state="preparing", phase="rendering")
require_cache_room(
self.cache_root,
65536,
kind="integrated-perception-overlays",
error_type=RecordedPerceptionOverlayError,
)
payload = _render(
result,
application_id=application_id,
@@ -506,29 +513,35 @@ class IntegratedPerceptionOverlayStore:
temporary_root=cache,
)
self._set_status(key, state="preparing", phase="cache-write")
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
try:
with temporary.open("xb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.chmod(temporary, 0o600)
os.replace(temporary, output)
write_json_atomic(
sidecar,
{
"schema_version": OVERLAY_CACHE_SCHEMA,
"renderer_version": OVERLAY_RENDERER_VERSION,
"session_id": session_id,
"result_id": result.result_id,
"result_created_at_utc": result.created_at_utc,
"recording_id": recording_id,
"byte_length": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
finally:
temporary.unlink(missing_ok=True)
with cache_publication(
self.cache_root,
len(payload) + 65536,
kind="integrated-perception-overlays",
error_type=RecordedPerceptionOverlayError,
):
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
try:
with temporary.open("xb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.chmod(temporary, 0o600)
os.replace(temporary, output)
write_json_atomic(
sidecar,
{
"schema_version": OVERLAY_CACHE_SCHEMA,
"renderer_version": OVERLAY_RENDERER_VERSION,
"session_id": session_id,
"result_id": result.result_id,
"result_created_at_utc": result.created_at_utc,
"recording_id": recording_id,
"byte_length": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
finally:
temporary.unlink(missing_ok=True)
self._set_status(
key,
state="ready",
@@ -770,9 +783,7 @@ class IntegratedPerceptionOverlayStore:
or descriptor.result_id != result.result_id
or descriptor.created_at_utc != result.created_at_utc
):
raise RecordedPerceptionOverlayError(
"integrated perception admission identity changed"
)
raise RecordedPerceptionOverlayError("integrated perception admission identity changed")
cache_root = _private_directory(self.cache_root)
session_cache = _private_child(cache_root, descriptor.session_id)
self._write_admission_document(
@@ -790,17 +801,24 @@ class IntegratedPerceptionOverlayStore:
session_cache: Path,
admission: _OverlayAdmission,
) -> None:
write_json_atomic(
session_cache / "admission.json",
{
"schema_version": OVERLAY_ADMISSION_SCHEMA,
"renderer_version": OVERLAY_RENDERER_VERSION,
"session_id": admission.session_id,
"result_id": admission.result_id,
"result_json_sha256": admission.result_json_sha256,
"result_created_at_utc": admission.result_created_at_utc,
},
)
try:
with cache_publication(
session_cache.parent, 65536, kind="integrated-perception-overlays"
):
write_json_atomic(
session_cache / "admission.json",
{
"schema_version": OVERLAY_ADMISSION_SCHEMA,
"renderer_version": OVERLAY_RENDERER_VERSION,
"session_id": admission.session_id,
"result_id": admission.result_id,
"result_json_sha256": admission.result_json_sha256,
"result_created_at_utc": admission.result_created_at_utc,
},
)
except CacheCapacityError:
# A full disk cache must not prevent recovery of an already sealed overlay.
pass
def _latest_descriptor(self, session_id: str) -> _ResultDescriptor | None:
try:
@@ -1274,8 +1292,7 @@ def _read_result_descriptor(result_root: Path) -> _ResultDescriptor:
or root.name != f"e10-integrated-perception-{identity_sha256}"
or hashlib.sha256(_canonical_json(identity)).hexdigest() != identity_sha256
or result.get("acceptance_state") != "accepted"
or result.get("publication_scope")
!= "recorded-integrated-realtime-qualification-only"
or result.get("publication_scope") != "recorded-integrated-realtime-qualification-only"
or not isinstance(session_id, str)
or _SAFE_RECORDING_ID.fullmatch(session_id) is None
or not isinstance(job_id, str)
+36 -33
View File
@@ -16,6 +16,7 @@ import numpy as np
import rerun as rr
from k1link.artifacts import write_json_atomic
from k1link.cache_budget import cache_publication, require_cache_room
from k1link.sessions import SessionIntegrityError
from .jobs import CameraComputeJob, validate_camera_compute_job
@@ -222,6 +223,12 @@ class RecordedPerceptionOverlayStore:
cached = _read_cached_overlay(output, sidecar, result)
if cached is not None:
return cached
require_cache_room(
self.cache_root,
65536,
kind="perception-overlays",
error_type=RecordedPerceptionOverlayError,
)
payload = _render_overlay(
result,
application_id=application_id,
@@ -229,26 +236,32 @@ class RecordedPerceptionOverlayStore:
ffmpeg_path=self.ffmpeg_path,
ffprobe_path=self.ffprobe_path,
)
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
try:
with temporary.open("xb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.chmod(temporary, 0o600)
os.replace(temporary, output)
write_json_atomic(
sidecar,
{
"schema_version": "missioncore.perception-overlay-cache/v1",
"result_id": result.result_id,
"recording_id": recording_id,
"byte_length": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
finally:
temporary.unlink(missing_ok=True)
with cache_publication(
self.cache_root,
len(payload) + 65536,
kind="perception-overlays",
error_type=RecordedPerceptionOverlayError,
):
temporary = output.with_name(f".{output.name}.{os.getpid()}.tmp")
try:
with temporary.open("xb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.chmod(temporary, 0o600)
os.replace(temporary, output)
write_json_atomic(
sidecar,
{
"schema_version": "missioncore.perception-overlay-cache/v1",
"result_id": result.result_id,
"recording_id": recording_id,
"byte_length": len(payload),
"sha256": hashlib.sha256(payload).hexdigest(),
},
)
finally:
temporary.unlink(missing_ok=True)
return payload
def _latest_result(self, session_id: str) -> RecordedPerceptionResult | None:
@@ -408,10 +421,7 @@ def _render_overlay(
f"{detection.class_name} · {detection.score:.0%}"
for detection in frame.detections
],
colors=[
_class_color(detection.class_id)
for detection in frame.detections
],
colors=[_class_color(detection.class_id) for detection in frame.detections],
show_labels=True,
),
)
@@ -431,16 +441,9 @@ def _render_overlay(
def _camera_source_bytes(job: CameraComputeJob) -> bytes:
epoch = (
job.job_root
/ "input"
/ "camera"
/ job.source_id
/ f"epoch-{job.codec_epoch}"
)
epoch = job.job_root / "input" / "camera" / job.source_id / f"epoch-{job.codec_epoch}"
paths = [epoch / "init.mp4"] + [
epoch / "segments" / f"{sequence}.m4s"
for sequence in range(1, job.segment_count + 1)
epoch / "segments" / f"{sequence}.m4s" for sequence in range(1, job.segment_count + 1)
]
total = sum(path.stat().st_size for path in paths)
if total > MAX_OVERLAY_SOURCE_BYTES: