fix: handle duplicate room creation race condition#165
Conversation
Catch 23505 unique constraint error when frontend creates room before backend's selectRoom sees it. Skip notification if room already exists.
Simpler fix - keep parallel execution, only catch the 23505 error.
This is the actual fix - createNewRoom is called during setupConversation at request START, which is where the 500 error occurs.
Frontend no longer creates rooms, so no race condition. Backend is single source of truth for room creation.
- Changed insertRoom to use upsert with ignoreDuplicates: true - Reverted try/catch in createNewRoom.ts and handleChatCompletion.ts - Cleaner solution: duplicates are silently ignored at the DB level
One-line fix: change insert to upsert in insertRoom.ts. Removes try/catch workarounds since upsert handles duplicates.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Braintrust eval reportCatalog Opportunity Analysis Evaluation (HEAD-1769547899)
Catalog Songs Count Evaluation (HEAD-1769547899)
First Week Album Sales Evaluation (HEAD-1769547899)
Memory & Storage Tools Evaluation (HEAD-1769547899)
Monthly Listeners Tracking Evaluation (HEAD-1769547899)
Search Web Tool Evaluation (HEAD-1769547899)
Social Scraping Evaluation (HEAD-1769547899)
Spotify Followers Evaluation (HEAD-1769547899)
Spotify Tools Evaluation (HEAD-1769547899)
TikTok Analytics Questions Evaluation (HEAD-1769547899)
|
sweetmantech
left a comment
There was a problem hiding this comment.
where are your using tests to follow TDD (red-green-refactor) for API changes?
Renames the function and file from insertRoom to upsertRoom to align with the actual Supabase method being called (.upsert()). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds comprehensive unit tests covering: - Basic upsert operation - Null artist_id handling - Null topic handling - Error handling on upsert failure - Upsert behavior (update on conflict) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: handle duplicate room creation race condition Catch 23505 unique constraint error when frontend creates room before backend's selectRoom sees it. Skip notification if room already exists. * fix: keep Promise.all, just wrap in try/catch Simpler fix - keep parallel execution, only catch the 23505 error. * fix: handle duplicate room in createNewRoom.ts This is the actual fix - createNewRoom is called during setupConversation at request START, which is where the 500 error occurs. * fix: revert try/catch bandaid - no longer needed Frontend no longer creates rooms, so no race condition. Backend is single source of truth for room creation. * fix: use upsert instead of insert for room creation - Changed insertRoom to use upsert with ignoreDuplicates: true - Reverted try/catch in createNewRoom.ts and handleChatCompletion.ts - Cleaner solution: duplicates are silently ignored at the DB level * fix: use upsert instead of insert for rooms One-line fix: change insert to upsert in insertRoom.ts. Removes try/catch workarounds since upsert handles duplicates. * refactor: rename insertRoom to upsertRoom to match method Renames the function and file from insertRoom to upsertRoom to align with the actual Supabase method being called (.upsert()). * test: add unit tests for upsertRoom function Adds comprehensive unit tests covering: - Basic upsert operation - Null artist_id handling - Null topic handling - Error handling on upsert failure - Upsert behavior (update on conflict) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
* fix: handle duplicate room creation race condition (#165) * fix: handle duplicate room creation race condition Catch 23505 unique constraint error when frontend creates room before backend's selectRoom sees it. Skip notification if room already exists. * fix: keep Promise.all, just wrap in try/catch Simpler fix - keep parallel execution, only catch the 23505 error. * fix: handle duplicate room in createNewRoom.ts This is the actual fix - createNewRoom is called during setupConversation at request START, which is where the 500 error occurs. * fix: revert try/catch bandaid - no longer needed Frontend no longer creates rooms, so no race condition. Backend is single source of truth for room creation. * fix: use upsert instead of insert for room creation - Changed insertRoom to use upsert with ignoreDuplicates: true - Reverted try/catch in createNewRoom.ts and handleChatCompletion.ts - Cleaner solution: duplicates are silently ignored at the DB level * fix: use upsert instead of insert for rooms One-line fix: change insert to upsert in insertRoom.ts. Removes try/catch workarounds since upsert handles duplicates. * refactor: rename insertRoom to upsertRoom to match method Renames the function and file from insertRoom to upsertRoom to align with the actual Supabase method being called (.upsert()). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: add unit tests for upsertRoom function Adds comprehensive unit tests covering: - Basic upsert operation - Null artist_id handling - Null topic handling - Error handling on upsert failure - Upsert behavior (update on conflict) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> * perf: optimize bundle and parallelize sequential awaits (#161) * perf: optimize bundle and parallelize sequential awaits - Add optimizePackageImports for date-fns, @AI-SDK packages - Parallelize MCP tools and Composio tools fetching with Promise.all - Parallelize Trigger.dev schedule deletion and DB deletion in deleteTask These optimizations improve API response times by parallelizing independent operations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: add unit tests for parallel execution optimizations - Add comprehensive tests for deleteTask function including: - Basic functionality (fetch, delete from DB, delete from Trigger.dev) - Error handling (task not found, propagated errors) - Handling tasks without trigger_schedule_id - Parallel execution verification - Add parallel execution tests for setupToolsForRequest: - Verify MCP and Composio tools are fetched concurrently - Verify both operations are called when authToken is provided Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Re-opening for review before merge.
This changes
insertRoomto use upsert instead of insert to handle race conditions when creating rooms.