mirror of
https://github.com/openai/codex.git
synced 2026-11-13 06:45:07 +00:00
Support remote compaction for Azure responses providers (#17958)
Azure Responses providers were still falling back to local compaction because the compaction gate only checked `ModelProviderInfo::is_openai()`. Move the capability check onto `ModelProviderInfo` with `supports_remote_compaction()`, backed by the existing Azure Responses endpoint detection used in `codex-api`, and have `core::compact` delegate to that helper. Add regression coverage for: - OpenAI providers using remote compaction - Azure providers using remote compaction - non-OpenAI/non-Azure providers staying on the local path resolves #17773 --------- Co-authored-by: Michael Bolin <mbolin@openai.com>
This commit is contained in:
1 parent
6696e0bbc3
commit
f2a4925f63
4 files changed
+87
-1
No files matched your search
@@ -58,7 +58,7 @@ pub(crate) enum InitialContextInjection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn should_use_remote_compact_task(provider: &ModelProviderInfo) -> bool {
|
pub(crate) fn should_use_remote_compact_task(provider: &ModelProviderInfo) -> bool {
|
||||||
provider.is_openai()
|
provider.supports_remote_compaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn run_inline_auto_compact_task(
|
pub(crate) async fn run_inline_auto_compact_task(
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
use codex_model_provider_info::ModelProviderInfo;
|
||||||
|
use codex_model_provider_info::WireApi;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
async fn process_compacted_history_with_test_session(
|
async fn process_compacted_history_with_test_session(
|
||||||
@@ -185,6 +187,30 @@ fn build_token_limited_compacted_history_appends_summary_message() {
|
|||||||
assert_eq!(summary, summary_text);
|
assert_eq!(summary, summary_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_use_remote_compact_task_for_azure_provider() {
|
||||||
|
let provider = ModelProviderInfo {
|
||||||
|
name: "Azure".into(),
|
||||||
|
base_url: Some("https://example.com/openai".into()),
|
||||||
|
env_key: Some("AZURE_OPENAI_API_KEY".into()),
|
||||||
|
env_key_instructions: None,
|
||||||
|
experimental_bearer_token: None,
|
||||||
|
auth: None,
|
||||||
|
wire_api: WireApi::Responses,
|
||||||
|
query_params: None,
|
||||||
|
http_headers: None,
|
||||||
|
env_http_headers: None,
|
||||||
|
request_max_retries: None,
|
||||||
|
stream_max_retries: None,
|
||||||
|
stream_idle_timeout_ms: None,
|
||||||
|
websocket_connect_timeout_ms: None,
|
||||||
|
requires_openai_auth: false,
|
||||||
|
supports_websockets: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(should_use_remote_compact_task(&provider));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn process_compacted_history_replaces_developer_messages() {
|
async fn process_compacted_history_replaces_developer_messages() {
|
||||||
let compacted_history = vec![
|
let compacted_history = vec![
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
use codex_api::Provider as ApiProvider;
|
use codex_api::Provider as ApiProvider;
|
||||||
use codex_api::RetryConfig as ApiRetryConfig;
|
use codex_api::RetryConfig as ApiRetryConfig;
|
||||||
|
use codex_api::is_azure_responses_provider;
|
||||||
use codex_app_server_protocol::AuthMode;
|
use codex_app_server_protocol::AuthMode;
|
||||||
use codex_protocol::config_types::ModelProviderAuthInfo;
|
use codex_protocol::config_types::ModelProviderAuthInfo;
|
||||||
use codex_protocol::error::CodexErr;
|
use codex_protocol::error::CodexErr;
|
||||||
@@ -300,6 +301,10 @@ impl ModelProviderInfo {
|
|||||||
self.name == OPENAI_PROVIDER_NAME
|
self.name == OPENAI_PROVIDER_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn supports_remote_compaction(&self) -> bool {
|
||||||
|
self.is_openai() || is_azure_responses_provider(&self.name, self.base_url.as_deref())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn has_command_auth(&self) -> bool {
|
pub fn has_command_auth(&self) -> bool {
|
||||||
self.auth.is_some()
|
self.auth.is_some()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,61 @@ supports_websockets = true
|
|||||||
assert_eq!(provider.websocket_connect_timeout_ms, Some(15_000));
|
assert_eq!(provider.websocket_connect_timeout_ms, Some(15_000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_supports_remote_compaction_for_openai() {
|
||||||
|
let provider = ModelProviderInfo::create_openai_provider(/*base_url*/ None);
|
||||||
|
|
||||||
|
assert!(provider.supports_remote_compaction());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_supports_remote_compaction_for_azure_name() {
|
||||||
|
let provider = ModelProviderInfo {
|
||||||
|
name: "Azure".into(),
|
||||||
|
base_url: Some("https://example.com/openai".into()),
|
||||||
|
env_key: Some("AZURE_OPENAI_API_KEY".into()),
|
||||||
|
env_key_instructions: None,
|
||||||
|
experimental_bearer_token: None,
|
||||||
|
auth: None,
|
||||||
|
wire_api: WireApi::Responses,
|
||||||
|
query_params: None,
|
||||||
|
http_headers: None,
|
||||||
|
env_http_headers: None,
|
||||||
|
request_max_retries: None,
|
||||||
|
stream_max_retries: None,
|
||||||
|
stream_idle_timeout_ms: None,
|
||||||
|
websocket_connect_timeout_ms: None,
|
||||||
|
requires_openai_auth: false,
|
||||||
|
supports_websockets: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(provider.supports_remote_compaction());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_supports_remote_compaction_for_non_openai_non_azure_provider() {
|
||||||
|
let provider = ModelProviderInfo {
|
||||||
|
name: "Example".into(),
|
||||||
|
base_url: Some("https://example.com/v1".into()),
|
||||||
|
env_key: Some("API_KEY".into()),
|
||||||
|
env_key_instructions: None,
|
||||||
|
experimental_bearer_token: None,
|
||||||
|
auth: None,
|
||||||
|
wire_api: WireApi::Responses,
|
||||||
|
query_params: None,
|
||||||
|
http_headers: None,
|
||||||
|
env_http_headers: None,
|
||||||
|
request_max_retries: None,
|
||||||
|
stream_max_retries: None,
|
||||||
|
stream_idle_timeout_ms: None,
|
||||||
|
websocket_connect_timeout_ms: None,
|
||||||
|
requires_openai_auth: false,
|
||||||
|
supports_websockets: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(!provider.supports_remote_compaction());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_provider_auth_config_defaults() {
|
fn test_deserialize_provider_auth_config_defaults() {
|
||||||
let base_dir = tempdir().unwrap();
|
let base_dir = tempdir().unwrap();
|
||||||
|
|||||||
Reference in new issue
Block a user