"""Read-only actual boundary-cost accounting; never authorizes normal training. Only the two registered fresh/light performance cycles are cost samples. Their next serial cycle start is a measured conservative tail-completion upper bound, not an invented postvalidation duration. All current compiled-cache bytes are charged to EACH sample (deliberate overcount); cache reuse is never free by fiat. No normal directory-hashing/finalization policy or reserves are registered yet, so the strict full-suite forecast remains INSUFFICIENT-MEASUREMENTS. This report does not independently re-observe historical OS exits or certify learning. """ from __future__ import annotations from copy import deepcopy import hashlib import json import math from pathlib import Path import execution_authority as A import execution_budget as B import execution_workflow as F SCHEMA = 'conditioning-actual-budget-report-v1' TRAIN = 'performance--natural-light-fresh' PROBE = 'performance--evaluation-A-light-fresh' SELECTED = {TRAIN: [('brain',TRAIN),('original_E',TRAIN+'--original-E'),('cpu_validator',TRAIN+'--cpu-verify')], PROBE: [('brain',PROBE)]} POLICY = 'measured-fresh-light-1200-fullgraph-with-original-E-and-CPU-verification-for-training' require = A.require def _canonical(value): return json.dumps(value,sort_keys=True,separators=(',', ':'),ensure_ascii=False,allow_nan=False) def _sha(value): return hashlib.sha256(_canonical(value).encode()).hexdigest() def _same(a,b): return _canonical(a)==_canonical(b) def _number(value): return type(value) in (int,float) and math.isfinite(value) and value>=0 class Evidence: def __init__(self): self.pins={} self.derived={} def pin(self,path,expected=None): if not Path(path).exists(): raise FileNotFoundError(2,'Missing measurement evidence',str(path)) entry=A.pin(path);p=entry['path'];sha=entry['sha256'] require(expected is None or sha==expected,'Evidence bytes changed: '+p) require(p not in self.pins or self.pins[p]==sha,'Conflicting evidence pin: '+p) self.pins[p]=sha return dict(receipt_id=p,sha256=sha) def read(self,path,expected=None): self.pin(path,expected) return A.read(path) def inventory(self,directory): result=F.tree(directory) for name,row in result.items():self.pin(Path(directory)/name,row['sha256']) return result def derived_binding(self,name,value): key='derived:'+name self.derived[key]=deepcopy(value) return dict(receipt_id=key,sha256=_sha(value)) def authenticated(self): return {**self.pins,**{key:_sha(value) for key,value in self.derived.items()}} def _parent_process(name,reg,reg_sha,evidence): exp=F.EXP;process_path=exp/'receipts'/f'{name}.process.json' process=evidence.read(process_path) require(process['schema']=='conditioning-execution-process-v1' and process['complete'] is True and process['name']==name and process['registration_sha256']==reg_sha and type(process['exit_code']) is int and process['exit_code']==0 and process['timed_out'] is False, 'Unsuccessful/unbound parent process: '+name) jobpath=exp/'jobs'/f'{name}.json';job=evidence.read(jobpath,process['job_sha256']) workerpath=exp/'receipts'/f'{name}.worker.json' worker=evidence.read(workerpath,process['worker_receipt_sha256']) ap=job['kind'] in ('brain','update');script=F.AP_WORKER if ap else F.MODEL/'isolated_execution.py' schema='phase4ap-isolated-worker-receipt-v1' if ap else 'conditioning-isolated-execution-receipt-v1' worker_sha=F.W.AP_SHA if ap else reg['source_sha256'][str(script)] require(worker['schema']==schema and worker['complete'] is True and job['worker_sha256']==worker_sha and all(worker[k]==job[k] for k in ('job_id','kind','registration_sha256','worker_sha256')) and job['job_id']==name and job['kind']==process['kind'] and job['registration_sha256']==reg_sha and worker['job_sha256']==process['job_sha256'] and job['receipt_file']==str(workerpath), 'Worker/job/parent receipt identity differs') expected={**job['input_sha256'],str(jobpath):process['job_sha256'],str(script):worker_sha} if ap:expected.update({v['path']:v['sha256'] for v in job['sources'].values()}) else: expected[str(F.AP_WORKER)]=F.W.AP_SHA expected.update({str(F.MODEL/n):s for n,s in job['source_sha256'].items()}) require(expected.get(str(exp/'protocol/preregistered.json'))==reg_sha and worker['verified_input_sha256' if ap else 'input_sha256']==expected,'Actual input/source closure differs') for path,sha in expected.items():evidence.pin(path,sha) command=process['argv'] require(type(command) is list and len(command)>3 and command[1:3]==['-B',str(script)] and command[3:]==(['brain' if job['kind']=='brain' else 'update'] if ap else [])+ ['--job',str(jobpath),'--job-sha256',process['job_sha256']], 'Observed child command differs') for side in ('stdout','stderr'):evidence.pin(exp/'logs'/f'{name}.{side}.log',process[side+'_sha256']) evidence.pin(str(workerpath)+'.attempt.json',worker['attempt_sha256']) output=Path(job['output_dir']) require(output.is_relative_to(exp) and worker['output_dir']==str(output),'Wrong child output root') inventory=evidence.inventory(output);hashes={k:v['sha256'] for k,v in inventory.items()} require(inventory and hashes==worker['output_files_sha256'] and process['output_bytes']==sum(v['bytes'] for v in inventory.values()) and process['output_inventory_sha256']==hashlib.sha256(json.dumps(hashes,sort_keys=True).encode()).hexdigest(), 'Actual complete child output inventory differs') start,exit_,end=(process[k] for k in ('spawn_monotonic','exit_monotonic','validation_end_monotonic')) require(all(_number(v) for v in (start,exit_,end)) and start