AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix: classify blocked Reddit discovery listings (#1247)
Ilia Alshanetsky70990709fee8
diff --git a/changelog.d/940.fixed.md b/changelog.d/940.fixed.mdnew file mode 100644index 00000000..73349783--- /dev/null+++ b/changelog.d/940.fixed.md@@ -0,0 +1 @@+Fixed Reddit discovery reporting blocked or cardless r/all listings as no results instead of a degraded source.diff --git a/skills/last30days/scripts/lib/reddit_listing.py b/skills/last30days/scripts/lib/reddit_listing.pyindex bc79f1f5..35751b7f 100644--- a/skills/last30days/scripts/lib/reddit_listing.py+++ b/skills/last30days/scripts/lib/reddit_listing.py@@ -41,6 +41,19 @@ MAX_WORKERS = 4LISTING_TIMEOUT = 15_POST_CARD = re.compile(r"<shreddit-post(?=[\s>])[^>]*>")+_BLOCK_MARKERS = (+ "verify you are human",+ "confirm you are a human",+ "just a moment",+ "attention required",+ "cf-browser-verification",+ "challenge-platform",+ "/svc/shreddit/js-challenge",+ "please wait for verification",+ "enable javascript and reload",+ "you've been blocked",+ "whoa there",+)def _log(msg: str) -> None:@@ -172,6 +185,19 @@ def _listing_url(subreddit: str, sort: str, timeframe: str = TIMEFRAME) -> str:return url+def _listing_body_problem(subreddit: str, body: str) -> Optional[str]:+ lower = body.lower()+ is_blocked = any(marker in lower for marker in _BLOCK_MARKERS)+ is_all = subreddit.removeprefix("r/").strip().lower() == "all"+ if not is_all and not is_blocked:+ return None+ if parse_cards(body):+ return None+ if is_blocked:+ return "Reddit listing interstitial: HTTP 2xx with no post cards"+ return "Reddit r/all listing schema drift: HTTP 2xx with no post cards"++def _fetch_one(subreddit: str,sort: str,@@ -190,12 +216,13 @@ def _fetch_one_with_status() -> tuple[List[Dict[str, Any]], Optional[str]]:try:# retry_429 records a terminal miss into the pipeline sink (issue #899)- # and retries a 429 once through the limiter (issue #985). An empty- # body ("") is a real empty listing; None never is.+ # and retries a 429 once through the limiter (issue #985). Empty+ # dedicated-subreddit fragments can be valid; r/all cannot be empty.text, error = http.reddit_keyless_get_text_retry_429(_listing_url(subreddit, sort, timeframe),timeout=LISTING_TIMEOUT,accept="text/html",+ validate=lambda body: _listing_body_problem(subreddit, body),)if text is None:return [], (error or "no response")diff --git a/tests/test_discover_mode.py b/tests/test_discover_mode.pyindex ec0e7769..0acd2be5 100644--- a/tests/test_discover_mode.py+++ b/tests/test_discover_mode.py@@ -12,7 +12,7 @@ from unittest import mockimport pytestimport last30days as cli-from lib import dates, discovery_handoff, pipeline, planner, reddit_listing, render, rerank, schema+from lib import dates, digg, discovery_handoff, pipeline, planner, reddit_listing, render, rerank, schemaREPO_ROOT = Path(__file__).resolve().parents[1]@@ -407,6 +407,138 @@ def test_discovery_listing_block_is_reported_as_rate_limited():assert "429" in (outcome.detail or "")+def test_discovery_listing_403_is_reported_as_auth_failed():+ blocked = urllib.error.HTTPError(+ "https://www.reddit.com/r/all/rising/", 403, "Forbidden", {}, None,+ )+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch("lib.http.urllib.request.urlopen", side_effect=blocked):+ report = pipeline.run_discover(+ domain="", config={}, as_of_date="2026-07-10",+ )++ outcome = report.source_status["reddit"]+ assert outcome.state == schema.AUTH_FAILED+ assert "403" in (outcome.detail or "")++[email protected]("body", [+ "",+ "<!doctype html><html><body><h1>You've been blocked</h1></body></html>",+ "<html><body><main>Reddit listing layout changed</main></body></html>",+])+def test_reddit_global_listing_without_cards_reports_schema_drift(body):+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch.object(reddit_listing.http, "get_text", return_value=body), \+ mock.patch("lib.reddit_arctic.fetch_listings", return_value=[]):+ report = pipeline.run_discover(+ domain="", config={}, as_of_date="2026-07-10",+ )++ outcome = report.source_status["reddit"]+ assert outcome.state == schema.SCHEMA_DRIFT+ assert "HTTP 2xx" in (outcome.detail or "")+ assert "no post cards" in (outcome.detail or "")+++def test_reddit_domain_filter_zero_after_valid_listing_remains_no_results():+ body = (+ "<!doctype html><html><body>"+ '<shreddit-post permalink="/r/cats/comments/abc123/post/" '+ 'post-title="A playful kitten" score="42" comment-count="7" '+ 'author="owner" subreddit-name="cats" '+ 'created-timestamp="2026-07-09T12:00:00+00:00">'+ "</body></html>"+ )+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch.object(reddit_listing.http, "get_text", return_value=body), \+ mock.patch("lib.reddit_arctic.fetch_listings", return_value=[]):+ report = pipeline.run_discover(+ domain="urban gardening", config={}, as_of_date="2026-07-10",+ subreddits=["all"],+ )++ assert report.source_status["reddit"].state == schema.NO_RESULTS++[email protected]("body", [+ "<div></div>",+ "<!doctype html><html><body><main>No posts yet</main></body></html>",+])+def test_empty_dedicated_reddit_listing_remains_no_results(body):+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch.object(reddit_listing.http, "get_text", return_value=body), \+ mock.patch("lib.reddit_arctic.fetch_listings", return_value=[]):+ report = pipeline.run_discover(+ domain="tea", config={}, as_of_date="2026-07-10",+ subreddits=["tea"],+ )++ assert report.source_status["reddit"].state == schema.NO_RESULTS+++def test_dedicated_reddit_challenge_fragment_reports_schema_drift():+ body = "<div class='challenge-platform'>Please verify you are human</div>"+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch.object(reddit_listing.http, "get_text", return_value=body), \+ mock.patch("lib.reddit_arctic.fetch_listings", return_value=[]):+ report = pipeline.run_discover(+ domain="tea", config={}, as_of_date="2026-07-10",+ subreddits=["tea"],+ )++ outcome = report.source_status["reddit"]+ assert outcome.state == schema.SCHEMA_DRIFT+ assert "interstitial" in (outcome.detail or "")+++def test_dedicated_reddit_search_challenge_fixture_reports_schema_drift():+ body = (REPO_ROOT / "fixtures/reddit_search_challenge.html").read_text(+ encoding="utf-8"+ )+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch.object(reddit_listing.http, "get_text", return_value=body), \+ mock.patch("lib.reddit_arctic.fetch_listings", return_value=[]):+ report = pipeline.run_discover(+ domain="tea", config={}, as_of_date="2026-07-10",+ subreddits=["tea"],+ )++ outcome = report.source_status["reddit"]+ assert outcome.state == schema.SCHEMA_DRIFT+ assert "interstitial" in (outcome.detail or "")+++def test_dedicated_reddit_verification_title_reports_schema_drift():+ body = "<html><title>Please wait for verification</title></html>"+ with mock.patch.object(pipeline, "available_sources", return_value=["reddit"]), \+ mock.patch.object(reddit_listing.http, "get_text", return_value=body), \+ mock.patch("lib.reddit_arctic.fetch_listings", return_value=[]):+ report = pipeline.run_discover(+ domain="tea", config={}, as_of_date="2026-07-10",+ subreddits=["tea"],+ )++ outcome = report.source_status["reddit"]+ assert outcome.state == schema.SCHEMA_DRIFT+ assert "interstitial" in (outcome.detail or "")+++def test_global_digg_empty_topic_skips_cli_without_fabricated_failure():+ plan = schema.DiscoveryPlan(+ domain="", category=None, subreddits=[], sources=["digg"],+ )+ with mock.patch.object(digg, "_run_cli") as run_cli:+ items, error = pipeline._fetch_discovery_source(+ "digg", plan, from_date="2026-06-10", to_date="2026-07-10",+ depth="default", mock=False, config={}, keyword_gate=False,+ )++ assert items == []+ assert error is None+ run_cli.assert_not_called()++def test_reddit_discovery_adapter_preserves_partial_feed_errors():"""When one shreddit sort lane fails and another succeeds, the failed lane's error is kept.