Skip to content

Commit f046a98

Browse files
committed
fix(antigravity): keep alias-mapped IDs and explicit names across copies
Two gaps in the explicit-name fallback, reported by CodeRabbit on #2071: - Some IDs are not in `model_name_from_id` but their placeholder is mapped by `normalize_antigravity_model` (for example 1187 -> gemini-3.5-flash-extra-low). Treating them as unknown let the row's name override that mapping. - When the same usage is recorded in a step row without a model name and in a generation row with one, the step copy is merged first and its placeholder survived because `merge_usage_event` only replaced the default model. Decide "unresolved" from the normalized result instead of the raw ID table, and let the merge replace any unresolved model, not only the default one.
1 parent 97c42c7 commit f046a98

2 files changed

Lines changed: 115 additions & 44 deletions

File tree

‎rust/adapters/antigravity/src/loader.rs‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,74 @@ mod tests {
10131013
assert_eq!(retry.model.as_deref(), Some("model_placeholder_m499"));
10141014
}
10151015

1016+
#[test]
1017+
fn keeps_alias_mapped_ids_over_explicit_model_name() {
1018+
let fixture = Fixture::new();
1019+
create_database(
1020+
&fixture.path("conversations/session.db"),
1021+
&[(
1022+
0,
1023+
metadata_blob(
1024+
Some("gemini-3-flash-agent"),
1025+
Some(UsageFixture {
1026+
model_id: Some(1187),
1027+
input_tokens: 60,
1028+
total_output_tokens: 10,
1029+
visible_output_tokens: 10,
1030+
..UsageFixture::default()
1031+
}),
1032+
Some((1_781_481_600, 0)),
1033+
&[],
1034+
),
1035+
)],
1036+
&[],
1037+
&[],
1038+
);
1039+
1040+
let entries = load_from_fixture(&fixture, true);
1041+
1042+
assert_eq!(entries.len(), 1);
1043+
assert_eq!(
1044+
entries[0].model.as_deref(),
1045+
Some("gemini-3.5-flash-extra-low")
1046+
);
1047+
}
1048+
1049+
#[test]
1050+
fn keeps_explicit_model_name_when_merging_unnamed_step_copy() {
1051+
let fixture = Fixture::new();
1052+
let usage = UsageFixture {
1053+
model_id: Some(1401),
1054+
input_tokens: 60,
1055+
total_output_tokens: 10,
1056+
visible_output_tokens: 10,
1057+
response_id: Some("shared-response"),
1058+
..UsageFixture::default()
1059+
};
1060+
create_database(
1061+
&fixture.path("conversations/session.db"),
1062+
&[(
1063+
0,
1064+
metadata_blob(
1065+
Some("claude-opus-5-5-medium"),
1066+
Some(usage),
1067+
Some((1_781_481_600, 0)),
1068+
&[],
1069+
),
1070+
)],
1071+
&[(
1072+
0,
1073+
step_metadata_blob(None, Some(usage), Some((1_781_481_600, 0)), &[], Some(1)),
1074+
)],
1075+
&[],
1076+
);
1077+
1078+
let entries = load_from_fixture(&fixture, true);
1079+
1080+
assert_eq!(entries.len(), 1);
1081+
assert_eq!(entries[0].model.as_deref(), Some("claude-opus-5-5-medium"));
1082+
}
1083+
10161084
#[test]
10171085
fn skips_zero_byte_databases_and_reports_valid_entries() {
10181086
let fixture = Fixture::new();

‎rust/adapters/antigravity/src/parser.rs‎

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -492,18 +492,19 @@ fn append_usage_event(
492492
let reasoning_tokens = usage
493493
.reasoning_tokens
494494
.max(total_output_tokens.saturating_sub(output_tokens));
495-
let same_model_row = context.model.filter(|_| context.model_id == usage.model_id);
496-
let model = usage
495+
let id_model = usage
497496
.model_id
498-
.and_then(known_model_name)
499-
.and_then(normalize_antigravity_model)
500-
.or_else(|| same_model_row.and_then(normalize_antigravity_model))
501-
.or_else(|| {
502-
usage
503-
.model_id
504-
.map(model_name_from_id)
505-
.and_then(|model| normalize_antigravity_model(&model))
506-
})
497+
.map(model_name_from_id)
498+
.and_then(|model| normalize_antigravity_model(&model));
499+
let same_model_row = context
500+
.model
501+
.filter(|_| context.model_id == usage.model_id)
502+
.and_then(normalize_antigravity_model);
503+
let model = id_model
504+
.clone()
505+
.filter(|model| !is_unresolved_model(model))
506+
.or_else(|| same_model_row.filter(|model| !is_unresolved_model(model)))
507+
.or(id_model)
507508
.or_else(|| context.model.and_then(normalize_antigravity_model))
508509
.unwrap_or_else(|| DEFAULT_MODEL.to_string());
509510
let provider = usage.provider.or(context.provider);
@@ -565,7 +566,7 @@ pub(super) fn merge_usage_event(
565566
.saturating_add(target.cache_creation_tokens)
566567
.saturating_add(target.cache_read_tokens)
567568
.saturating_add(target.total_output_tokens);
568-
if target.model == DEFAULT_MODEL && duplicate.model != DEFAULT_MODEL {
569+
if is_unresolved_model(&target.model) && !is_unresolved_model(&duplicate.model) {
569570
target.model = duplicate.model.clone();
570571
}
571572
if target.provider.is_none() {
@@ -879,40 +880,42 @@ fn field_text(fields: &[ProtoField<'_>], number: u32) -> Option<String> {
879880
}
880881

881882
fn model_name_from_id(model_id: u64) -> String {
882-
known_model_name(model_id).map_or_else(
883-
|| match model_id {
884-
1_000.. => format!("model_placeholder_m{}", model_id - 1_000),
885-
_ => format!("antigravity-model-{model_id}"),
886-
},
887-
ToString::to_string,
888-
)
883+
match model_id {
884+
246 => "gemini-2.5-pro".to_string(),
885+
312 => "gemini-2.5-flash".to_string(),
886+
313 | 329 => "gemini-2.5-flash-thinking".to_string(),
887+
330 => "gemini-2.5-flash-lite".to_string(),
888+
281 | 282 => "claude-4-sonnet".to_string(),
889+
290 | 291 => "claude-4-opus".to_string(),
890+
333 | 334 => "claude-4.5-sonnet".to_string(),
891+
340 | 341 => "claude-4.5-haiku".to_string(),
892+
342 => "model_openai_gpt_oss_120b_medium".to_string(),
893+
1318 => "gemini-3.8-flash-high".to_string(),
894+
1319 => "gemini-3.8-flash-medium".to_string(),
895+
1320 => "gemini-3.8-flash-low".to_string(),
896+
1298 => "gemini-3.7-flash-high".to_string(),
897+
1299 => "gemini-3.7-flash-medium".to_string(),
898+
1300 => "gemini-3.7-flash-low".to_string(),
899+
1071 => "gemini-3.6-flash-high".to_string(),
900+
1072 => "gemini-3.6-flash-medium".to_string(),
901+
1073 => "gemini-3.6-flash-low".to_string(),
902+
1417..=1419 => "gemini-4-argon".to_string(),
903+
1402 => "claude-opus-5-5".to_string(),
904+
1050 => "gemini-3.1-flash-lite".to_string(),
905+
1_000.. => format!("{UNRESOLVED_PLACEHOLDER_PREFIX}{}", model_id - 1_000),
906+
_ => format!("{UNRESOLVED_ID_PREFIX}{model_id}"),
907+
}
889908
}
890909

891-
fn known_model_name(model_id: u64) -> Option<&'static str> {
892-
Some(match model_id {
893-
246 => "gemini-2.5-pro",
894-
312 => "gemini-2.5-flash",
895-
313 | 329 => "gemini-2.5-flash-thinking",
896-
330 => "gemini-2.5-flash-lite",
897-
281 | 282 => "claude-4-sonnet",
898-
290 | 291 => "claude-4-opus",
899-
333 | 334 => "claude-4.5-sonnet",
900-
340 | 341 => "claude-4.5-haiku",
901-
342 => "model_openai_gpt_oss_120b_medium",
902-
1318 => "gemini-3.8-flash-high",
903-
1319 => "gemini-3.8-flash-medium",
904-
1320 => "gemini-3.8-flash-low",
905-
1298 => "gemini-3.7-flash-high",
906-
1299 => "gemini-3.7-flash-medium",
907-
1300 => "gemini-3.7-flash-low",
908-
1071 => "gemini-3.6-flash-high",
909-
1072 => "gemini-3.6-flash-medium",
910-
1073 => "gemini-3.6-flash-low",
911-
1417..=1419 => "gemini-4-argon",
912-
1402 => "claude-opus-5-5",
913-
1050 => "gemini-3.1-flash-lite",
914-
_ => return None,
915-
})
910+
const UNRESOLVED_PLACEHOLDER_PREFIX: &str = "model_placeholder_m";
911+
const UNRESOLVED_ID_PREFIX: &str = "antigravity-model-";
912+
913+
// A placeholder that normalization did not map to a real model, so a model
914+
// name from another field or a duplicate copy should replace it.
915+
fn is_unresolved_model(model: &str) -> bool {
916+
model == DEFAULT_MODEL
917+
|| model.starts_with(UNRESOLVED_PLACEHOLDER_PREFIX)
918+
|| model.starts_with(UNRESOLVED_ID_PREFIX)
916919
}
917920

918921
fn normalize_antigravity_model(raw: &str) -> Option<String> {

0 commit comments

Comments
 (0)