fix(reddit): prevent enrichment timeout from discarding all search results#116
Open
thinkun wants to merge 1 commit intomvanhorn:mainfrom
Open
fix(reddit): prevent enrichment timeout from discarding all search results#116thinkun wants to merge 1 commit intomvanhorn:mainfrom
thinkun wants to merge 1 commit intomvanhorn:mainfrom
Conversation
…sults Bug: When ScrapeCreators comment enrichment was slow (fetching top comments for 5 posts), the entire search_and_enrich() function could exceed the caller's 90-second ThreadPoolExecutor timeout. This raised a TimeoutError in last30days.py's result-collection phase, which left reddit_items as its initialized empty list [] — silently discarding all search results even though the search phase had already completed successfully (e.g. 116 posts found and deduped). The user would see contradictory output: [Reddit] Final: 116 Reddit posts ← logged during search [Reddit] Enriching comments for 5 posts ← enrichment starts ✗ Error: Reddit search timed out after 90s ← timeout fires ✓ Reddit Found 0 threads ← all results gone Root cause: search_and_enrich() ran enrichment synchronously in the same call stack as the search. There was no timeout boundary between the two phases, so a slow enrichment consumed the entire budget and the caller's future.result(timeout=90) would fire before the function could return. Fix: Run enrich_with_comments() in a dedicated thread with its own 45-second timeout (leaving ~45s for the search phase within the caller's 90s window). If enrichment times out or raises: - Search results are preserved and returned WITHOUT comments - A descriptive log message is emitted - The caller's future.result() succeeds normally The fix is backward-compatible: - New enrich_timeout param defaults to 45s (no caller changes needed) - enrich_timeout=0 skips enrichment entirely (useful for testing) - Successful enrichment behaves identically to before Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6b33b08 to
e5ded2c
Compare
|
Hit this exact issue running research in autonomous agent pipelines — logs show 100+ posts found, output says 0. The two-phase approach (return search results even if enrichment times out) is the right fix. Would love to see this merged. |
|
Error code has to be synchronized with the Github server |
|
.server has to be changed |
Owner
|
This is a real problem - losing 100+ search results because enrichment timed out is painful. The two-phase approach (return search results even if enrichment fails) is the right instinct. Can't commit to merging this as-is because the v3.0 rewrite completely rearchitects how source results flow through the pipeline, but I think the pattern is sound and I'll consider incorporating it. Thanks for the contribution. |
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
search_and_enrich()exceeds the caller's 90-secondThreadPoolExecutortimeout. The resultingTimeoutErrordiscards all search results — even though the search phase already completed successfully (e.g. 116 posts found and deduped). The user sees✓ Reddit Found 0 threadsdespite logs showing 116 posts were found.enrich_with_comments()in a dedicated thread with its own 45-second timeout. If enrichment times out or fails, search results are returned without comments instead of being thrown away. Backward-compatible — no caller changes needed.How to reproduce
/last30dayswith a broad topic that returns many Reddit results (e.g. "best local AI models across different use cases")reddit_future.result(timeout=90)deadline inlast30days.py**ERROR:** Reddit search timed out after 90sandReddit: 0 threadsRoot cause
search_and_enrich()ranenrich_with_comments()synchronously in the same call stack as the search. There was no timeout boundary between the two phases, so slow enrichment consumed the entire budget:Changes
scripts/lib/reddit.py—search_and_enrich()ThreadPoolExecutor(max_workers=1)with a 45-second timeoutTimeoutErroror any exception: search results are preserved, a log message is emittedenrich_timeoutparameter (default 45s, set to 0 to skip enrichment)Test plan
/last30dayswith a topic that triggers Reddit search — verify Reddit results appear in outputtime.sleep(60)at top ofenrich_with_comments) — verify search results are returned without comments and log shows timeout messageenrich_timeout=0skips enrichment entirely🤖 Generated with Claude Code