fix(openai): read lazily discovered models in /v1/models endpoint - #564
Conversation
BasicWorker.models() was returning from immutable metadata instead of models_override, so the /v1/models response was empty for wildcard proxy workers even after successful model refresh. Also replaced RwLock with ArcSwap for lock-free reads on the hot path. Signed-off-by: Chang Su <chang.s.su@oracle.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughReplaced lock-based model override storage with lock-free ArcSwap in the Worker trait and BasicWorker. The Worker trait's Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug where the OpenAI Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a bug where lazily discovered models were not being returned by the /v1/models endpoint for wildcard workers. The migration from RwLock to ArcSwap is a significant improvement, enhancing performance on read-heavy hot paths and simplifying the code by removing lock management boilerplate. The modification to the Worker::models() trait method to return a Vec<ModelCard> is a logical and necessary change to support this fix. I have a couple of suggestions to further refine the code for clarity and conciseness.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@model_gateway/src/core/worker.rs`:
- Around line 657-665: Add a regression unit test that verifies the wildcard
lazy-discovery path: create a wildcard worker (the Worker/WorkerMetadata used in
tests), assert initially models() returns empty, has_models_discovered() is
false and supports_model(...) is false for a sample model; then call
set_models(...) with a Vec<ModelCard> and assert afterwards that models()
returns the new WorkerModels (match length/content), supports_model(...) returns
true for a model present in the Vec, and has_models_discovered() is true. Use
the existing Worker::set_models, Worker::models(), Worker::supports_model(), and
Worker::has_models_discovered() methods and construct ModelCard instances
consistent with other tests so the test focuses only on lazy-discovery behavior.
Signed-off-by: Chang Su <chang.s.su@oracle.com>
Description
Problem
The OpenAI
/v1/modelsendpoint returns an empty model list for wildcard proxy workers. When a worker is in wildcard mode (no API key configured),refresh_external_models()correctly discovers models from backends and stores them viaset_models()intomodels_override. However,get_models()then callsworker.models()which reads from the immutablemetadata.spec.models— ignoring the lazily discovered models entirely.Solution
models()onBasicWorkerto checkmodels_overridefirst (same pattern assupports_model()andhas_models_discovered())&[ModelCard]toVec<ModelCard>so the override can return owned data from theArcSwapRwLock<Option<WorkerModels>>withArcSwap<WorkerModels>for lock-free reads on the hot path (supports_modelis called on every request)Changes
worker.rs: AddedBasicWorker::models()override; replacedStdRwLockwithArcSwap; simplifiedsupports_model,set_models,has_models_discovered— no more lock guard boilerplateworker_builder.rs: Initializemodels_overridewithArcSwap::from_pointee(WorkerModels::Wildcard)instead ofRwLock::new(None)Test Plan
cargo check -p smgpassescargo test -p smg -- worker— all 14 worker tests passChecklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspassesSummary by CodeRabbit