initialize(); try { $model = in_array('--openai', $argv, true) ? 'openai' : 'qwen'; $expectedError = $model === 'openai' ? 'INPUT_TOKEN_BUDGET_EXCEEDED' : 'INVALID_FILE_EVIDENCE_OUTPUT'; $batch = Db::name('prescription_ai_batch')->where('id', 1)->where('prescription_id', 7556)->find(); $task = Db::name('prescription_ai_task')->where('batch_id', 1)->where('model_key', $model)->find(); if (!$batch || !$task || $batch['validity'] !== 'current' || $task['status'] !== 'failed' || $task['error_code'] !== $expectedError) { throw new RuntimeException('Task is no longer the expected failed task'); } if (Db::name('prescription_ai_task')->where('model_key', $model)->where('status', 'running')->count() > 0) { throw new RuntimeException('A model task is running; do not stop its consumer'); } $actor = (int) $batch['actor_id']; $info = PrescriptionAiAccess::actor($actor); if (!$info || !PrescriptionAiAccess::allowed($actor, $info, 'retry')) { throw new RuntimeException('Retry is not authorized for the original actor'); } if (in_array('--apply', $argv, true)) { $result = PrescriptionAiLogic::retry(1, $model, $actor, $info); } else { $result = ['model' => $model, 'eligible' => true, 'running_model_tasks' => 0, 'applied' => false]; } echo json_encode($result, JSON_UNESCAPED_UNICODE), PHP_EOL; } catch (Throwable $error) { echo json_encode(['retry_error' => get_class($error), 'code' => $error->getCode()]), PHP_EOL; exit(1); }