Restore complete LAB recordings from verified Worker publications
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Bounded, cached native replay packaging on Core; no inference or Worker IO."""
|
||||
"""Ready Worker replay restoration with bounded legacy native packaging."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -12,6 +12,7 @@ import tempfile
|
||||
import threading
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Callable
|
||||
from contextlib import nullcontext
|
||||
from pathlib import Path
|
||||
from typing import Any, cast
|
||||
|
||||
@@ -26,8 +27,8 @@ from k1link.laboratory.canonical_rerun_overlay import (
|
||||
canonical_lab_replay,
|
||||
canonical_recording_id,
|
||||
)
|
||||
from k1link.laboratory.local_presentations import LOCK as PRESENTATION_LOCK
|
||||
from k1link.laboratory.local_presentations import LocalPresentations
|
||||
from k1link.laboratory.replay_restore import WorkerReplayRestore
|
||||
from k1link.observatory.portable_object_replay import (
|
||||
RENDERER_VERSION as OBJECT_RENDERER_VERSION,
|
||||
)
|
||||
@@ -71,13 +72,16 @@ class PortableReplayService:
|
||||
recording_source: Callable[[str], tuple[Path, str] | None],
|
||||
ffmpeg_path: Path,
|
||||
local_copies: LocalPresentations | None = None,
|
||||
remote_replays: WorkerReplayRestore | None = None,
|
||||
) -> None:
|
||||
self.view = view
|
||||
self.data_dir = data_dir
|
||||
self.media = media
|
||||
self.recording_source = recording_source
|
||||
self.ffmpeg_path = ffmpeg_path
|
||||
self.cache = data_dir / "observatory-portable-replay-cache"
|
||||
self.cache = (local_copies.root if local_copies else
|
||||
data_dir / "observatory-portable-replay-cache")
|
||||
self.remote_replays = remote_replays
|
||||
self.local_copies = local_copies
|
||||
self._verified: OrderedDict[tuple[Path, str], tuple[int, ...]] = OrderedDict()
|
||||
|
||||
@@ -144,11 +148,17 @@ class PortableReplayService:
|
||||
def prepare(self, result_id: str, base_sha: str) -> CanonicalLabReplayArtifact:
|
||||
# Serialize packaging on the constrained operator host, including
|
||||
# concurrent clicks. Waiting readers cannot start a duplicate render.
|
||||
with PRESENTATION_LOCK, _LOCK:
|
||||
with _LOCK, (self.local_copies.use(result_id) if self.local_copies else nullcontext()):
|
||||
cached = self.cached(result_id, base_sha)
|
||||
if cached is not None:
|
||||
return cached
|
||||
key, view = self._key(result_id, base_sha)
|
||||
if self.remote_replays is not None:
|
||||
restored = self.remote_replays.restore(result_id, base_sha, key, self.cache)
|
||||
if restored is not None:
|
||||
if self.local_copies is not None:
|
||||
self.local_copies.register(result_id, restored, self.cache / f"{key}.json")
|
||||
return restored
|
||||
base = self.recording_source(view["source_session_id"])
|
||||
if base is None or base[1] != base_sha:
|
||||
raise PortableReplayError("source recording generation is not ready")
|
||||
@@ -322,11 +332,17 @@ class PortableReplayService:
|
||||
def prepare_composition(
|
||||
self, run_id: str, result_ids: tuple[str, ...], base_sha: str
|
||||
) -> CanonicalLabReplayArtifact:
|
||||
with PRESENTATION_LOCK, _LOCK:
|
||||
with _LOCK, (self.local_copies.use(run_id) if self.local_copies else nullcontext()):
|
||||
cached = self.cached_composition(run_id, result_ids, base_sha)
|
||||
if cached is not None:
|
||||
return cached
|
||||
key, views = self._composition_key(run_id, result_ids, base_sha)
|
||||
if self.remote_replays is not None:
|
||||
restored = self.remote_replays.restore(run_id, base_sha, key, self.cache)
|
||||
if restored is not None:
|
||||
if self.local_copies is not None:
|
||||
self.local_copies.register(run_id, restored, self.cache / f"{key}.json")
|
||||
return restored
|
||||
source_session_id = cast(str, views[0]["source_session_id"])
|
||||
base = self.recording_source(source_session_id)
|
||||
if base is None or base[1] != base_sha:
|
||||
|
||||
Reference in New Issue
Block a user