"""Persist a validation-selected threshold without granting execution permission.""" import json def load_allow_threshold(model, override=None): if override is not None:return override path=model/'operating-policy.json' if not path.exists():return .90 policy=json.loads(path.read_text());threshold=float(policy['allow_threshold']) if not 0<=threshold<=1.0001:raise ValueError('Invalid saved operating threshold') if (threshold>1)!=bool(policy.get('disable_automatic_allow',False)): raise ValueError('Inconsistent automatic ALLOW disabling policy') return threshold def save_experimental_policy(model,validation): policy=dict(allow_threshold=validation['operating_threshold'],disable_automatic_allow=validation['operating_threshold']>1, selected_on='validation_only',validation_sha256=validation['dataset_sha256'],validation_passed=validation['readiness']['passed'], criteria_passed=False,status='experimental_until_test_and_audit_pass',production_execution_enabled=False) (model/'operating-policy.json').write_text(json.dumps(policy,indent=2)+'\n')