Fix describe generator script syntax and fail on stale JSON fallback

This commit is contained in:
hbrain 2026-05-31 18:31:46 +02:00
parent 62156ed946
commit 5c544f3cfb
2 changed files with 31 additions and 2 deletions

View file

@ -107,11 +107,39 @@ $cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshe
// Allow long-running
@set_time_limit(0);
$gfile = dirname($jobdir) . '/' . basename($jobdir) . '.json';
$gfileExistedBefore = is_file($gfile);
$gfileMtimeBefore = $gfileExistedBefore ? @filemtime($gfile) : null;
exec($cmd, $out_lines, $rc);
$log = implode("\n", $out_lines);
clearstatcache(true, $gfile);
if ($rc !== 0) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => 'generator failed',
'log' => $log,
'rc' => $rc,
'output_file' => basename($gfile),
'stale_output_present' => is_file($gfile),
], JSON_UNESCAPED_UNICODE);
exit;
}
if (!is_file($gfile)) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => 'no gemini output',
'log' => $log,
'rc' => $rc,
], JSON_UNESCAPED_UNICODE);
exit;
}
// If gemini_generated.json exists, parse and return
$gfile = dirname($jobdir) . '/' . basename($jobdir) . '.json';
if (is_file($gfile)) {
$raw = @file_get_contents($gfile);
$json_data = @json_decode($raw, true);