Skip to content

Comments

Lazy-import similar_talks to fix Gunicorn worker OOM on startup#4569

Merged
patrick91 merged 1 commit intomainfrom
fix/lazy-import-similar-talks
Feb 9, 2026
Merged

Lazy-import similar_talks to fix Gunicorn worker OOM on startup#4569
patrick91 merged 1 commit intomainfrom
fix/lazy-import-similar-talks

Conversation

@patrick91
Copy link
Member

Summary

  • Moves the import of reviews.similar_talks from the top of admin.py into the view function that uses it
  • The module imports heavy ML libraries (sentence-transformers, bertopic, torch) at module level, which caused Gunicorn workers to OOM/timeout during boot and prevented the previous deploy from going live

Test plan

  • Merge and verify the deploy succeeds (health check passes)
  • Trigger the review recap analysis in admin and verify it still works

Move the import of reviews.similar_talks into the admin view that uses
it. The module imports heavy ML libraries (sentence-transformers,
bertopic, torch) which caused Gunicorn workers to OOM/timeout during
boot, preventing deployment.
@vercel
Copy link

vercel bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pycon Building Building Preview Feb 9, 2026 2:17pm

@patrick91 patrick91 merged commit 5fd9f3e into main Feb 9, 2026
5 of 7 checks passed
@patrick91 patrick91 deleted the fix/lazy-import-similar-talks branch February 9, 2026 14:18
@claude
Copy link
Contributor

claude bot commented Feb 9, 2026

Summary

Moves the import of heavy ML libraries (sentence-transformers, bertopic, torch) from module-level to function-level in reviews/admin.py to prevent Gunicorn worker OOM during startup.

Issues Found

Testing - Test mocks need updating

The lazy import breaks existing tests. Currently, tests mock reviews.admin.compute_similar_talks and reviews.admin.compute_topic_clusters, expecting these functions to be imported at module level. After this change, the functions are imported inside review_recap_compute_analysis_view(), so they no longer exist in the reviews.admin namespace.

Affected tests in backend/reviews/tests/test_recap.py:

  • test_recap_view_does_not_call_ml_functions (lines 111-112)
  • test_compute_analysis_view_returns_submissions_and_clusters (lines 189-203)
  • test_compute_analysis_view_passes_recompute_flag (lines 238-245)
  • test_compute_analysis_view_no_recompute_by_default (lines 262-270)

Fix needed: Change all mock paths from:

  • mocker.patch("reviews.admin.compute_similar_talks", ...)
  • mocker.patch("reviews.admin.compute_topic_clusters", ...)

To:

  • mocker.patch("reviews.similar_talks.compute_similar_talks", ...)
  • mocker.patch("reviews.similar_talks.compute_topic_clusters", ...)

This will patch the functions at their source module instead of where they were previously imported.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.50%. Comparing base (3cbed04) to head (28e8f73).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4569   +/-   ##
=======================================
  Coverage   92.50%   92.50%           
=======================================
  Files         355      355           
  Lines       10658    10658           
  Branches      812      812           
=======================================
  Hits         9859     9859           
  Misses        687      687           
  Partials      112      112           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant