Commit 6b33b08
fix(reddit): prevent enrichment timeout from discarding all search results
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>1 parent 4d6224f commit 6b33b08
1 file changed
+36
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
| 587 | + | |
587 | 588 | | |
588 | 589 | | |
589 | 590 | | |
590 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
591 | 604 | | |
592 | 605 | | |
593 | 606 | | |
594 | 607 | | |
595 | 608 | | |
596 | 609 | | |
597 | 610 | | |
| 611 | + | |
| 612 | + | |
598 | 613 | | |
599 | 614 | | |
600 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
601 | 618 | | |
602 | 619 | | |
603 | 620 | | |
604 | 621 | | |
605 | | - | |
606 | | - | |
607 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
608 | 639 | | |
609 | 640 | | |
610 | 641 | | |
| |||
0 commit comments