fix(api): fall back to primary DB in supabaseGetScrapeById to fix /interact 404 race condition#3282
Open
firecrawl-spring[bot] wants to merge 1 commit intomainfrom
Open
fix(api): fall back to primary DB in supabaseGetScrapeById to fix /interact 404 race condition#3282firecrawl-spring[bot] wants to merge 1 commit intomainfrom
firecrawl-spring[bot] wants to merge 1 commit intomainfrom
Conversation
…teract 404 race condition When v2 /scrape completes (especially cache hits), the response is sent before the fire-and-forget logScrape insert is visible on the read replica. If /interact is called immediately, it reads from the replica and returns 404 "Job not found". Add a primary DB fallback in supabaseGetScrapeById: when the read replica returns no data, retry against the primary. This adds zero latency on the normal path (replica hit) and only queries the primary when the record is missing, which is exactly the race condition window. Co-Authored-By: micahstairs <micah@sideguide.dev>
Contributor
|
Found 1 test failure on Blacksmith runners: Failure
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/scrapereturns quickly (especially cache hits), the fire-and-forgetlogScrapeinsert may not yet be visible on the Supabase read replica when/interactis called immediately after/interactto return 404 "Job not found" becausesupabaseGetScrapeByIdreads fromsupabase_rr_service(read replica)supabase_service(primary), which resolves the race condition with zero latency impact on the normal pathRoot Cause
scrape.tssetsskipNuq: truefor v2 API callsscrape-worker.tscreateslogScrapePromisebut does NOT await it whenskipNuqis true — only attaches a.catch()handler/interactreads fromsupabase_rr_service(read replica) viasupabaseGetScrapeByIdFix
In
supabaseGetScrapeById, when the read replica returns null, fall back to querying the primary database. This:Related Pylon Ticket
https://app.usepylon.com/issues?issueNumber=25927
Summary by cubic
Fixes a race that caused /interact 404s right after /scrape.
supabaseGetScrapeByIdnow falls back to the primary DB when the read replica returns no data.supabase_service.logScrape.Written for commit 86bed05. Summary will update on new commits.