env->load($root . '/.env'); $app->config->set(require $root . '/config/prescription_ai.php', 'prescription_ai'); $targetTime = (new \DateTimeImmutable('2026-10-27T10:17:23+08:00'))->getTimestamp(); $matches = []; foreach (glob($root . '/runtime/adminapi/assistant-requests/*.json') ?: [] as $file) { if (filemtime($file) !== $targetTime) continue; $state = json_decode((string) file_get_contents($file), true, 64, JSON_THROW_ON_ERROR); if (($state['status'] ?? '') !== 'error' || empty($state['validation_rejected']) || ($state['producer_terminal_status'] ?? '') !== 'stopped' || ($state['persisted_run_status'] ?? '') !== 'running' || ($state['verification_attempts'] ?? 0) !== 2 || count($state['submitted_attempts'] ?? []) !== 1 || !is_array($state['upstream'] ?? null)) continue; $matches[] = ['file' => $file, 'state' => $state]; } if (count($matches) !== 1) { echo json_encode(['ok' => false, 'error_code' => 'ORIGINAL_SELECTOR_NOT_UNIQUE', 'candidate_count' => count($matches)]); exit; } $file = $matches[0]['file']; $before = hash_file('sha256', $file); $identity = array_intersect_key($matches[0]['state']['upstream'], array_flip(['profile', 'user', 'task_id', 'workflow_run_id', 'generation'])); unset($matches, $state); $started = hrtime(true); $result = \app\common\service\DifyWorkflowRunStatus::lookup($identity, 1000); $out = ['ok' => ($result['ok'] ?? false) === true, 'elapsed_ms' => (int) floor((hrtime(true) - $started) / 1e6), 'original_control_unchanged' => hash_file('sha256', $file) === $before, 'status_lookup_count' => 1]; if ($out['ok']) $out['status'] = $result['status']; else $out['error_code'] = $result['error_code'] ?? 'RUN_STATUS_UNCONFIRMED'; unset($identity, $result, $file); echo json_encode($out, JSON_THROW_ON_ERROR); } catch (\Throwable $ignored) { echo '{"ok":false,"error_code":"ORIGINAL_STATUS_DIAGNOSTIC_FAILED"}'; }