fix(copilot): stop losing product images to dead browsers and bot walls - #42
Merged
Merged
Conversation
extract_product_images returned 0 images and "Image extraction failed" on DigiKey: the page is a Cloudflare interstitial and Chromium (single-process, 512MB dyno) had died, so newPage() hit a stale handle. - relaunch once when the cached browser is disconnected or newPage reports it closed - read og/twitter/JSON-LD straight from HTML when the browser cannot answer - recognise anti-bot interstitials and report them as blocked, not as a failure Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
From the production logs:
extract_product_imageson a DigiKey URL returned0 imagesandImage extraction failed, withbrowser.newPage: Target page, context or browser has been closed. Two independent causes, both of which surfaced as the same useless outcome.Stale browser handle. Chromium runs
--single-processon a 512MB dyno; when it is OOM-killed,browserPromisestill resolves to a corpse (thedisconnectedhandler clears it, but not before the next job asks for a page). The next job then dies for the previous job's crash.withBrowserPagenow checks liveness and relaunches once:The page was a Cloudflare interstitial. DigiKey served a Turnstile challenge, so there was nothing to harvest, and harvesting it anyway would have handed the copilot a shield logo as a component photo. New
server/ai/product-images.tsrecognises those pages (looksLikeBotChallenge) and parsesog:image/twitter:image/JSON-LD straight out of HTML — no browser — which is where distributors put the product photo anyway. So:browser first (it resolves lazy gallery images), HTTP fetch as the fallback whenever the browser returns nothing or cannot run. A missing Playwright binary still throws — that is a deployment fact for an operator, not a page to work around. The tool and the copilot's tool line now say why it came back empty ("distributor blocked the reader") so the model picks a different distributor instead of retrying the same wall.
Testing
test/product-images.test.ts(6) covers challenge detection, HTML harvesting and ranking;test/render-browser.test.tsgrows 3 cases for relaunch-after-death, the HTML fallback, and a blocked page. Full suite 475 passing; prettier, eslint andtsc --noEmitclean. Not verified against the live DigiKey page — the fix is inferred from the attached production log.Link to Devin session: https://app.devin.ai/sessions/27a2860693d444f8a9a37442a83762d7
Requested by: @alanshen27