fix: rd_per_g line 345 + result ALTER TABLE + streak columns + ACTION_NETWORK_JWT#258
Conversation
…ON_NETWORK_JWT env var
📝 WalkthroughWalkthroughModified token preference logic in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Docker | Apr 8, 2026 1:28a.m. | Review ↗ | |
| JavaScript | Apr 8, 2026 1:28a.m. | Review ↗ | |
| Python | Apr 8, 2026 1:28a.m. | Review ↗ | |
| SQL | Apr 8, 2026 1:28a.m. | Review ↗ | |
| Secrets | Apr 8, 2026 1:28a.m. | Review ↗ |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
TIP This summary will be updated as you push new changes. Give us feedback
There was a problem hiding this comment.
Code Review
This pull request updates the token retrieval logic in action_network_layer.py to prioritize the ACTION_NETWORK_JWT environment variable and modifies terminology in bug_checker.py. However, the changes in bug_checker.py introduce a NameError by removing the json import and an AttributeError due to incorrect datetime usage, which also discards the required timezone context. It is recommended to restore the import and use the _pt_today() helper.
| try: | ||
| import json | ||
| today = datetime.now(_PT).strftime("%Y-%m-%d") | ||
| today = datetime.date.today().strftime("%Y-%m-%d") |
There was a problem hiding this comment.
The removal of import json will cause a NameError when json.load() is called at line 223. Additionally, datetime.date.today() will raise an AttributeError because datetime refers to the datetime.datetime class in this scope (due to the import on line 11), and it also loses the timezone context (_PT) used consistently throughout this file. It is recommended to restore the json import and use the existing _pt_today() helper.
| today = datetime.date.today().strftime("%Y-%m-%d") | |
| import json | |
| today = _pt_today() |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
action_network_layer.py (1)
581-587:⚠️ Potential issue | 🟡 MinorLog message is inconsistent with new token priority.
The token retrieval now correctly prefers
ACTION_NETWORK_JWToverACTION_NETWORK_COOKIE, but the log message on line 584 still only referencesACTION_NETWORK_COOKIE. This will mislead operators debugging authentication issues.Proposed fix to align log message with implementation
token = os.getenv("ACTION_NETWORK_JWT", os.getenv("ACTION_NETWORK_COOKIE", "")).strip() if not token: logger.info( - "[ActionNetwork] ACTION_NETWORK_COOKIE not set — " + "[ActionNetwork] ACTION_NETWORK_JWT/ACTION_NETWORK_COOKIE not set — " "prop projections unavailable; SharpFadeAgent will use Path 2." ) return []Additionally, consider updating the docstring at lines 550-553 and the module-level docstring at line 19 to document the new
ACTION_NETWORK_JWTpreference.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@action_network_layer.py` around lines 581 - 587, The info log that reports missing credentials is out of sync with the token lookup in which token = os.getenv("ACTION_NETWORK_JWT", os.getenv("ACTION_NETWORK_COOKIE", "")).strip(); update the logger.info call (the one referencing ACTION_NETWORK_COOKIE) to reflect the new precedence (e.g., mention ACTION_NETWORK_JWT preferred and fallback to ACTION_NETWORK_COOKIE or simply say neither ACTION_NETWORK_JWT nor ACTION_NETWORK_COOKIE is set) so operators aren't misled; also update the surrounding docstring(s) (the module-level docstring and the function/method docstring that describes Action Network auth) to document that ACTION_NETWORK_JWT is now preferred over ACTION_NETWORK_COOKIE.
🧹 Nitpick comments (1)
bug_checker.py (1)
233-256: Use consistent terminology for streak transitionsDoc/comment says “restart(s)” while code/metric naming still uses
resetsand output saysreset(s). Pick one term to avoid operator confusion during incident triage.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bug_checker.py` around lines 233 - 256, The code mixes “reset(s)” and “restart(s)”: rename the variable and all related text to a single term (choose either "resets" or "restarts") for consistency; update the local variable (currently resets), the SQL/comment context around last_updated, the detail string built in detail = f"... {resets} ...", and any status/metric naming logic (e.g., the resets > 10 check) so all identifiers and user-facing output use the chosen term consistently (refer to the variable resets, the detail string construction, the SQL that computes the count, and the threshold check).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bug_checker.py`:
- Around line 217-218: The code calls datetime.date.today() but datetime was
imported as the datetime class, which will raise AttributeError and uses local
time; replace that with a UTC-based call such as
datetime.utcnow().date().strftime("%Y-%m-%d") (or
datetime.utcnow().date().isoformat()) when computing the today string used for
cache_path (the variables today and cache_path in bug_checker.py) so the call is
valid and uses UTC to match sportsbook_reference_layer.py's cache writer.
---
Outside diff comments:
In `@action_network_layer.py`:
- Around line 581-587: The info log that reports missing credentials is out of
sync with the token lookup in which token = os.getenv("ACTION_NETWORK_JWT",
os.getenv("ACTION_NETWORK_COOKIE", "")).strip(); update the logger.info call
(the one referencing ACTION_NETWORK_COOKIE) to reflect the new precedence (e.g.,
mention ACTION_NETWORK_JWT preferred and fallback to ACTION_NETWORK_COOKIE or
simply say neither ACTION_NETWORK_JWT nor ACTION_NETWORK_COOKIE is set) so
operators aren't misled; also update the surrounding docstring(s) (the
module-level docstring and the function/method docstring that describes Action
Network auth) to document that ACTION_NETWORK_JWT is now preferred over
ACTION_NETWORK_COOKIE.
---
Nitpick comments:
In `@bug_checker.py`:
- Around line 233-256: The code mixes “reset(s)” and “restart(s)”: rename the
variable and all related text to a single term (choose either "resets" or
"restarts") for consistency; update the local variable (currently resets), the
SQL/comment context around last_updated, the detail string built in detail =
f"... {resets} ...", and any status/metric naming logic (e.g., the resets > 10
check) so all identifiers and user-facing output use the chosen term
consistently (refer to the variable resets, the detail string construction, the
SQL that computes the count, and the threshold check).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d663a35b-43bf-418f-a269-7efd82e4b19d
📒 Files selected for processing (2)
action_network_layer.pybug_checker.py
| today = datetime.date.today().strftime("%Y-%m-%d") | ||
| cache_path = f"/tmp/sb_ref_{today}.json" |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify datetime import style and cache-date derivation points.
rg -n -C2 'from datetime import datetime, timezone, timedelta|datetime\.date\.today\(|datetime\.now\(timezone\.utc\)' bug_checker.py sportsbook_reference_layer.pyRepository: jaayslaughter-cpu/mework
Length of output: 1317
Fix cache-date derivation: current call is invalid and timezone-inconsistent
Line 217 uses datetime.date.today() even though datetime is imported as the datetime.datetime class; this will raise AttributeError at runtime. Also, this check should use UTC date to match sportsbook_reference_layer.py cache writer behavior.
Suggested fix
- today = datetime.date.today().strftime("%Y-%m-%d")
+ # Keep date basis aligned with sportsbook_reference_layer cache writes (UTC).
+ today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
cache_path = f"/tmp/sb_ref_{today}.json"🧰 Tools
🪛 Ruff (0.15.9)
[error] 218-218: Probable insecure usage of temporary file or directory: "/tmp/sb_ref_"
(S108)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@bug_checker.py` around lines 217 - 218, The code calls datetime.date.today()
but datetime was imported as the datetime class, which will raise AttributeError
and uses local time; replace that with a UTC-based call such as
datetime.utcnow().date().strftime("%Y-%m-%d") (or
datetime.utcnow().date().isoformat()) when computing the today string used for
cache_path (the variables today and cache_path in bug_checker.py) so the call is
valid and uses UTC to match sportsbook_reference_layer.py's cache writer.
Four fixes from Apr 8 audit:
game_prediction_layer.py — line 345
h["rd_per_g"]→h["home_rd_per_g"]. Kills last GamePred KeyError crash every cycle.tasklets.py —
ALTER TABLE bet_ledger ADD COLUMN IF NOT EXISTS result VARCHAR(10)added to_ensure_bet_ledger(). Permanent guard so result column survives any DB reprovision.bug_checker.py —
streak_count→current_count,updated_at→last_updatedin_check_streak_state(). Fixes the column-does-not-exist error on every 10 AM health check since yesterday.action_network_layer.py — env var now reads
ACTION_NETWORK_JWTfirst, falls back toACTION_NETWORK_COOKIE. This is why Action Network returned empty arrays every cycle — token was set as JWT in Railway but code was reading COOKIE. Fixes SharpFadeAgent Path 1 / sharp prop data.Summary by cubic
Fixes four production issues: a GamePred KeyError, missing
bet_ledger.result, incorrect streak column names, and Action Network auth lookup. This stabilizes prediction runs and restores Action Network prop data.Bug Fixes
home_rd_per_ginstead ofrd_per_gto eliminate the KeyError.bet_ledger.resultexists viaALTER TABLEin_ensure_bet_ledger().ud_streak_statewithcurrent_countandlast_updatedto stop column-not-found errors.ACTION_NETWORK_JWTwith fallback toACTION_NETWORK_COOKIEfor live and daily projections.Migration
bet_ledger.resultif missing; setACTION_NETWORK_JWTto use a JWT token (cookie still supported).Written for commit 6384944. Summary will update on new commits.
Summary by CodeRabbit