"""Exclusive Phase3/4 guard carrying every prior billed/unknown reservation.""" import importlib.util import json from decimal import Decimal from pathlib import Path import httpx from services.local_s2s.components import EvaluationBudgetExhausted path=Path('/checks/browser-budget.py') if not path.exists():path=Path(__file__).with_name('browser-budget.py') spec=importlib.util.spec_from_file_location('previous_browser_budget',path) previous=importlib.util.module_from_spec(spec);spec.loader.exec_module(previous) class BrowserBudget(previous.BrowserBudget): def __init__(self,root,*,upstream=None): previous.native.validate_prices(root) checkpoint=root/'carried-budget-preparation.json' if checkpoint.exists(): # Migration from another host: documentary carry, never invented bills. prior=json.loads(checkpoint.read_text()) previous.require(prior['prior_conservative_exposure_usd']=='0.704504399' and prior['total_cap_usd']=='1' and prior['paid_calls_on_this_host']==0 and prior['prior_private_ledgers_available'] is False and prior['source']=='docs/evaluation/local-s2s/phase-04-interruption-incident.md' and prior['status']=='preparation_only_not_a_live_admission_ledger' and not (root/'previous-phase4-ledger.json').exists() and not (root/'prior-final-billing.json').exists()) carried=Decimal(prior['prior_conservative_exposure_usd']) self.maximum_attempts={'speech':4,'transcriptions':4,'completions':4} runs_path=root/'previous-windows-runs.json' old_ledger=root/'previous-windows-ledger.json' old_billing=root/'previous-windows-billing.json' previous.require(old_ledger.exists()==old_billing.exists()) if runs_path.exists(): previous.require(not old_ledger.exists()) runs=json.loads(runs_path.read_text()) previous.require(isinstance(runs,list) and 0= self.maximum_attempts[stage]: self.state['last_denial']={'stage':stage,'reason':'attempt_limit', 'admitted_attempts':used} self.save() raise EvaluationBudgetExhausted('Evaluation attempt limit reached') return await super().handle_async_request(request)