From 0d10b1e559f3fe3d65e651290d077c746c5e3319 Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Tue, 7 Apr 2026 11:03:56 -0500 Subject: [PATCH 1/3] fix: add logging to POST /api/sandboxes for debugging errors Both validation/auth failures and sandbox creation errors were being returned as JSON responses without any server-side logging, making it impossible to diagnose issues from Vercel function logs. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/sandbox/createSandbox.ts | 1 + lib/sandbox/createSandboxPostHandler.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/sandbox/createSandbox.ts b/lib/sandbox/createSandbox.ts index 16d0da3f..40dd6354 100644 --- a/lib/sandbox/createSandbox.ts +++ b/lib/sandbox/createSandbox.ts @@ -37,6 +37,7 @@ export async function createSandbox( params.source && "type" in params.source && params.source.type === "snapshot"; // Pass params directly to SDK - it handles all the type variants + console.log("[createSandbox] Creating sandbox with params:", JSON.stringify(params, null, 2)); const sandbox = await Sandbox.create( hasSnapshotSource ? { diff --git a/lib/sandbox/createSandboxPostHandler.ts b/lib/sandbox/createSandboxPostHandler.ts index e953b88a..accede2d 100644 --- a/lib/sandbox/createSandboxPostHandler.ts +++ b/lib/sandbox/createSandboxPostHandler.ts @@ -19,6 +19,8 @@ import { processCreateSandbox } from "@/lib/sandbox/processCreateSandbox"; export async function createSandboxPostHandler(request: NextRequest): Promise { const validated = await validateSandboxBody(request); if (validated instanceof NextResponse) { + const errorBody = await validated.clone().json(); + console.error("[POST /api/sandboxes] Validation/auth failed:", errorBody); return validated; } @@ -33,6 +35,7 @@ export async function createSandboxPostHandler(request: NextRequest): Promise Date: Tue, 7 Apr 2026 11:10:25 -0500 Subject: [PATCH 2/3] debug: add hash diagnostic logging to getApiKeyAccountId Logs key prefix, computed hash, and match count to help diagnose why prod API key lookups return no results. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/auth/getApiKeyAccountId.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/auth/getApiKeyAccountId.ts b/lib/auth/getApiKeyAccountId.ts index 49af4106..7cff5afc 100644 --- a/lib/auth/getApiKeyAccountId.ts +++ b/lib/auth/getApiKeyAccountId.ts @@ -29,7 +29,10 @@ export async function getApiKeyAccountId(request: NextRequest): Promise Date: Tue, 7 Apr 2026 11:14:14 -0500 Subject: [PATCH 3/3] debug: add detailed logging to processCreateSandbox Logs snapshot ID resolution, snapshot vs fresh creation failures, and insertAccountSandbox errors to trace the exact failure point. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/sandbox/processCreateSandbox.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/sandbox/processCreateSandbox.ts b/lib/sandbox/processCreateSandbox.ts index dc378a08..c8084dc9 100644 --- a/lib/sandbox/processCreateSandbox.ts +++ b/lib/sandbox/processCreateSandbox.ts @@ -40,6 +40,7 @@ export async function processCreateSandbox( const { accountId, prompt } = input; const snapshotId = await getValidSnapshotId(accountId); + console.log("[processCreateSandbox] accountId:", accountId, "snapshotId:", snapshotId ?? "none"); let result; @@ -49,19 +50,28 @@ export async function processCreateSandbox( source: { type: "snapshot", snapshotId }, }); result = createResult.response; - } catch { - const freshResult = await createSandbox({}); - result = freshResult.response; + } catch (snapshotError) { + console.error("[processCreateSandbox] Snapshot creation failed:", snapshotError); + try { + const freshResult = await createSandbox({}); + result = freshResult.response; + } catch (freshError) { + console.error("[processCreateSandbox] Fresh fallback also failed:", freshError); + throw freshError; + } } } else { const freshResult = await createSandbox({}); result = freshResult.response; } - await insertAccountSandbox({ + const insertResult = await insertAccountSandbox({ account_id: accountId, sandbox_id: result.sandboxId, }); + if (insertResult.error) { + console.error("[processCreateSandbox] insertAccountSandbox failed:", insertResult.error); + } // Trigger the prompt execution task if a prompt was provided let runId: string | undefined;