import pathlib,hashlib,json,shutil,subprocess,datetime root=pathlib.Path('/home/ps/huobao-gpu-selection');manifest=json.loads((root/'panel-routing-manifest.json').read_text()) old=""" if any(d.get('torch_vram_total', 0) > 1024**3 for d in stats.json().get('devices', [])): return None""" new=""" if any(d.get('torch_vram_total', 0) > 1024**3 for d in stats.json().get('devices', [])): # Release only idle model caches; queue contents and results stay intact. released = await client.post(f'{legacy.base_url}/free', json={'unload_models': True, 'free_memory': True}, headers=provider_headers(legacy)) released.raise_for_status() return None""" for short,name in [('general','canvas-h3-prompt-normalizer-healthy-20261026'),('vdn','huobao-vdn-normalizer')]: p=root/(name+'.candidate.py');assert hashlib.sha256(p.read_bytes()).hexdigest()==manifest[short]['after'] source=p.read_text();assert source.count(old)==1 shutil.copy2(p,root/(name+'.before-idle-release-'+datetime.datetime.now().strftime('%Y%m%d-%H%M%S')+'.py')) p.write_text(source.replace(old,new));subprocess.run(['docker','restart','--timeout','60',name],check=True,stdout=subprocess.DEVNULL) print('Idle cache release enabled:',name)