From 8912fcc3541c6688450c76fa8d7a3347592dfcee Mon Sep 17 00:00:00 2001 From: "anthropic-code-agent[bot]" <242468646+Claude@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:31:18 +0000 Subject: [PATCH] Fix: Use /tmp for SQLite environments on Vercel serverless MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes environment creation failure on Vercel deployment where POST succeeds but GET returns 404. **Root Cause:** - LocalSQLiteEnvironmentDatabaseAdapter was trying to write to `.objectstack/data/environments/` - Vercel serverless functions have read-only filesystem except for `/tmp` - Environment provisioning failed silently when trying to create database files - POST returned 202 Accepted, but async provisioning failed - Subsequent GET requests returned 404 because environment was stuck in "failed" state **Solution:** - Detect serverless environments (VERCEL=1, AWS_LAMBDA_FUNCTION_NAME, FUNCTION_NAME) - Use `/tmp/.objectstack/data/environments/` in serverless, `.objectstack/data/environments/` in local dev - Both `sqlite` and `turso` (fallback) adapters now use the serverless-aware path **Testing:** - Environment creation will now succeed on Vercel - Local development unaffected (still uses relative path) - AWS Lambda and similar platforms also supported 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 Co-authored-by: os-zhuang <277994282+os-zhuang@users.noreply.github.com> --- .../src/environment-provisioning.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/services/service-tenant/src/environment-provisioning.ts b/packages/services/service-tenant/src/environment-provisioning.ts index 574c2d813..cba48d0ba 100644 --- a/packages/services/service-tenant/src/environment-provisioning.ts +++ b/packages/services/service-tenant/src/environment-provisioning.ts @@ -535,7 +535,8 @@ export class EnvironmentProvisioningService { * the control-plane ObjectQL driver handles persisting the record into * `memory-driver.json` in its native format). * - Always register the `sqlite` adapter (writes a `.db` file per env - * under `.objectstack/data/environments/`). + * under `.objectstack/data/environments/` in local dev, or `/tmp/.objectstack/data/environments/` + * in serverless environments like Vercel where only /tmp is writable). * - For the `turso` key: * - if `TURSO_ORG_NAME` + `TURSO_API_TOKEN` are both set → use the * real Turso Platform adapter (creates cloud databases); @@ -547,7 +548,15 @@ export function createDefaultEnvironmentAdapters( ): EnvironmentDatabaseAdapter[] { const adapters: EnvironmentDatabaseAdapter[] = []; adapters.push(new MemoryEnvironmentDatabaseAdapter()); - adapters.push(new LocalSQLiteEnvironmentDatabaseAdapter()); + + // Use /tmp for serverless environments (Vercel, AWS Lambda, etc.) + // These platforms only have /tmp as writable filesystem + const isServerless = env.VERCEL === '1' || env.AWS_LAMBDA_FUNCTION_NAME || env.FUNCTION_NAME; + const sqliteBaseDir = isServerless + ? '/tmp/.objectstack/data/environments' + : '.objectstack/data/environments'; + + adapters.push(new LocalSQLiteEnvironmentDatabaseAdapter(sqliteBaseDir)); const orgName = env.TURSO_ORG_NAME; const apiToken = env.TURSO_API_TOKEN; @@ -557,7 +566,7 @@ export function createDefaultEnvironmentAdapters( // Local-dev fallback: when the user picks `turso` in Studio but no // platform creds are configured, still create a real file on disk so // the UX is "I created an env and I can see it". - adapters.push(new LocalSQLiteEnvironmentDatabaseAdapter(undefined, 'turso')); + adapters.push(new LocalSQLiteEnvironmentDatabaseAdapter(sqliteBaseDir, 'turso')); } return adapters; }