<?php
declare(strict_types=1);require __DIR__.'/native.php';require __DIR__.'/decimal-oracle.php';ck(!file_exists($runtime.'/retry-path-preconditions.json'),'Exact additional path preflight once');$ids=json_decode(file_get_contents($runtime.'/prepared.json'),true)['ids'];$guard=json_decode(file_get_contents($runtime.'/guard.json'),true);$own=ownSnapshot();$old=oldProtection();ck($old===$guard['old_protection'],'Original fullrow unchanged before precise retry');$cash=readNative('AI','SELECT CAST(balance AS '.($dm?'VARCHAR(40)':'CHAR').') balance_text,CAST(gift_balance AS '.($dm?'VARCHAR(40)':'CHAR').') gift_text,CAST(pay_money AS '.($dm?'VARCHAR(40)':'CHAR').') pay_text FROM yoshop_user WHERE user_id=?',[$ids['AI_U1']]);ck(dec102text($cash[0]['balance_text'])==='1.00'&&dec102text($cash[0]['gift_text'])==='0.00'&&dec102text($cash[0]['pay_text'])==='0.00','Exact cash1 before retry');$events=array_map(static function($x){return json_decode($x,true);},file($runtime.'/business-native.jsonl',FILE_IGNORE_NEW_LINES));$scenario=$lane==='B'?'DIRECT_SUCCESS':'PREPAY_FIRST';$attempts=[];$rollbacks=[];foreach($events as $e)if($e['scenario']===$scenario){if(($e['layer']??'')==='actual PDOStatement.execute'&&in_array($e['operation']??'',['INSERT','UPDATE'],true))$attempts[]=$e;if(($e['layer']??'')==='actual PDO.rollBack')$rollbacks[]=$e;}ck($attempts===[],'Failed path had zero native DML');ck(count($rollbacks)===($lane==='B'?2:1),'Failed original transaction rollbacks');$direct=readNative('ZHCT','SELECT COUNT(*) n FROM ydy_meal_order WHERE user_id=? AND remark=?',[$ids['STORE_U1'],'CDXCORE11S1_DIRECT']);ck((int)$direct[0]['n']===0,'No prior direct order');if($lane==='B'){ck(count($own['meal_order'])===1&&(int)$own['meal_order'][0]['id']===68497,'Only already successful prepay remains');$hash=md5('meal_direct_pay_'.$ids['AI_U1'].'_'.$ids['STORE_R1']);$file=$runtime.'/cache/'.substr($hash,0,2).'/'.substr($hash,2).'.php';if(is_file($file)){clearstatcache(true,$file);$raw=file_get_contents($file);ck((int)substr($raw,8,12)===5&&time()>filemtime($file)+5,'Original failed-payment lock expired naturally');}}else{ck($own['meal_order']===[],'C no order before first successful retry');$prepared=json_decode(file_get_contents($runtime.'/prepared.json'),true);ck($own['STORE_P1']===[$prepared['rows']['STORE_P1']],'C prepay still exact original unbound');}saveOnce('retry-path-preconditions.json',['lane'=>$lane,'failed_native_DML'=>$attempts,'actual_rollbacks'=>$rollbacks,'own'=>$own,'old'=>$old,'cash_text_raw'=>$cash,'no_direct_order_count'=>$direct,'HTTP'=>0,'DML'=>0]);echo json_encode(['lane'=>$lane,'zero_failed_native_DML'=>true,'rollback_count'=>count($rollbacks),'cash'=>'1.00','old_protection_equal'=>true]),"\n";
