AI vision stage fails on 302 redirects (media_proxy image URLs) #105
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
The vision stage fails to download the first image for posts whose media is served through Mastodon's
media_proxyURLs. The download raises, the post skips vision classification, and it staysAI: pending.Affected posts (from
packages/fenliu/fenliu-all.log): 42, 43, 44, 46.Root cause
Mastodon serves some attachments via
https://mastodon.social/media_proxy/<id>/small, which responds302 Foundredirecting tohttps://files.mastodon.social/cache/media_attachments/files/....The httpx2 client that downloads images is created without
follow_redirects=True:Unlike stock httpx, httpx2's
raise_for_status()raises on a 3xx redirect response. Traceback fromlogs/fenliu_debug.log:Fix direction
Create the download client with
follow_redirects=True:The AI API client in
ai_classification.pydoes not need this — it only callsapi.moonshot.ai, which does not redirect.Impact
Posts with
media_proxyURLs never get a vision verdict (leftAI: pending, reviewed manually). No mis-classification — just unclassified posts.Plan of attack:
packages/fenliu/src/fenliu/services/ai_pipeline.py—classify_postscreates the download client withfollow_redirects=Truesomedia_proxy302s are followed.packages/fenliu/src/fenliu/services/ai_vision.py—download_first_imageguesses MIME from the post-redirect final URL (response.url) instead of the requested URL, so proxied non-jpeg attachments get their real MIME in the data URI sent to the vision API.classify_postsviahttpx2.MockTransport, and a direct MIME-from-final-URL test.fix/issue-105-follow-media-proxy-redirects, single commit, PR tomain.