Skip to content

fix(buddy): clearer errors for /start 500 (Daily key + DB schema)#130

Merged
auerbachb merged 1 commit into
mainfrom
fix/buddy-start-error-handling
Apr 16, 2026
Merged

fix(buddy): clearer errors for /start 500 (Daily key + DB schema)#130
auerbachb merged 1 commit into
mainfrom
fix/buddy-start-error-handling

Conversation

@auerbachb
Copy link
Copy Markdown
Owner

@auerbachb auerbachb commented Apr 14, 2026

Cause of POST …/start 500

Most likely one of:

  1. DAILY_API_KEY unset in VercelcreateRoom threw a plain Error, which was rethrown and became 500.
  2. Prod DB missing daily_room_name / daily_room_urlUPDATE buddy_sessions fails → 500 (often if drizzle-kit push was only run against dev).

Change

  • Map those cases to 503 with a specific error string (and log server-side).
  • On DB update failure after Daily room exists: delete the orphan Daily room, then return 503.
  • Non-DailyApiError from Daily path: 503 instead of 500.

What you should verify on prod

  • Vercel Production env: DAILY_API_KEY set.
  • Neon production DB has buddy daily room columns (drizzle-kit push with prod POSTGRES_URL or drizzle/buddy_sessions_daily_room_incremental.sql).

After deploy, retry Start — UI should show the API error message via existing ApiError handling.

Made with Cursor

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced error handling during shared session startup with clearer diagnostic messages
    • Improved system resilience by gracefully managing configuration and database-related issues during session initialization
    • Better error recovery with specific guidance when problems occur, preventing unhandled exceptions

- Missing DAILY_API_KEY: explicit message (was plain Error → 500)
- Daily non-API failures: 503 + log, not 500
- DB update failures (e.g. missing daily_room columns): cleanup Daily room, 503 + migration hint
- DB race still returns 409 after orphan room cleanup

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
still-point Ready Ready Preview, Comment Apr 14, 2026 4:54pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 839aa488-2f31-405d-a733-d6c4a1a1a8be

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa6dd9 and 1915d77.

📒 Files selected for processing (1)
  • src/app/api/buddy/sessions/[id]/start/route.ts

📝 Walkthrough

Walkthrough

The error handling in the buddy session start route was expanded to handle Daily room creation failures (including name-conflict retries, API key issues, and generic errors) and database update failures (with Daily cleanup and specific schema error detection) with controlled HTTP responses instead of throwing exceptions.

Changes

Cohort / File(s) Summary
Buddy Session Start Error Handling
src/app/api/buddy/sessions/[id]/start/route.ts
Expanded error handling for Daily room creation (name-conflict retry, missing API key, generic errors) and wrapped database transition update in try-catch with automatic room cleanup on failure; added regex-based schema error detection (daily_room, does not exist, 42703) to return specific recovery instructions.

Sequence Diagram

sequenceDiagram
    participant Client
    participant API as API Route
    participant Daily as Daily API
    participant DB as Database
    
    Client->>API: Start buddy session
    API->>Daily: Create room with prefix
    
    alt Name Conflict (Retry)
        Daily-->>API: Name conflict error
        API->>Daily: Retry with different name
        alt Retry Succeeds
            Daily-->>API: Room created
        else Retry Fails
            Daily-->>API: Error logged
            API-->>Client: 503 (retry failed)
        end
    else Missing DAILY_API_KEY
        Daily-->>API: Error contains DAILY_API_KEY
        API-->>Client: 503 (set DAILY_API_KEY)
    else Generic Error
        Daily-->>API: Other error
        API-->>Client: 503 (unexpected error)
    end
    
    rect rgba(100, 200, 100, 0.5)
        API->>DB: Transition to active state
        alt DB Success
            DB-->>API: Row updated
            API-->>Client: 200 OK
        else DB Schema Error (regex match)
            DB-->>API: Error (daily_room/42703)
            API->>Daily: Delete room (ignoreMissing)
            Daily-->>API: Deletion complete
            API-->>Client: 503 (run schema push)
        else DB Other Error
            DB-->>API: Unexpected error
            API->>Daily: Delete room (ignoreMissing)
            Daily-->>API: Deletion complete
            API-->>Client: 503 (try again)
        end
    end
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 Errors caught with gentle care,
No more exceptions thrown in air!
Try and catch, then cleanup right,
Buddy sessions burn so bright!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: improved error handling and clearer error messages for the /start endpoint, specifically addressing Daily API key and database schema issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/buddy-start-error-handling

Comment @coderabbitai help to get the list of available commands and usage tips.

@auerbachb
Copy link
Copy Markdown
Owner Author

Production readiness check for buddy start (per PR #130 notes):

  • Extracted required checks from PR body:
    • Vercel Production env var: DAILY_API_KEY
    • Neon prod public.buddy_sessions columns: daily_room_name, daily_room_url
  • Verified Vercel Production DAILY_API_KEY exists
    • Blocked in this environment at https://vercel.com/login?next=%2Fdashboard (auth required)
  • Verified Neon production schema contains required columns
    • Blocked in this environment at Neon login (auth required)

Exact Neon verification query:

SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema='public'
  AND table_name='buddy_sessions'
  AND column_name IN ('daily_room_name','daily_room_url')
ORDER BY column_name;

If schema drift is found, apply incremental SQL from drizzle/buddy_sessions_daily_room_incremental.sql:

ALTER TABLE "buddy_sessions" ADD COLUMN IF NOT EXISTS "daily_room_name" varchar(128);
ALTER TABLE "buddy_sessions" ADD COLUMN IF NOT EXISTS "daily_room_url" text;

Follow-up tracking issue (includes checklist + exact SQL):

Note: PR #130 is currently open, so code deploy is still required before confirming production behavior of the new 503 error mapping path.

@auerbachb auerbachb merged commit c1e875f into main Apr 16, 2026
4 checks passed
@auerbachb auerbachb deleted the fix/buddy-start-error-handling branch April 16, 2026 18:41
@auerbachb
Copy link
Copy Markdown
Owner Author

Production verification update (confirmed):

Environment + schema prerequisites for buddy start are satisfied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant