mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Dedupe fallback model metadata warnings (#21090)
Fixes #21070. This is a small cleanup around model metadata handling for gateway/provider model names. It follows the report and proposed direction from @dkbush by keeping the fallback metadata warning useful without repeating it every turn, and by tightening the existing provider-prefix lookup path. - Track fallback metadata warning slugs in session state so each unresolved model warns once per session. - Keep warning emission outside the session-state lock and preserve the existing warning text. - Allow one-segment provider prefixes with hyphenated provider IDs, while preserving the multi-segment rejection behavior. - Add focused coverage for warning dedupe and hyphenated provider-prefix metadata matching. Testing: - Ran `just fmt`. - Ran `git diff --check`. - Added tests for the new warning dedupe and provider-prefix lookup behavior.
This commit is contained in:
committed by
GitHub
Unverified
parent
63a27ad6c6
commit
d5f0b6d63a
@@ -421,15 +421,16 @@ fn find_model_by_longest_prefix(model: &str, candidates: &[ModelInfo]) -> Option
|
||||
fn find_model_by_namespaced_suffix(model: &str, candidates: &[ModelInfo]) -> Option<ModelInfo> {
|
||||
// Retry metadata lookup for a single namespaced slug like `namespace/model-name`.
|
||||
//
|
||||
// This only strips one leading namespace segment and only when the namespace is ASCII
|
||||
// alphanumeric/underscore (`\w+`) to avoid broadly matching arbitrary aliases.
|
||||
// This only strips one leading namespace segment and only when the namespace looks
|
||||
// like a simple provider id to avoid broadly matching arbitrary aliases.
|
||||
let (namespace, suffix) = model.split_once('/')?;
|
||||
if suffix.contains('/') {
|
||||
return None;
|
||||
}
|
||||
if !namespace
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '_')
|
||||
if namespace.is_empty()
|
||||
|| !namespace
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -295,6 +295,21 @@ async fn get_model_info_matches_namespaced_suffix() {
|
||||
assert!(!model_info.used_fallback_model_metadata);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_model_info_matches_hyphenated_provider_namespace_suffix() {
|
||||
let config = ModelsManagerConfig::default();
|
||||
let remote = remote_model("gpt-image", "Image", /*priority*/ 0);
|
||||
let manager = static_manager_for_tests(ModelsResponse {
|
||||
models: vec![remote],
|
||||
});
|
||||
let namespaced_model = "openai-codex/gpt-image".to_string();
|
||||
|
||||
let model_info = manager.get_model_info(&namespaced_model, &config).await;
|
||||
|
||||
assert_eq!(model_info.slug, namespaced_model);
|
||||
assert!(!model_info.used_fallback_model_metadata);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_model_info_rejects_multi_segment_namespace_suffix_matching() {
|
||||
let codex_home = tempdir().expect("temp dir");
|
||||
|
||||
Reference in New Issue
Block a user