Files
MeltMind/tools/phase3_followup_postfit_recovery_common.py
T

74 lines
3.3 KiB
Python

"""Route the labelled replacement bindings and account for c's original zero-worker stop."""
from pathlib import Path
from phase2_gate_outcome_review import validate_review
from phase2_h1_worker_v2 import checked, sha
from phase2_home_freeze_io import verify
from phase3_followup_postfit_common import config as old_config, read, root_for
RULING = 'h-fc56663d'
ORIGINAL_BINDINGS = {
'c': 'c00d177fb115e8942e2c86ffc5ac83197c5382a31518f20362a163166486b564',
'b': '7ea2f073097926cdd56fb84de286271a984619019d5a3df6fa5a2c3cc8802451',
}
def recovery_root(item):
return root_for(item).with_name(f'phase3-item-{item}-postfit-idle-recovery-2026-11-19')
def contract_delta(original, revised):
expected = dict(original, idle_wait_seconds=20, code_sha256=revised['code_sha256'])
if revised != expected or 'idle_wait_seconds' in original or type(revised['idle_wait_seconds']) is not int:
raise ValueError('Only the fixed idle field and recovery code identity may differ')
def accounting(item):
original = root_for(item)
binding = original/'expected-review-binding.json'
checked(binding,ORIGINAL_BINDINGS[item])
base = dict(item=item, approval=RULING, original_root=str(original), original_binding_sha256=sha(binding),
original_review_sha256=sha(original/'review.json'), predicted_parts=0, target_accesses=0,
prior_gpu_seconds=0., prior_cpu_seconds=0., no_second_recovery=True)
if (original/'score').exists() or (original/'predictions-manifest.json').exists() or list(original.rglob('worker.started.json')):
raise PermissionError('Original candidate used its scientific access')
if item=='b':
if any((original/n).exists() for n in ('started.json','complete.json','jobs')):
raise PermissionError('Original b must remain unattempted')
return base
complete = original/'complete.json'
guard_path = original/'jobs/0/prediction-guard.json'
stop = read(complete)
guard = read(guard_path)
if (stop['status']!='STOPPED' or stop['reason']!='RuntimeError: Fold 0 prediction stop'
or len(stop['records'])!=1 or stop['records'][0]['fold']!=0
or stop['records'][0]['guard']!=guard or guard['worker'] is not None
or guard['reasons'][0]!="KeyError: 'idle_wait_seconds'"):
raise ValueError('Wrong original c infrastructure failure')
return dict(base, original_terminal_sha256=sha(complete), original_guard_sha256=sha(guard_path),
prior_gpu_seconds=stop['prediction_gpu_seconds'], prior_cpu_seconds=stop['postfit_cpu_seconds'])
def prior_stop(root):
path = root/'recovery-accounting.json'
receipt = read(path)
proof = verify(root,'implementation')
checked(path,proof['files'][str(path.resolve())])
if receipt!=accounting(receipt['item']):
raise ValueError('Original stop or held b state changed')
return receipt['prior_gpu_seconds'],receipt['prior_cpu_seconds']
def config(root, *, review=True):
c = read(root/'contract.json')
item = c['item']
if root.resolve()!=recovery_root(item):
raise PermissionError('Only the recovery-labelled roots are approved')
verify(root,'implementation')
if review:
validate_review(root)
old,tc,pilot,by = old_config(root_for(item))
contract_delta(old,c)
prior_stop(root)
return c,tc,pilot,by