diff --git a/crates/forge_app/src/orch_spec/orch_setup.rs b/crates/forge_app/src/orch_spec/orch_setup.rs index 0ad7399878..13639da91d 100644 --- a/crates/forge_app/src/orch_spec/orch_setup.rs +++ b/crates/forge_app/src/orch_spec/orch_setup.rs @@ -95,6 +95,7 @@ impl Default for TestContext { workspace_server_url: Url::parse("http://localhost:8080").unwrap(), max_extensions: 15, parallel_file_reads: 64, + model_cache_ttl: 604_800, }, title: Some("test-conversation".into()), agent: Agent::new( diff --git a/crates/forge_domain/src/env.rs b/crates/forge_domain/src/env.rs index c8c9ce51ec..903fd20c73 100644 --- a/crates/forge_domain/src/env.rs +++ b/crates/forge_domain/src/env.rs @@ -100,6 +100,9 @@ pub struct Environment { /// Controlled by FORGE_PARALLEL_FILE_READS environment variable. /// Caps the `buffer_unordered` concurrency to avoid EMFILE errors. pub parallel_file_reads: usize, + /// TTL in seconds for the model API list cache. + /// Controlled by FORGE_MODEL_CACHE_TTL environment variable. + pub model_cache_ttl: u64, } /// The output format used when auto-dumping a conversation on task completion. @@ -339,6 +342,7 @@ fn test_command_path() { max_extensions: 15, auto_dump: None, parallel_file_reads: 64, + model_cache_ttl: 604_800, }; let actual = fixture.command_path(); @@ -381,6 +385,7 @@ fn test_command_cwd_path() { max_extensions: 15, auto_dump: None, parallel_file_reads: 64, + model_cache_ttl: 604_800, }; let actual = fixture.command_cwd_path(); @@ -423,6 +428,7 @@ fn test_command_cwd_path_independent_from_command_path() { max_extensions: 15, auto_dump: None, parallel_file_reads: 64, + model_cache_ttl: 604_800, }; let command_path = fixture.command_path(); diff --git a/crates/forge_infra/src/env.rs b/crates/forge_infra/src/env.rs index b8d40a27db..6c32bd498a 100644 --- a/crates/forge_infra/src/env.rs +++ b/crates/forge_infra/src/env.rs @@ -104,6 +104,7 @@ impl ForgeEnvironmentInfra { .unwrap_or(32) }, ), + model_cache_ttl: parse_env::("FORGE_MODEL_CACHE_TTL").unwrap_or(604_800), /* 1 week */ } } diff --git a/crates/forge_repo/src/provider/chat.rs b/crates/forge_repo/src/provider/chat.rs index aa7021cc45..ce0a09b125 100644 --- a/crates/forge_repo/src/provider/chat.rs +++ b/crates/forge_repo/src/provider/chat.rs @@ -15,9 +15,6 @@ use crate::provider::google::GoogleResponseRepository; use crate::provider::openai::OpenAIResponseRepository; use crate::provider::openai_responses::OpenAIResponsesResponseRepository; -/// TTL for cached model lists: 2 hours in seconds. -const MODEL_CACHE_TTL_SECS: u128 = 7200; - /// Repository responsible for routing chat requests to the appropriate provider /// implementation based on the provider's response type. pub struct ForgeChatRepository { @@ -48,7 +45,7 @@ impl ForgeChatRepository { let model_cache = Arc::new(CacacheStorage::new( env.cache_dir().join("model_cache"), - Some(MODEL_CACHE_TTL_SECS), + Some(env.model_cache_ttl as u128), )); Self {