Skip to content

Commit 97c42c7

Browse files
committed
fix(antigravity): report explicit model names for unknown model IDs
Fixes #2070. Unknown numeric model IDs (1000+) became `model_placeholder_m<N>` and that placeholder took precedence over the explicit model name stored in the same record, so new models showed up with zero cost until their ID was added to the hard-coded table (#1893, #1897, #1904, #1947 all followed this path). Resolve the event model as: known ID mapping, then the row's explicit name when the row's chat model ID matches the usage model ID, then the placeholder. The ID check keeps retry usages that switched to a different model from inheriting the row's name.
1 parent d06f55b commit 97c42c7

2 files changed

Lines changed: 108 additions & 27 deletions

File tree

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,65 @@ mod tests {
954954
insta::assert_json_snapshot!(reports);
955955
}
956956

957+
#[test]
958+
fn prefers_explicit_model_name_over_placeholder_for_unknown_ids() {
959+
let fixture = Fixture::new();
960+
let cases = [
961+
(1401, "claude-opus-5-5-medium", "unknown-opus"),
962+
(1404, "claude-sonnet-5-5-medium", "unknown-sonnet"),
963+
(1427, "gemini-4-carbon", "unknown-carbon-high"),
964+
(1437, "gemini-4-carbon", "unknown-carbon-medium"),
965+
];
966+
let rows = cases
967+
.iter()
968+
.enumerate()
969+
.map(|(idx, (model_id, model, response_id))| {
970+
(
971+
i64::try_from(idx).unwrap(),
972+
metadata_blob(
973+
Some(model),
974+
Some(UsageFixture {
975+
model_id: Some(*model_id),
976+
input_tokens: 60,
977+
total_output_tokens: 10,
978+
cache_read_tokens: 40,
979+
visible_output_tokens: 10,
980+
response_id: Some(response_id),
981+
..UsageFixture::default()
982+
}),
983+
Some((1_781_481_600 + u64::try_from(idx).unwrap(), 0)),
984+
&[UsageFixture {
985+
model_id: Some(1499),
986+
input_tokens: 5,
987+
total_output_tokens: 1,
988+
visible_output_tokens: 1,
989+
response_id: Some("unknown-retry"),
990+
..UsageFixture::default()
991+
}],
992+
),
993+
)
994+
})
995+
.collect::<Vec<_>>();
996+
create_database(&fixture.path("conversations/session.db"), &rows, &[], &[]);
997+
998+
let entries = load_from_fixture(&fixture, true);
999+
1000+
for (_, model, response_id) in cases {
1001+
let entry = entries
1002+
.iter()
1003+
.find(|entry| entry.data.message.id.as_deref() == Some(response_id))
1004+
.unwrap();
1005+
assert_eq!(entry.model.as_deref(), Some(model));
1006+
assert!(entry.cost > 0.0);
1007+
assert!(entry.missing_pricing_model.is_none());
1008+
}
1009+
let retry = entries
1010+
.iter()
1011+
.find(|entry| entry.data.message.id.as_deref() == Some("unknown-retry"))
1012+
.unwrap();
1013+
assert_eq!(retry.model.as_deref(), Some("model_placeholder_m499"));
1014+
}
1015+
9571016
#[test]
9581017
fn skips_zero_byte_databases_and_reports_valid_entries() {
9591018
let fixture = Fixture::new();

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

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub(super) fn parse_sqlite_file(path: &Path) -> Result<Option<Vec<AntigravityUsa
218218
usage,
219219
EventContext {
220220
model: model.as_deref(),
221+
model_id: metadata.model_id,
221222
provider: metadata.provider,
222223
timestamp,
223224
trajectory_timestamp,
@@ -234,6 +235,7 @@ pub(super) fn parse_sqlite_file(path: &Path) -> Result<Option<Vec<AntigravityUsa
234235
usage,
235236
EventContext {
236237
model: model.as_deref(),
238+
model_id: metadata.model_id,
237239
provider: metadata.provider,
238240
timestamp,
239241
trajectory_timestamp,
@@ -285,6 +287,7 @@ pub(super) fn parse_sqlite_file(path: &Path) -> Result<Option<Vec<AntigravityUsa
285287
usage,
286288
EventContext {
287289
model: model.as_deref(),
290+
model_id: metadata.model_id,
288291
provider: None,
289292
timestamp: metadata.timestamp.map(|timestamp| (timestamp, 3)),
290293
trajectory_timestamp,
@@ -301,6 +304,7 @@ pub(super) fn parse_sqlite_file(path: &Path) -> Result<Option<Vec<AntigravityUsa
301304
usage,
302305
EventContext {
303306
model: model.as_deref(),
307+
model_id: metadata.model_id,
304308
provider: None,
305309
timestamp: metadata.timestamp.map(|timestamp| (timestamp, 3)),
306310
trajectory_timestamp,
@@ -446,6 +450,7 @@ fn table_exists(connection: &sqlite::Connection, table: &str) -> Result<bool> {
446450
#[derive(Clone, Copy)]
447451
struct EventContext<'a> {
448452
model: Option<&'a str>,
453+
model_id: Option<u64>,
449454
provider: Option<u64>,
450455
timestamp: Option<(TimestampMs, u8)>,
451456
trajectory_timestamp: Option<TimestampMs>,
@@ -487,10 +492,18 @@ fn append_usage_event(
487492
let reasoning_tokens = usage
488493
.reasoning_tokens
489494
.max(total_output_tokens.saturating_sub(output_tokens));
495+
let same_model_row = context.model.filter(|_| context.model_id == usage.model_id);
490496
let model = usage
491497
.model_id
492-
.map(model_name_from_id)
493-
.and_then(|model| normalize_antigravity_model(&model))
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+
})
494507
.or_else(|| context.model.and_then(normalize_antigravity_model))
495508
.unwrap_or_else(|| DEFAULT_MODEL.to_string());
496509
let provider = usage.provider.or(context.provider);
@@ -866,31 +879,40 @@ fn field_text(fields: &[ProtoField<'_>], number: u32) -> Option<String> {
866879
}
867880

868881
fn model_name_from_id(model_id: u64) -> String {
869-
match model_id {
870-
246 => "gemini-2.5-pro".to_string(),
871-
312 => "gemini-2.5-flash".to_string(),
872-
313 | 329 => "gemini-2.5-flash-thinking".to_string(),
873-
330 => "gemini-2.5-flash-lite".to_string(),
874-
281 | 282 => "claude-4-sonnet".to_string(),
875-
290 | 291 => "claude-4-opus".to_string(),
876-
333 | 334 => "claude-4.5-sonnet".to_string(),
877-
340 | 341 => "claude-4.5-haiku".to_string(),
878-
342 => "model_openai_gpt_oss_120b_medium".to_string(),
879-
1318 => "gemini-3.8-flash-high".to_string(),
880-
1319 => "gemini-3.8-flash-medium".to_string(),
881-
1320 => "gemini-3.8-flash-low".to_string(),
882-
1298 => "gemini-3.7-flash-high".to_string(),
883-
1299 => "gemini-3.7-flash-medium".to_string(),
884-
1300 => "gemini-3.7-flash-low".to_string(),
885-
1071 => "gemini-3.6-flash-high".to_string(),
886-
1072 => "gemini-3.6-flash-medium".to_string(),
887-
1073 => "gemini-3.6-flash-low".to_string(),
888-
1417..=1419 => "gemini-4-argon".to_string(),
889-
1402 => "claude-opus-5-5".to_string(),
890-
1050 => "gemini-3.1-flash-lite".to_string(),
891-
1_000.. => format!("model_placeholder_m{}", model_id - 1_000),
892-
_ => format!("antigravity-model-{model_id}"),
893-
}
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+
)
889+
}
890+
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+
})
894916
}
895917

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

0 commit comments

Comments
 (0)