diff --git a/api/wevia-sse-orchestrator.php b/api/wevia-sse-orchestrator.php index b59c978d1..1d9e85417 100644 --- a/api/wevia-sse-orchestrator.php +++ b/api/wevia-sse-orchestrator.php @@ -185,7 +185,20 @@ if (!empty($msg)) { if (!$__sd_safe) continue; // DOCTRINE-215 opus-phase74 - inject MSG env for cmd extraction $__sd_env = 'MSG=' . escapeshellarg($__sd_msg) . ' '; - $__sd_out = @shell_exec($__sd_env . 'timeout 90 bash -c ' . escapeshellarg($__sd_cmd) . ' 2>&1'); + // DOCTRINE-216 opus-phase75 - async long intents to bypass CF 504 + $__sd_long_intents = ['wevia_gemini_ux_apply', 'wevia_gemini_ux_fix', 'wevia_playwright_ux_overlap_gemini_audit']; + if (in_array($__sd_info['name'] ?? '', $__sd_long_intents)) { + // Background exec + return task_id immediate + $__sd_task_id = 'task_' . bin2hex(random_bytes(5)); + $__sd_task_out = "/tmp/wevia-tasks/{$__sd_task_id}.out"; + $__sd_task_flag = "/tmp/wevia-tasks/{$__sd_task_id}.flag"; + @mkdir('/tmp/wevia-tasks', 0777, true); + $__sd_full_cmd = $__sd_env . 'timeout 180 bash -c ' . escapeshellarg($__sd_cmd); + @exec("nohup bash -c " . escapeshellarg("$__sd_full_cmd > $__sd_task_out 2>&1; touch $__sd_task_flag") . " > /dev/null 2>&1 &"); + $__sd_out = "ASYNC_LAUNCHED task_id=$__sd_task_id\nPoll: /api/wevia-async-exec.php?poll=$__sd_task_id\nIntent {$__sd_info['name']} running in background (90-180s)."; + } else { + $__sd_out = @shell_exec($__sd_env . 'timeout 90 bash -c ' . escapeshellarg($__sd_cmd) . ' 2>&1'); + } sse([ 'type' => 'exec', 'text' => "Intent '{$__sd_info['name']}' executed (trigger tokens matched: $__sd_trg)\n" . trim((string)$__sd_out),