Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix: preserve requested Reddit search date windows (#1213)

Ilia Alshanetskya19d5e1f4b91
diff --git a/changelog.d/+cr-013-reddit-date-window.fixed.md b/changelog.d/+cr-013-reddit-date-window.fixed.md
new file mode 100644
index 00000000..e522791e
--- /dev/null
+++ b/changelog.d/+cr-013-reddit-date-window.fixed.md
@@ -0,0 +1 @@
+Paid Reddit search preserves the requested date range at every research depth, including historical windows.
diff --git a/skills/last30days/scripts/lib/reddit.py b/skills/last30days/scripts/lib/reddit.py
index c662d7df..e56b5d92 100644
--- a/skills/last30days/scripts/lib/reddit.py
+++ b/skills/last30days/scripts/lib/reddit.py
@@ -42,19 +42,16 @@ DEPTH_CONFIG = {
"global_searches": 1,
"subreddit_searches": 2,
"comment_enrichments": 3,
- "timeframe": "week",
},
"default": {
"global_searches": 2,
"subreddit_searches": 3,
"comment_enrichments": 5,
- "timeframe": "month",
},
"deep": {
"global_searches": 3,
"subreddit_searches": 5,
"comment_enrichments": 8,
- "timeframe": "month",
},
}
@@ -456,9 +453,6 @@ def _dedupe_posts(posts: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
return unique
-_TIMEFRAME_ORDER = {"hour": 0, "day": 1, "week": 2, "month": 3, "year": 4, "all": 5}
-
-
def _days_to_reddit_bucket(days: float) -> str:
"""Map a day count onto the smallest Reddit rolling bucket that covers it.
@@ -489,7 +483,7 @@ def _window_to_time_filter(from_date: str, to_date: str) -> str:
bucket that reaches ``from_date``; span-alone would pick ``week`` and
the API would omit the entire requested range.
- Take the wider of the two; the caller then mins with the depth default.
+ Take the wider of the two, independently of retrieval depth.
Phase 5 still trims to ``from_date``/``to_date``. Falls back to ``month``
if the dates don't parse.
"""
@@ -531,13 +525,7 @@ def search_reddit(
return {"items": [], "error": "No SCRAPECREATORS_API_KEY configured"}
config = DEPTH_CONFIG.get(depth, DEPTH_CONFIG["default"])
- # Fetch window must track the requested date range, not just the depth
- # default. Otherwise a --days 1 request fetches a month of relevance-
- # sorted posts and Phase 5 discards everything outside 24h (0 on quiet
- # days). Use the tighter of {window-derived, depth default}.
- _depth_tf = config["timeframe"]
- _window_tf = _window_to_time_filter(from_date, to_date)
- timeframe = _window_tf if _TIMEFRAME_ORDER.get(_window_tf, 3) <= _TIMEFRAME_ORDER.get(_depth_tf, 3) else _depth_tf
+ timeframe = _window_to_time_filter(from_date, to_date)
intent = infer_query_intent(topic)
# === Phase 1: Query Expansion ===
diff --git a/tests/test_reddit.py b/tests/test_reddit.py
index 9dbaa23a..6189ee72 100644
--- a/tests/test_reddit.py
+++ b/tests/test_reddit.py
@@ -1,5 +1,7 @@
import unittest
+import pytest
+
from lib.reddit import (
_extract_date,
_extract_score,
@@ -304,3 +306,39 @@ def test_window_to_time_filter_covers_historical_from_date(monkeypatch):
# One-day request ending two weeks ago: span alone would pick "week" and
# miss the entire range; age of from_date requires "month".
assert reddit._window_to_time_filter("2026-07-09", "2026-07-10") == "month"
+
+
+ "depth,from_date,to_date,expected",
+ [
+ ("default", "2026-04-25", "2026-07-24", "year"),
+ ("quick", "2026-06-24", "2026-07-24", "month"),
+ ("deep", "2026-04-25", "2026-07-24", "year"),
+ ("quick", "2026-07-09", "2026-07-10", "month"),
+ ("default", "2026-07-23", "2026-07-24", "week"),
+ ("deep", "2026-07-23", "2026-07-24", "week"),
+ ],
+)
+def test_search_reddit_requests_complete_date_window(monkeypatch, depth, from_date, to_date, expected):
+ from datetime import datetime, timezone
+ from unittest.mock import Mock
+
+ from lib import reddit
+
+ clock = Mock()
+ clock.now.return_value = datetime(2026, 7, 24, tzinfo=timezone.utc)
+ monkeypatch.setattr(reddit, "datetime", clock)
+ global_search = Mock(return_value=[])
+ subreddit_search = Mock(return_value=[])
+ monkeypatch.setattr(reddit, "_global_search", global_search)
+ monkeypatch.setattr(reddit, "_subreddit_search", subreddit_search)
+
+ reddit.search_reddit(
+ "Python", from_date, to_date, depth=depth,
+ token="dummy-scrapecreators-key", subreddits=["Python"],
+ )
+
+ assert global_search.call_count > 0
+ assert subreddit_search.call_count > 0
+ assert {call.args[-1] for call in global_search.call_args_list} == {expected}
+ assert {call.args[-1] for call in subreddit_search.call_args_list} == {expected}
diff --git a/tests/test_reddit_sc.py b/tests/test_reddit_sc.py
index f52d8f54..80d7ed61 100644
--- a/tests/test_reddit_sc.py
+++ b/tests/test_reddit_sc.py
@@ -143,7 +143,7 @@ class TestDepthConfig(unittest.TestCase):
self.assertIn(depth, reddit.DEPTH_CONFIG)
def test_required_keys(self):
- required = {"global_searches", "subreddit_searches", "comment_enrichments", "timeframe"}
+ required = {"global_searches", "subreddit_searches", "comment_enrichments"}
for depth, config in reddit.DEPTH_CONFIG.items():
self.assertTrue(required.issubset(config.keys()),
f"Missing keys in {depth}: {required - config.keys()}")