[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
@@ -211,6 +211,7 @@ pub(super) async fn make_chatwidget_manual(
plan_type: None,
codex_rate_limit_reached_type: None,
rate_limit_warnings: RateLimitWarningState::default(),
warning_display_state: WarningDisplayState::default(),
rate_limit_switch_prompt: RateLimitSwitchPromptState::default(),
add_credits_nudge_email_in_flight: None,
adaptive_chunking: crate::streaming::chunking::AdaptiveChunkingPolicy::default(),
@@ -1323,6 +1323,34 @@ async fn warning_event_adds_warning_history_cell() {
);
}
#[tokio::test]
async fn repeated_model_metadata_warning_is_hidden_for_same_slug() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let warning = "Model metadata for `unknown-model` not found. Defaulting to fallback metadata; this can degrade performance and cause issues.";
handle_warning(&mut chat, warning);
handle_warning(&mut chat, warning);
let cells = drain_insert_history(&mut rx);
assert_eq!(cells.len(), 1, "expected one warning history cell");
let rendered = lines_to_single_string(&cells[0]);
assert!(
rendered.contains("unknown-model"),
"warning cell missing model slug: {rendered}"
);
}
#[tokio::test]
async fn repeated_generic_warning_is_not_hidden() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
handle_warning(&mut chat, "test warning message");
handle_warning(&mut chat, "test warning message");
let cells = drain_insert_history(&mut rx);
assert_eq!(cells.len(), 2, "expected both warning history cells");
}
#[tokio::test]
async fn status_line_invalid_items_warn_once() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+23
View File
@@ -0,0 +1,23 @@
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)
}