-
Notifications
You must be signed in to change notification settings - Fork 7.2k
feat: tui start shouldn't wait for model to resolve
#8717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aibrahim-oai
wants to merge
19
commits into
main
Choose a base branch
from
async-tui-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9cd4d89
async
aibrahim-oai c982cbd
files
aibrahim-oai a944b0e
files
aibrahim-oai ff5f74b
models
aibrahim-oai 5f56a23
models
aibrahim-oai 88d090a
models
aibrahim-oai d7b0997
models
aibrahim-oai 5c79085
models
aibrahim-oai 0239053
models
aibrahim-oai dbd5c6a
models
aibrahim-oai 083d8d8
models
aibrahim-oai a32c06f
Merge branch 'main' into async-tui-1
aibrahim-oai 1907557
Apply reasoning-effort mapping on migration accept
aibrahim-oai 706e92f
tests
aibrahim-oai 0f3c232
tests
aibrahim-oai 284dc5c
models
aibrahim-oai 91bc7fc
tui2
aibrahim-oai bf37fe6
tui2
aibrahim-oai 7fe7b7b
snap
aibrahim-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ use std::collections::HashSet; | |
| use std::path::PathBuf; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
| use tokio::sync::Mutex; | ||
| use tokio::sync::RwLock; | ||
| use tokio::sync::TryLockError; | ||
| use tracing::error; | ||
|
|
@@ -39,6 +40,7 @@ pub struct ModelsManager { | |
| // todo(aibrahim) merge available_models and model family creation into one struct | ||
| local_models: Vec<ModelPreset>, | ||
| remote_models: RwLock<Vec<ModelInfo>>, | ||
| refresh_lock: Mutex<()>, | ||
| auth_manager: Arc<AuthManager>, | ||
| etag: RwLock<Option<String>>, | ||
| codex_home: PathBuf, | ||
|
|
@@ -53,6 +55,7 @@ impl ModelsManager { | |
| Self { | ||
| local_models: builtin_model_presets(auth_manager.get_auth_mode()), | ||
| remote_models: RwLock::new(Self::load_remote_models_from_file().unwrap_or_default()), | ||
| refresh_lock: Mutex::new(()), | ||
| auth_manager, | ||
| etag: RwLock::new(None), | ||
| codex_home, | ||
|
|
@@ -68,6 +71,7 @@ impl ModelsManager { | |
| Self { | ||
| local_models: builtin_model_presets(auth_manager.get_auth_mode()), | ||
| remote_models: RwLock::new(Self::load_remote_models_from_file().unwrap_or_default()), | ||
| refresh_lock: Mutex::new(()), | ||
| auth_manager, | ||
| etag: RwLock::new(None), | ||
| codex_home, | ||
|
|
@@ -78,6 +82,7 @@ impl ModelsManager { | |
|
|
||
| /// Fetch the latest remote models, using the on-disk cache when still fresh. | ||
| pub async fn refresh_available_models_with_cache(&self, config: &Config) -> CoreResult<()> { | ||
| let _refresh_guard = self.refresh_lock.lock().await; | ||
| if !config.features.enabled(Feature::RemoteModels) | ||
| || self.auth_manager.get_auth_mode() == Some(AuthMode::ApiKey) | ||
| { | ||
|
|
@@ -104,10 +109,23 @@ impl ModelsManager { | |
| let client = ModelsClient::new(transport, api_provider, api_auth); | ||
|
|
||
| let client_version = format_client_version_to_whole(); | ||
| let (models, etag) = client | ||
| .list_models(&client_version, HeaderMap::new()) | ||
| .await | ||
| .map_err(map_api_error)?; | ||
| let remote_models = tokio::time::timeout( | ||
| Duration::from_secs(5), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit add const |
||
| client.list_models(&client_version, HeaderMap::new()), | ||
| ) | ||
| .await; | ||
|
|
||
| let (models, etag) = match remote_models { | ||
| Ok(Ok((models, etag))) => (models, etag), | ||
| Ok(Err(err)) => { | ||
| error!("failed to refresh remote models: {}", map_api_error(err)); | ||
| return Ok(()); | ||
| } | ||
| Err(_) => { | ||
| error!("timed out refreshing remote models after 5s"); | ||
| return Ok(()); | ||
| } | ||
| }; | ||
|
|
||
| self.apply_remote_models(models.clone()).await; | ||
| *self.etag.write().await = etag.clone(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this lock in the same place we do the network call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's purpose is to avoid multiple parallel network calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to attempt a refresh after we have cache as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that's already handled with
if self.try_load_cache().await {no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if two instances hit
refresh_available_models_with_cacheat time 0 and 1.Then, both won't find cache.
both will do a call.
both will update cache
What I want is, if one is already updating, wait then read the cache because it will exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do double check lock (https://en.wikipedia.org/wiki/Double-checked_locking)