Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
@@ -3,10 +3,44 @@
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def create_episode(state: Path, run_id: str, evidence_root: Path | None = None):
|
||||
"""Keep the canonical episode path while using explicit evidence storage.
|
||||
|
||||
A whole-episode junction preserves relative asset paths and the sealed
|
||||
evidence boundary. Existing episodes and targets are never reused.
|
||||
"""
|
||||
episode = state / run_id
|
||||
if evidence_root is None or evidence_root.resolve() == state.resolve():
|
||||
episode.mkdir(exist_ok=False)
|
||||
return episode
|
||||
if os.name != 'nt' or not evidence_root.is_absolute():
|
||||
raise ValueError('External episode storage requires an absolute Windows directory')
|
||||
for path in (episode, evidence_root):
|
||||
if any(c in str(path) for c in '&|<>^%!"\r\n'):
|
||||
raise ValueError('Unsupported episode storage path')
|
||||
if episode.exists() or episode.is_junction():
|
||||
raise FileExistsError(episode)
|
||||
evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
target = evidence_root / run_id
|
||||
target.mkdir(exist_ok=False)
|
||||
try:
|
||||
subprocess.run(['cmd.exe', '/d', '/c', 'mklink', '/J', str(episode), str(target)],
|
||||
check=True, capture_output=True, timeout=10)
|
||||
if not episode.is_junction() or episode.resolve() != target.resolve():
|
||||
raise RuntimeError('Episode storage junction identity mismatch')
|
||||
except BaseException:
|
||||
if episode.is_junction():
|
||||
os.rmdir(episode)
|
||||
target.rmdir() # Only our newly created, still-empty directory.
|
||||
raise
|
||||
return episode
|
||||
|
||||
|
||||
class StateChannel:
|
||||
"""Latest-value local IPC using SQLite WAL, available in both Python hosts.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user