Skip to content

PR #571: Fix bp2vec TensorFlow crash — graceful fallback + add TF to requirements#440

Merged
jaayslaughter-cpu merged 1 commit into
mainfrom
pr-571-bp2vec-tf-fix
May 15, 2026
Merged

PR #571: Fix bp2vec TensorFlow crash — graceful fallback + add TF to requirements#440
jaayslaughter-cpu merged 1 commit into
mainfrom
pr-571-bp2vec-tf-fix

Conversation

@jaayslaughter-cpu
Copy link
Copy Markdown
Owner

@jaayslaughter-cpu jaayslaughter-cpu commented May 15, 2026

Problem

job_bp2vec_retrain crashed every run with ModuleNotFoundError: No module named 'tensorflow', then called sys.exit(1) which disrupted the APScheduler event loop (caused one CancelledError in job_data_hub).

Fixes

1. bp2vec_train.py — graceful fallback

  • build_model(): sys.exit(1)return None in ImportError handler
  • train(): guard added after build_model() — if model is None, log warning and return cleanly instead of crashing on model.summary()

2. requirements_army.txt — add TensorFlow

  • tensorflow>=2.15.0 added — enables actual bp2vec embedding training

After this deploy, job_bp2vec_retrain will complete successfully.


Summary by cubic

Stops job_bp2vec_retrain from crashing when tensorflow is missing and adds tensorflow to requirements so bp2vec training can run without disrupting APScheduler.

  • Bug Fixes

    • build_model(): on ImportError, log and return None instead of sys.exit(1).
    • train(): guard for None model; log and exit early to avoid APScheduler cancellations.
  • Dependencies

    • Add tensorflow>=2.15.0 to requirements_army.txt.

Written for commit bb35f4a. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Training pipeline now gracefully handles missing dependencies with informative logging, allowing the system to continue instead of terminating unexpectedly.
  • Chores

    • Added required ML training library to project dependencies.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR adds TensorFlow as a dependency and refactors the training pipeline to gracefully handle missing TensorFlow. Instead of terminating on import failure, build_model() now logs an error and returns None. The train() function detects this None and aborts with a warning, allowing caller-level error handling.

Changes

TensorFlow graceful failure

Layer / File(s) Summary
Dependency and build_model error handling
requirements_army.txt, bp2vec_train.py
tensorflow>=2.15.0 is added to the dependency list. build_model() catches TensorFlow import failures, logs an error, and returns None instead of exiting the process.
Train pipeline null-check
bp2vec_train.py
train() checks whether build_model() returned None and exits early with a warning log instead of calling model.summary() or proceeding to fitting.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

A rabbit once trained with great care,
When TensorFlow failed, the process would spare—
No exit, no crash, just a note in the log,
Then train() would gracefully pause through the fog. 🐰🧠

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: fixing a TensorFlow crash through graceful fallback handling and adding TensorFlow to requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr-571-bp2vec-tf-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented May 15, 2026

DeepSource Code Review

We reviewed changes in 95671fa...bb35f4a on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Docker May 15, 2026 4:32a.m. Review ↗
JavaScript May 15, 2026 4:32a.m. Review ↗
Python May 15, 2026 4:32a.m. Review ↗
SQL May 15, 2026 4:32a.m. Review ↗
Secrets May 15, 2026 4:32a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jaayslaughter-cpu jaayslaughter-cpu merged commit 6669289 into main May 15, 2026
7 of 9 checks passed
@secure-code-warrior-for-github
Copy link
Copy Markdown

Micro-Learning Topic: Cross-site scripting (Detected by phrase)

Matched on "XSS"

Cross-site scripting vulnerabilities occur when unescaped input is rendered into a page displayed to the user. When HTML or script is included in the input, it will be processed by a user's browser as HTML or script and can alter the appearance of the page or execute malicious scripts in their user context.

Try a challenge in Secure Code Warrior

Helpful references

Micro-Learning Topic: External entity injection (Detected by phrase)

Matched on "xXE"

What is this? (2min video)

An XML External Entity attack is a type of attack against an application that parses XML input. This attack occurs when XML input containing a reference to an external entity is processed by a weakly configured XML parser. This attack may lead to the disclosure of confidential data, denial of service, server-side request forgery, port scanning from the perspective of the machine where the parser is located, and other system impacts.

Try a challenge in Secure Code Warrior

Helpful references

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates bp2vec_train.py to handle missing TensorFlow dependencies more gracefully by returning None instead of calling sys.exit(1), and adds tensorflow to the requirements file. Feedback suggests addressing a remaining sys.exit(1) call in load_statcast_seasons to ensure consistent behavior and recommended moving the dependency check to the beginning of the train function to avoid unnecessary data processing.

Comment thread bp2vec_train.py
log.error("TensorFlow not installed. Run: pip install tensorflow")
sys.exit(1)
log.error("TensorFlow not installed — bp2vec training skipped. Add tensorflow to requirements_army.txt")
return None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The transition from sys.exit(1) to return None correctly addresses the issue of disrupting the scheduler's event loop. However, please note that load_statcast_seasons (line 130) still contains a sys.exit(1) call on pybaseball import failure. To fully achieve the goal of a graceful fallback and prevent process termination in a shared environment, that instance should also be updated to return or raise an exception instead of exiting.

Comment thread bp2vec_train.py
Comment on lines +315 to +317
if model is None:
log.warning("bp2vec training aborted — TensorFlow unavailable. Add tensorflow to requirements_army.txt")
return
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check correctly handles the case where TensorFlow is missing. However, it occurs after load_statcast_seasons and build_indices, which can be time-consuming (the docstring mentions 10-20 minutes). Consider performing a quick check for TensorFlow availability at the very beginning of the train function to "fail fast" and avoid unnecessary data processing when the dependency is unavailable.

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