<?php
$file=__DIR__.'/private/readiness-retry-trace.json';if(is_file($file))throw new RuntimeException('Readiness retry already started; no replay');
$record=['lane'=>getenv('NF_LANE'),'started'=>true,'completed'=>false];file_put_contents($file,json_encode($record));chmod($file,0600);ob_start();$code=0;
try{require __DIR__.'/readiness.php';$record['completed']=true;$record['success']=true;}
catch(Throwable $e){$code=1;$message=$e->getMessage();foreach([$cfg['password']??'',$cfg['username']??'']as $secret)if(is_string($secret)&&$secret!=='')$message=str_replace($secret,'<redacted>',$message);$trace=[];foreach($e->getTrace()as $frame)$trace[]=array_intersect_key($frame,array_flip(['file','line','class','function','type']));$record['exception']=['class'=>get_class($e),'message'=>$message,'trace_without_args'=>$trace];}
$record['stdout']=ob_get_clean();$record['oracle_attempts']=$GLOBALS['NF_ORACLE_ATTEMPTS']??[];$record['oracle_completed']=$GLOBALS['NF_ORACLE']??[];$record['DML']=0;$record['DDL']=0;$record['HTTP']=0;file_put_contents($file,json_encode($record,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION));chmod($file,0600);
echo json_encode(['lane'=>getenv('NF_LANE'),'success'=>$record['success']??false,'exception'=>$record['exception']['class']??null,'SELECT_attempts'=>count($record['oracle_attempts']),'SELECT_completed'=>count($record['oracle_completed']),'HTTP'=>0,'DML'=>0]),PHP_EOL;exit($code);

