mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
d5f0b6d63a
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.
24 lines
840 B
Rust
24 lines
840 B
Rust
use std::collections::HashSet;
|
|
|
|
const FALLBACK_MODEL_METADATA_WARNING_PREFIX: &str = "Model metadata for `";
|
|
const FALLBACK_MODEL_METADATA_WARNING_SUFFIX: &str =
|
|
"` not found. Defaulting to fallback metadata; this can degrade performance and cause issues.";
|
|
|
|
#[derive(Default)]
|
|
pub(super) struct WarningDisplayState {
|
|
fallback_model_metadata_slugs: HashSet<String>,
|
|
}
|
|
|
|
impl WarningDisplayState {
|
|
pub(super) fn should_display(&mut self, message: &str) -> bool {
|
|
fallback_model_metadata_warning_slug(message)
|
|
.is_none_or(|slug| self.fallback_model_metadata_slugs.insert(slug.to_string()))
|
|
}
|
|
}
|
|
|
|
fn fallback_model_metadata_warning_slug(message: &str) -> Option<&str> {
|
|
message
|
|
.strip_prefix(FALLBACK_MODEL_METADATA_WARNING_PREFIX)?
|
|
.strip_suffix(FALLBACK_MODEL_METADATA_WARNING_SUFFIX)
|
|
}
|