43 lines
5.0 KiB
Python
43 lines
5.0 KiB
Python
"""Rebind an unlaunched postfit after the same-review monitor-error correction."""
|
|
import json,re,shutil,subprocess,time
|
|
from pathlib import Path
|
|
from phase2_h1_worker_v2 import checked,sha,save
|
|
from phase2_home_freeze_io import freeze,verify
|
|
from phase3_item1_postfit_common import config,read
|
|
B=Path('/home/frank14f/optane/MeltMind');R=Path('/home/frank14f/MeltMind-runs/phase3-item1-postfit-2026-11-18');A=B/'artifacts/phase3-item1-postfit-monitor-fix-2026-11-18'
|
|
def main():
|
|
import psutil
|
|
if any((R/n).exists() for n in ['started.json','review.json','monitor-correction.json']):raise RuntimeError('Already launched/reviewed/revised; inspect rather than overwrite')
|
|
for p in psutil.process_iter(['cmdline']):
|
|
if any(Path(x).name in {'phase3_item1_postfit.py','phase3_item1_postfit_worker.py'} for x in p.info['cmdline'] or []):raise RuntimeError('Postfit process present')
|
|
checked(R/'contract.json','4229906e5d2a6e7febee84b932e2e45b817421f255127cbfb0fe66cc74d6e9aa');old=read(R/'contract.json');proof=read(A/'original-root/implementation-git-freeze.json')
|
|
if proof['commit']!='53cca79a47caebaa1ddb8a10e201c1b050dfa258':raise ValueError('Original review identity')
|
|
for p in (A/'original-root').iterdir():
|
|
if p.is_file() and sha(p)!=sha(R/p.name):raise ValueError('Original root not preserved exactly')
|
|
# Validate archived source bytes against the old immutable Git, independent of edited working paths.
|
|
for name in ['phase3_item1_postfit_guard.py','test_phase3_item1_postfit.py']:
|
|
data=subprocess.check_output(['git','-C',proof['local_repository'],'show',proof['commit']+':tools/'+name])
|
|
if data!=(A/'original-source'/name).read_bytes():raise ValueError('Original source archive differs')
|
|
train=Path(old['training_root']);tc=read(train/'contract.json');verify(train,'implementation')
|
|
for p,h in tc['code_sha256'].items():checked(p,h)
|
|
log=A/'synthetic-attempt1.log';text=log.read_text()
|
|
if 'Ran 29 tests' not in text or not text.rstrip().endswith('OK'):raise ValueError('Actual29 tests required')
|
|
codes=dict(old['code_sha256']);changed=[]
|
|
for p,h in codes.items():
|
|
now=sha(Path(p))
|
|
if now!=h:changed.append(p);codes[p]=now
|
|
expected={str(B/'tools/phase3_item1_postfit_guard.py'),str(B/'tools/test_phase3_item1_postfit.py'),str(B/'docs/phase3-item1-postfit-2026-11-18.md')}
|
|
if set(changed)!=expected:raise ValueError('Unexpected existing code-map changes')
|
|
me=B/'tools/revise_phase3_item1_postfit_monitor.py';codes[str(me)]=sha(me)
|
|
c=dict(old,code_sha256=codes,engineering_revision='MeltAssist1794952096 monitor-error wrapper correction',supersedes_unreviewed_implementation=proof['commit'],same_independent_review=True)
|
|
correction=dict(status='CORRECTED_PENDING_SAME_REVIEW_NOT_LAUNCHED',finding='1794952096.039169',old_implementation=proof['commit'],old_contract_sha256=sha(R/'contract.json'),old_binding_sha256=sha(R/'expected-review-binding.json'),changed_existing_code_files=changed,shared_supervisor_unchanged=True,training_pins_verified=len(tc['code_sha256']),actual_monitor_failure_observed=False,wrapper_error_reason='WORKER_MONITOR_ERRORS',original_receipt_retained=True,synthetic_wrapper_calls=2,new_fits=0,new_predictions=0,new_scores=0,test_target_values_read=False,unix=time.time())
|
|
save(R/'contract.json',c);save(R/'monitor-correction.json',correction);shutil.copyfile(log,R/'synthetic-monitor-correction.log')
|
|
save(R/'acceptance.json',dict(status='PASS',tests=29,elapsed_seconds=float(re.search(r'Ran 29 tests in ([0-9.]+)s',text).group(1)),log_sha256=sha(log),test_source_sha256=sha(B/'tools/test_phase3_item1_postfit.py'),scope='CPU synthetic; actual wrapper with synthetic supervisor receipt and mocked GPU probes; no real worker or targets',old_logs_preserved=True))
|
|
save(R/'training-live-snapshot.json',read(train/'live-progress.json'))
|
|
freeze(R,'implementation',[R/'contract.json',R/'comparison-contract.json',R/'acceptance.json',R/'preparation-audit.json',R/'monitor-correction.json',R/'training-live-snapshot.json',*[p for p in R.glob('synthetic*.log')],*[Path(p) for p in codes],A/'before.json',*[p for p in (A/'original-root').iterdir() if p.is_file()],*[p for p in (A/'original-source').iterdir() if p.is_file()]])
|
|
proof=verify(R,'implementation');binding=dict(reviewed_commit=proof['commit'],contract_sha256=sha(R/'contract.json'),implementation_proof_sha256=sha(R/'implementation-git-freeze.json'),comparison_contract_sha256=c['comparison_contract_sha256'],code_sha256=codes);save(R/'expected-review-binding.json',binding)
|
|
freeze(R,'review-binding',[R/'contract.json',R/'expected-review-binding.json',R/'implementation-git-freeze.json',R/'implementation-authorization.json']);config(R)
|
|
result=dict(root=str(R),implementation=proof['commit'],contract_sha256=sha(R/'contract.json'),proof_sha256=sha(R/'implementation-git-freeze.json'),binding_sha256=sha(R/'expected-review-binding.json'),comparison_sha256=c['comparison_contract_sha256'],code_files=len(codes),tests=29,actual_review_pending=True,launched=False)
|
|
save(A/'revised-identity.json',result);print(json.dumps(result))
|
|
if __name__=='__main__':main()
|