You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #585 committed sportsbook_reference_layer.py and action_network_layer.py as 1-line placeholders. The placeholder content causes uncaught NameError/SyntaxError exceptions that are NOT caught by except ImportError. Railway crashes on startup and every request returns 500 after PR #585 merged.
Fix 1 — sportsbook_reference_layer.py (CRITICAL: system down)
Replaced 1-line placeholder with a working module exporting build_sportsbook_reference().
Implements the full fallback chain: DK Tier 0 → FD 0.5 → Redis cache → AN supplement (always-run) → TheRundown all 9 markets.
Includes the PR #585 intended content.
Fix 2 — action_network_layer.py (CRITICAL: system down)
Replaced 1-line placeholder (placeholder — will be overwritten by localPath) with a working module.
Exports: fetch_mlb_prop_projections, fetch_mlb_game_sentiment, build_sharp_report, fetch_live_projections, fetch_all_projections.
Includes PR #585 fixes: pitcher_walks → walks_allowed, clamp widened to max(0.30, min(0.70, ...)).
Fix 3 — tasklets.py line 6373 — layer_audit missing from INSERT tuple (CORRUPTION)
The bet_ledger INSERT had 20 columns (18 %s + 2 hardcoded) but only 17 values in the Python tuple. layer_audit was listed as a column with no value → psycopg2 raises TypeError silently on every INSERT → zero picks written to bet_ledger since PR #582. Added _sl.get("_layer_audit") as the 18th tuple value.
model_prob is stored as 0–100 (e.g. 68.3). Training filter was model_prob >= 0.59 (always TRUE). Changed to model_prob >= 59. Without this, 75 historically gate-bypassed rows (model_prob ~55.0) contaminate XGB training.
Fix 5 — tasklets.py line 5634 — _get_props early-exit on PrizePicks (BUG)
PP-first path was return props without UD props. Underdog props were silently dropped on days where PP loaded first. Now calls _extract_underdog_props(hub) and extends before returning.
Summary by cubic
Replaced placeholder sportsbook and Action Network layers with working modules to stop startup crashes. Fixed bet_ledger INSERT values, corrected XGB probability threshold, and ensured Underdog props are included when PrizePicks loads first.
Bug Fixes
Restored sportsbook and Action Network layers with full fallback chain (DK → FD → Redis → ActionNetwork supplement → TheRundown). Exposes fetch/build helpers; widened implied-prob clamp and corrected walks_allowed mapping.
Added missing layer_audit to bet_ledger INSERT tuple so ledger writes resume.
Fixed XGB training filter to model_prob >= 59 (value is 0–100) to avoid bad rows in training.
Updated _get_props to include Underdog props when PP loads first.
The PR adds two new data-layer modules—action_network_layer.py for Action Network MLB prop projections and game sentiment, and sportsbook_reference_layer.py for aggregating references from multiple sportsbook/projection sources via multi-tier fallback lookup. It updates tasklets.py to include Underdog props in the PP-first path and to persist layer-audit metadata and correct a model-training threshold.
Changes
Action Network Data Integration and Reference Aggregation
Layer / File(s)
Summary
Action Network module setup and authentication action_network_layer.py (1–60)
Module docstring defines purpose and authentication via ACTION_NETWORK_COOKIE; market-name-to-prop_type mapping normalizes incoming market labels and corrects pitcher walks to walks_allowed; conditional auth headers include x-auth-token when cookie is present.
MLB prop projections REST fetching and parsing action_network_layer.py (62–123)
Public wrapper fetch_mlb_prop_projections() delegates to internal REST retrieval of Action Network games endpoint; iterates games and player props to normalize fields, extract line/ticket/money percentages with fallbacks, compute implied probability (clamped to [0.30, 0.70]), and return standardized dict entries; returns empty list on auth failure or parse errors.
Game sentiment and sharp-money signal derivation action_network_layer.py (125–189)
fetch_mlb_game_sentiment() fetches games and extracts away/home over/under ticket and money percentages keyed by team; build_sharp_report() derives OVER/UNDER "sharp_side" based on whether money% exceeds ticket% by 10pp threshold.
Projection utilities and pandas-based aggregation action_network_layer.py (191–214)
fetch_live_projections() aliases main projection fetch; fetch_all_projections() conditionally splits projections into batters and pitchers subsets when pandas is available.
Sportsbook reference builder entry point and error handling sportsbook_reference_layer.py (1–40)
Public build_sportsbook_reference() wraps internal _build() and returns empty dict on exceptions with warning log.
DraftKings and FanDuel sportsbook reference integration sportsbook_reference_layer.py (42–56)
Tier 0/0.5 fallback: loads sharp probabilities from draftkings_layer.get_dk_sharp_prob and fanduel_layer.get_fd_sharp_prob, merges results into reference map, swallows failures with debug logging.
Redis cache reference tier and day-scoped lookup sportsbook_reference_layer.py (68–86)
Tier 1: reads date-scoped Redis key sb_ref_{YYYYMMDD}, parses JSON entries into reference map, swallows parse/connection failures with debug logging.
ActionNetwork and TheRundown reference supplements sportsbook_reference_layer.py (87–173)
Tier 5 (always-run): calls action_network_layer.fetch_mlb_prop_projections(), computes implied probability from over-percent fields (clamped [0.30, 0.70]), inserts only absent keys with source tagging. Tier 6 (always-run): conditionally calls TheRundown RapidAPI with fixed market-id mapping, computes fair probability from moneyline values (defaulting 0.5 on errors), inserts absent keys with rounding and source tag.
Prop ingestion pipeline update with Underdog inclusion tasklets.py (5634–5642)
_get_props() in PP-first path now extends returned props with Underdog props from _extract_underdog_props(hub) when available, instead of returning only PrizePicks; includes corresponding log messages.
Bet ledger and model training updates tasklets.py (6373, 7907)
bet_ledger INSERT populates layer_audit column from _sl.get("_layer_audit") for persisted legs; run_xgboost_tasklet() training query corrects model_prob threshold from fractional 0.59 to percent-scale 59 for training-row qualification.
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
jaayslaughter-cpu/mework#258: Modifies action_network_layer.py authentication to prefer ACTION_NETWORK_JWT over ACTION_NETWORK_COOKIE in token sourcing.
jaayslaughter-cpu/mework#251: Introduces fetch_mlb_game_sentiment() in action_network_layer.py and its direct usage in tasklets.py for market sentiment data.
jaayslaughter-cpu/mework#406: Modifies sportsbook_reference_layer.py's Redis cache handling (sb_ref_{YYYYMMDD}) and reference population logic.
Poem
🐰 A rabbit hops through Action Network data,
Gathers projections, sentiment, and sharp signs with care,
Weaves them with sportsbooks in tiers of reference,
Underdog props now join PrizePicks with flair,
Layer audits recorded—the ledger complete!
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
✅ Passed
The title references 5 distinct bug fixes (crash files, INSERT tuple, XGB scale, _get_props, and layer_audit) addressing an emergency caused by PR #585, which aligns with the changeset's scope of restoring placeholder files and fixing multiple critical issues.
Docstring Coverage
✅ Passed
Docstring coverage is 91.67% 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 fix/pr586-emergency-5fixes
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.
We reviewed changes in 1e95712...9b58300 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
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.
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.
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds the action_network_layer.py and sportsbook_reference_layer.py modules to fetch MLB prop projections and aggregate sharp-line reference data. It also updates tasklets.py to include Underdog props in the PrizePicks workflow, record layer audit data, and adjust XGBoost probability filtering. The review identified critical performance and resource management issues in the reference layer due to blocking API calls and frequent Redis connection creation. Additionally, feedback was provided regarding inconsistent return types in error handling and the incorrect use of logical OR for numeric defaults, which would misinterpret zero-value percentages.
The reason will be displayed to describe this comment to others. Learn more.
The _build function (and consequently build_sportsbook_reference) has significant performance and resource management issues.
API Quota Exhaustion: It makes 9 blocking HTTP requests to TheRundown API (Tier 6) every time it is called. Since tasklets.py calls this function inside a loop for every prop (line 5945), a single cycle with 200 props would trigger 1,800 API calls, likely exhausting RapidAPI quotas and causing massive latency.
Connection Pooling: It creates a new Redis connection via from_url (line 76) on every call, which will quickly lead to connection pool exhaustion or file descriptor leaks.
This function must be memoized or the result should be cached in Redis/memory with a reasonable TTL (e.g., 5-10 minutes).
The reason will be displayed to describe this comment to others. Learn more.
The error handling paths return empty lists [] for batters and pitchers, but the success path (lines 207-208) returns pandas.DataFrame objects. Downstream callers (such as tasklets.py line 1396) that expect DataFrames and call attributes like .empty will raise an AttributeError if an exception occurs here.
The reason will be displayed to describe this comment to others. Learn more.
The use of the or operator for default values with numeric percentages (where 0 is a valid and significant value) will cause 0 to be incorrectly replaced by the fallback value (e.g., 50). In betting data, 0% money or tickets is a very strong signal that should not be normalized to 50%. This pattern is repeated for over_t, under_t, over_m, and under_m.
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.
OWASP Cross Site Scripting (XSS) Software Attack - OWASP community page with comprehensive information about cross site scripting, and links to various OWASP resources to help detect or prevent it.
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
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.
PR #586 — Emergency 5-Fix Patch
Why this is critical
PR #585 committed
sportsbook_reference_layer.pyandaction_network_layer.pyas 1-line placeholders. The placeholder content causes uncaughtNameError/SyntaxErrorexceptions that are NOT caught byexcept ImportError. Railway crashes on startup and every request returns 500 after PR #585 merged.Fix 1 —
sportsbook_reference_layer.py(CRITICAL: system down)Replaced 1-line placeholder with a working module exporting
build_sportsbook_reference().Implements the full fallback chain: DK Tier 0 → FD 0.5 → Redis cache → AN supplement (always-run) → TheRundown all 9 markets.
Includes the PR #585 intended content.
Fix 2 —
action_network_layer.py(CRITICAL: system down)Replaced 1-line placeholder (
placeholder — will be overwritten by localPath) with a working module.Exports:
fetch_mlb_prop_projections,fetch_mlb_game_sentiment,build_sharp_report,fetch_live_projections,fetch_all_projections.Includes PR #585 fixes:
pitcher_walks→walks_allowed, clamp widened tomax(0.30, min(0.70, ...)).Fix 3 —
tasklets.pyline 6373 —layer_auditmissing from INSERT tuple (CORRUPTION)The
bet_ledgerINSERT had 20 columns (18%s+ 2 hardcoded) but only 17 values in the Python tuple.layer_auditwas listed as a column with no value → psycopg2 raisesTypeErrorsilently on every INSERT → zero picks written tobet_ledgersince PR #582. Added_sl.get("_layer_audit")as the 18th tuple value.Fix 4 —
tasklets.pyline 7907 — XGB threshold scale mismatch (CORRUPTION)model_probis stored as 0–100 (e.g.68.3). Training filter wasmodel_prob >= 0.59(always TRUE). Changed tomodel_prob >= 59. Without this, 75 historically gate-bypassed rows (model_prob ~55.0) contaminate XGB training.Fix 5 —
tasklets.pyline 5634 —_get_propsearly-exit on PrizePicks (BUG)PP-first path was
return propswithout UD props. Underdog props were silently dropped on days where PP loaded first. Now calls_extract_underdog_props(hub)and extends before returning.Summary by cubic
Replaced placeholder sportsbook and Action Network layers with working modules to stop startup crashes. Fixed
bet_ledgerINSERT values, corrected XGB probability threshold, and ensured Underdog props are included when PrizePicks loads first.walks_allowedmapping.layer_audittobet_ledgerINSERT tuple so ledger writes resume.model_prob >= 59(value is 0–100) to avoid bad rows in training._get_propsto include Underdog props when PP loads first.Written for commit 9b58300. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
New Features
Bug Fixes