[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:
canvrno-oai
2026-05-06 13:11:44 -07:00
committed by GitHub
Unverified
parent 63a27ad6c6
commit d5f0b6d63a
6 changed files with 82 additions and 6 deletions
+6 -5
View File
@@ -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;
}