Files
zyt/artifacts/private_ai_runtime_status_20261027.php
2026-10-27 14:03:35 +08:00

50 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
// Read-only original-run observer. No route, stop, generation, or control writes.
ini_set('display_errors', '0');
ini_set('log_errors', '0');
header('Content-Type: application/json');
if (PHP_SAPI !== 'cgi-fcgi' || ($_SERVER['REMOTE_ADDR'] ?? '') !== '127.0.0.1'
|| ($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || (int) ($_SERVER['CONTENT_LENGTH'] ?? 0) !== 0) {
http_response_code(403); echo '{"ok":false,"error_code":"PRIVATE_FASTCGI_POST_REQUIRED"}'; exit;
}
try {
$root = dirname(__DIR__) . '/server';
require $root . '/vendor/autoload.php';
$app = new \think\App($root . '/');
require_once $root . '/vendor/topthink/framework/src/helper.php';
$app->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"}';
}