Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/tokscale-core/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) use error::{
SourceDiscoveryError, SourceParseError, SourcePipelineError, SourcePlanningError,
};

pub(crate) const MODEL_ID_CANONICALIZATION_REVISION: ParserRevision = 2;
pub(crate) const MODEL_ID_CANONICALIZATION_REVISION: ParserRevision = 3;
pub(crate) const OPENCODE_CURRENT_SQLITE_REVISION: ParserRevision =
MODEL_ID_CANONICALIZATION_REVISION + 1;
pub(crate) const EXPLICIT_TOKEN_OVERFLOW_REVISION: ParserRevision =
Expand Down
51 changes: 51 additions & 0 deletions crates/tokscale-core/src/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,23 @@ fn test_normalize_model_for_grouping() {
);
}

#[test]
fn test_normalize_model_for_grouping_canonicalizes_gpt_5_6_family_efforts() {
let cases = [
("custom:gpt-5.6-sol-high", "gpt-5.6-sol"),
("custom:gpt-5.6-sol-xhigh", "gpt-5.6-sol"),
("custom:gpt-5.6-sol-max", "gpt-5.6-sol"),
("custom:gpt-5.6-terra-xhigh", "gpt-5.6-terra"),
("custom:gpt-5.6-terra-max", "gpt-5.6-terra"),
("custom:gpt-5.6-luna-medium", "gpt-5.6-luna"),
("custom:gpt-5.6-luna-max", "gpt-5.6-luna"),
];

for (raw, expected) in cases {
assert_eq!(normalize_model_for_grouping(raw), expected);
}
}

#[test]
fn test_group_by_from_str_valid_values() {
assert_eq!(GroupBy::from_str("model").unwrap(), GroupBy::Model);
Expand Down Expand Up @@ -3966,6 +3983,40 @@ fn test_apply_token_pricing_clears_existing_cost_without_pricing() {
assert_eq!(msg.cost, 0.0);
}

#[test]
fn test_finalize_token_priced_messages_prices_canonical_gpt_5_6_factory_model() {
let mut litellm = HashMap::new();
litellm.insert(
"gpt-5.6-sol".into(),
pricing::ModelPricing {
input_cost_per_token: Some(0.001),
output_cost_per_token: Some(0.002),
..Default::default()
},
);
let pricing = pricing::PricingService::new(litellm, HashMap::new());
let mut messages = vec![UnifiedMessage::new(
"droid",
"gpt-5.6-sol-xhigh",
"openai",
"factory-session",
1_783_753_083_820,
TokenBreakdown {
input: 10,
output: 5,
cache_read: 0,
cache_write: 0,
reasoning: 2,
},
0.0,
)];

finalize_token_priced_messages(&mut messages, Some(&pricing));

assert_eq!(messages[0].model_id.as_ref(), "gpt-5.6-sol");
assert_eq!(messages[0].cost, 0.024);
}

#[test]
fn test_finalize_token_priced_messages_drops_rows_without_positive_tokens() {
let mut litellm = HashMap::new();
Expand Down
14 changes: 12 additions & 2 deletions crates/tokscale-core/src/model_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) const DEEPSEEK_V4_PRO_BETA_ALIAS: &str = "model1";
pub(crate) const DEEPSEEK_V4_FLASH_BETA_ALIAS: &str = "model2";

const CLAUDE_FAMILIES: &[&str] = &["opus", "sonnet", "haiku", "fable"];
const OPENAI_GPT_5_6_FAMILY: &[&str] = &["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"];
const OPENAI_REASONING_TIERS: &[&str] =
&["minimal", "low", "medium", "high", "xhigh", "auto", "none"];

Expand Down Expand Up @@ -247,7 +248,7 @@ fn canonicalize_openai_source_model(model: &str) -> Option<String> {
} else {
base
};
if (tier == "fast" || OPENAI_REASONING_TIERS.contains(&tier))
if (tier == "fast" || is_openai_reasoning_effort_for_model(base, tier))
&& is_openai_gpt_source_base_model(base)
{
return Some(base.to_string());
Expand All @@ -262,18 +263,27 @@ fn strip_parenthesized_openai_reasoning_tier(model: &str) -> Option<&str> {
let tier = tier.strip_suffix(')')?;
let base =
base.trim_end_matches(|ch: char| ch.is_ascii_whitespace() || matches!(ch, '-' | '_'));
if OPENAI_REASONING_TIERS.contains(&tier) && is_openai_gpt_source_base_model(base) {
if is_openai_reasoning_effort_for_model(base, tier) && is_openai_gpt_source_base_model(base) {
Some(base)
} else {
None
}
}

fn is_openai_reasoning_effort_for_model(model: &str, effort: &str) -> bool {
OPENAI_REASONING_TIERS.contains(&effort)
|| (effort == "max" && OPENAI_GPT_5_6_FAMILY.contains(&model))
}

fn is_openai_gpt_4o_source_base_model(model: &str) -> bool {
matches!(model, "gpt-4o" | "gpt-4o-mini")
}

fn is_openai_gpt_source_base_model(model: &str) -> bool {
if OPENAI_GPT_5_6_FAMILY.contains(&model) {
return true;
}

let rest = match model.strip_prefix("gpt-") {
Some(rest) => rest,
None => return false,
Expand Down
28 changes: 28 additions & 0 deletions crates/tokscale-core/src/sessions/droid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,34 @@ mod tests {
assert_eq!(messages[0].provider_id.as_ref(), "openai");
}

#[test]
fn test_parse_droid_file_canonicalizes_gpt_5_6_family_reasoning_effort() {
let temp_dir = tempfile::tempdir().unwrap();
let path = temp_dir.path().join("session.settings.json");
std::fs::write(
&path,
r#"{
"model": "custom:gpt-5.6-sol-xhigh",
"reasoningEffort": "xhigh",
"providerLock": "openai",
"providerLockTimestamp": "2026-07-11T13:38:03.820Z",
"tokenUsage": {
"inputTokens": 10,
"outputTokens": 5,
"thinkingTokens": 2
}
}"#,
)
.unwrap();

let messages = parse_droid_file(&path);

assert_eq!(messages.len(), 1);
assert_eq!(messages[0].model_id.as_ref(), "gpt-5.6-sol");
assert_eq!(messages[0].provider_id.as_ref(), "openai");
assert_eq!(messages[0].tokens.reasoning, 2);
}

#[test]
fn test_parse_droid_file_canonicalizes_space_before_parenthesized_tier() {
let temp_dir = tempfile::tempdir().unwrap();
Expand Down
Loading