"""Hash-verified migration of THIS study's regenerable cache to roomy tmpfs. Stops/restarts only the validated study worker. Models, source dataset and live services are not migration targets. Original disk copies are removed only after verified copies exist. Persistent manifest records exact hashes and recovery. """ import json,os,shutil,signal,subprocess,sys,tempfile,time from pathlib import Path import numpy as np from .common import ROOT,WORK,FEATURES,atomic,digest def main(): if FEATURES.is_symlink():raise RuntimeError('Cache already redirected; inspect migration manifest before any further move') if not (WORK/'protocol.json').exists() or FEATURES.resolve()!=ROOT.parent/'.cache/speaker-v4': raise RuntimeError('Not the validated V4 cache') files=list(FEATURES.iterdir());allowed={'q.npy','scale.npy','filled.npy','provenance.json'} if any(p.is_symlink() or not p.is_file() or p.name not in allowed for p in files):raise RuntimeError('Unexpected cache contents; refusing migration') size=sum(p.stat().st_size for p in files) mem={k:int(v.split()[0])*1024 for k,v in (line.split(':',1) for line in Path('/proc/meminfo').read_text().splitlines())} if size>1_600_000_000 or shutil.disk_usage('/dev/shm').free