From b42edbe681a6b9e0ee6222fbd898435247c40a89 Mon Sep 17 00:00:00 2001 From: Mark Henderson Date: Thu, 19 Feb 2026 17:31:01 -0800 Subject: [PATCH] fix: handle Cloud Run 409 by linking to existing service; show provisioning spinner not failure Co-authored-by: Cursor --- components/project-creation-modal.tsx | 6 ++++-- lib/cloud-run-workspace.ts | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/project-creation-modal.tsx b/components/project-creation-modal.tsx index a564579..44a7d83 100644 --- a/components/project-creation-modal.tsx +++ b/components/project-creation-modal.tsx @@ -329,9 +329,11 @@ export function ProjectCreationModal({ {createdTheiaUrl ? ( ) : ( - + )} - Dedicated IDE workspace{createdTheiaUrl ? ` at ${createdTheiaUrl.replace('https://', '')}` : ' — provisioning failed'} + Dedicated IDE workspace{createdTheiaUrl + ? ` at ${createdTheiaUrl.replace('https://', '')}` + : ' — provisioning in background (ready in ~30s)'} diff --git a/lib/cloud-run-workspace.ts b/lib/cloud-run-workspace.ts index 71f622d..54e1de1 100644 --- a/lib/cloud-run-workspace.ts +++ b/lib/cloud-run-workspace.ts @@ -112,6 +112,16 @@ export async function provisionTheiaWorkspace( if (!createRes.ok) { const body = await createRes.text(); + + // 409 = service already exists — fetch its URL instead of failing + if (createRes.status === 409) { + console.log(`[workspace] Cloud Run service already exists: ${serviceName} — fetching existing URL`); + const serviceUrl = await waitForServiceUrl(serviceName, token); + await allowUnauthenticated(serviceName, token); + console.log(`[workspace] Linked to existing service: ${serviceName} → ${serviceUrl}`); + return { serviceUrl, serviceName }; + } + throw new Error(`Cloud Run create service failed (${createRes.status}): ${body}`); }