From bb64cb46f92bafa62bbe003f89c94c32f50649de Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:37:25 +0000 Subject: [PATCH] Changes Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com> --- supabase/functions/provision-agent/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/supabase/functions/provision-agent/index.ts b/supabase/functions/provision-agent/index.ts index 0249a18..c31092d 100644 --- a/supabase/functions/provision-agent/index.ts +++ b/supabase/functions/provision-agent/index.ts @@ -98,9 +98,10 @@ Deno.serve(async (req) => { return jsonResponse(409, { error: "agent_instance is not in provisioning status", status: agent.status }); } + // Se já existe railway_service_id → fluxo de UPDATE (não tenta criar novo serviço) if (agent.railway_service_id) { - console.log(`[provision-agent] já tem railway_service_id=${agent.railway_service_id}, abortando`); - return jsonResponse(409, { error: "agent_instance already has a railway_service_id", railway_service_id: agent.railway_service_id }); + console.log(`[provision-agent] railway_service_id já existe (${agent.railway_service_id}) → modo update`); + return await handleUpdateExistingService(supabase, agent, body); } // 1b) Carregar profile (full_name → nome do agente)