Files
codex/codex-rs/tui/src/chatwidget/warnings.rs
T
canvrno-oai d5f0b6d63a [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.
2026-05-06 13:11:44 -07:00

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)
}