⚡ Offload synchronous AA scores loading to thread#98
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Sorry @sheepdestroyer, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 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 |
Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
565a4c3 to
31b17d8
Compare
|
@gemini /review |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Code Review
This pull request refactors how agentic index scores are loaded by moving the synchronous _load_aa_scores call out of the synchronous compute_free_model_score function and instead loading them asynchronously via asyncio.to_thread in the asynchronous entry points sync_adaptive_router_roster and get_best_free_model. Tests are also updated to manually trigger the score loading. The reviewer pointed out a potential race condition where concurrent calls to these asynchronous functions could trigger redundant thread creation and file reads, and suggested using an asyncio.Lock to ensure thread-safe initialization.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
router/main.py (1)
1177-1179: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winFail fast when the AA cache has not been initialized.
This function now treats an unloaded cache exactly like an unknown model and returns
25.0for everything. That makes any missed preload guard silently degrade model ranking instead of surfacing the contract break. Please add an explicit_AA_SCORES_LOADEDcheck here or route callers through a sharedensure_aa_scores_loaded()helper.Proposed change
def compute_free_model_score(m: dict) -> float: """Return AA agentic index score, or a low default for unknown models.""" + if not _AA_SCORES_LOADED: + raise RuntimeError("AA scores must be loaded before scoring free models") mid = m.get("id", "") return _AA_SCORES_CACHE.get(mid, 25.0)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@router/main.py` around lines 1177 - 1179, The AA score lookup in the function that reads from _AA_SCORES_CACHE should fail fast when the cache has not been initialized instead of silently returning the default 25.0 for every model. Add an explicit _AA_SCORES_LOADED guard in this lookup path, or have callers go through a shared ensure_aa_scores_loaded() helper before accessing the cache, so the contract break is surfaced immediately rather than treated as an unknown model.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@router/main.py`:
- Around line 1177-1179: The AA score lookup in the function that reads from
_AA_SCORES_CACHE should fail fast when the cache has not been initialized
instead of silently returning the default 25.0 for every model. Add an explicit
_AA_SCORES_LOADED guard in this lookup path, or have callers go through a shared
ensure_aa_scores_loaded() helper before accessing the cache, so the contract
break is surfaced immediately rather than treated as an unknown model.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cca88478-0fdf-4df6-abaa-e89ba0d31bb7
📒 Files selected for processing (2)
router/main.pytest_compute_free_model_score.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
@jules In |
Added an explicit |
Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
💡 What:
Removed the blocking synchronous call to
_load_aa_scores()fromcompute_free_model_score(). Instead,_load_aa_scores()is now offloaded to a background thread usingawait asyncio.to_thread(_load_aa_scores)outside of the loop in bothsync_adaptive_router_rosterandget_best_free_model.🎯 Why:
The
_load_aa_scores()method contains a synchronous file read (json.load(f)). When placed insidecompute_free_model_score(), this blocking I/O operation occurs sequentially for every model returned by the OpenRouter API during the first execution or cache miss. This blocks the main event loop, significantly increasing latency for all concurrent requests and delaying theget_best_free_model()operation. By pre-loading it once asynchronously using a thread pool, the event loop remains unblocked.📊 Measured Improvement:
PR created automatically by Jules for task 16551127323385849872 started by @sheepdestroyer
Summary by CodeRabbit