mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Remove the unused legacy remote compaction implementation (#44273)
## Why Remote compaction already uses the normal Responses API, leaving the legacy `/responses/compact` runner unused. ## What changed - Remove the legacy runner, endpoint client, request types, analytics variant, and obsolete test helpers and snapshots. - Move tool-output trimming and its metadata tests into `compact_remote_history` for reuse by remote compaction v2. - Consolidate retained-history filtering in the v2 implementation and remove redundant `RemoteCompactionV2` settings from tests. ## Testing Extend the retained-history unit test to explicitly check that hook prompts survive compaction. GitOrigin-RevId: 999bb1391aa22c3c281d6a96f98817d6c9e46ed9
This commit is contained in:
1 parent
a3ba42b010
commit
1ac689cc7d
44 files changed
+169
-1964
No files matched your search
@@ -34,8 +34,6 @@ use async_channel::Sender;
|
||||
use codex_api::AgentIdentityTelemetry;
|
||||
use codex_api::ApiError;
|
||||
use codex_api::AuthProvider;
|
||||
use codex_api::CompactClient as ApiCompactClient;
|
||||
use codex_api::CompactionInput as ApiCompactionInput;
|
||||
use codex_api::Compression;
|
||||
use codex_api::MemoriesClient as ApiMemoriesClient;
|
||||
use codex_api::MemorySummarizeInput as ApiMemorySummarizeInput;
|
||||
@@ -90,7 +88,6 @@ use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::InternalSessionSource;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::W3cTraceContext;
|
||||
use codex_rollout_trace::CompactionTraceContext;
|
||||
use codex_rollout_trace::InferenceTraceAttempt;
|
||||
use codex_rollout_trace::InferenceTraceContext;
|
||||
use codex_tools::create_tools_json_for_responses_api;
|
||||
@@ -168,21 +165,11 @@ const RESPONSES_WEBSOCKETS_V2_BETA_HEADER_VALUE: &str = "responses_websockets=20
|
||||
const X_OPENAI_INTERNAL_CODEX_RESPONSES_LITE_HEADER: &str =
|
||||
"x-openai-internal-codex-responses-lite";
|
||||
const REALTIME_CALLS_ENDPOINT: &str = "/realtime/calls";
|
||||
const RESPONSES_COMPACT_ENDPOINT: &str = "/responses/compact";
|
||||
// `/responses/compact` is unary, so the timeout covers the full response rather than one idle
|
||||
// period between stream events.
|
||||
const COMPACT_REQUEST_TIMEOUT_IDLE_MULTIPLIER: u32 = 4;
|
||||
const MEMORIES_SUMMARIZE_ENDPOINT: &str = "/memories/trace_summarize";
|
||||
#[cfg(test)]
|
||||
pub(crate) const WEBSOCKET_CONNECT_TIMEOUT: Duration =
|
||||
Duration::from_millis(DEFAULT_WEBSOCKET_CONNECT_TIMEOUT_MS);
|
||||
|
||||
pub(crate) struct CompactConversationRequestSettings {
|
||||
pub(crate) effort: Option<ReasoningEffortConfig>,
|
||||
pub(crate) summary: ReasoningSummaryConfig,
|
||||
pub(crate) service_tier: Option<String>,
|
||||
}
|
||||
|
||||
fn session_telemetry_for_request(
|
||||
session_telemetry: &SessionTelemetry,
|
||||
request: &ResponsesApiRequest,
|
||||
@@ -569,124 +556,6 @@ impl ModelClient {
|
||||
activated
|
||||
}
|
||||
|
||||
/// Compacts the current conversation history using the Compact endpoint.
|
||||
///
|
||||
/// This is a unary call (no streaming) that returns a new list of
|
||||
/// `ResponseItem`s representing the compacted transcript.
|
||||
///
|
||||
/// The model selection and telemetry context are passed explicitly to keep `ModelClient`
|
||||
/// session-scoped.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) async fn compact_conversation_history(
|
||||
&self,
|
||||
prompt: &Prompt,
|
||||
model_info: &ModelInfo,
|
||||
turn_state: Option<Arc<OnceLock<String>>>,
|
||||
settings: CompactConversationRequestSettings,
|
||||
session_telemetry: &SessionTelemetry,
|
||||
compaction_trace: &CompactionTraceContext,
|
||||
responses_metadata: &CodexResponsesMetadata,
|
||||
) -> Result<Vec<ResponseItem>> {
|
||||
if prompt.input.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let client_setup = self.current_client_setup().await?;
|
||||
let transport =
|
||||
self.build_api_transport(&client_setup.api_provider, RESPONSES_COMPACT_ENDPOINT)?;
|
||||
let request_telemetry = Self::build_request_telemetry(
|
||||
session_telemetry,
|
||||
AuthRequestTelemetryContext::new(
|
||||
client_setup.auth.as_ref().map(CodexAuth::auth_mode),
|
||||
client_setup.api_auth.as_ref(),
|
||||
client_setup.agent_identity_telemetry.clone(),
|
||||
PendingUnauthorizedRetry::default(),
|
||||
),
|
||||
RequestRouteTelemetry::for_endpoint(RESPONSES_COMPACT_ENDPOINT),
|
||||
self.state.auth_env_telemetry.clone(),
|
||||
);
|
||||
let request = self.build_responses_request(
|
||||
prompt,
|
||||
model_info,
|
||||
settings.effort,
|
||||
settings.summary,
|
||||
settings.service_tier,
|
||||
responses_metadata,
|
||||
)?;
|
||||
let ResponsesApiRequest {
|
||||
model,
|
||||
instructions,
|
||||
mut input,
|
||||
tools,
|
||||
parallel_tool_calls,
|
||||
reasoning,
|
||||
service_tier,
|
||||
prompt_cache_key,
|
||||
text,
|
||||
..
|
||||
} = request;
|
||||
self.prepare_response_items_for_request(&mut input);
|
||||
let payload = ApiCompactionInput {
|
||||
model: &model,
|
||||
input: &input,
|
||||
instructions: &instructions,
|
||||
tools,
|
||||
parallel_tool_calls,
|
||||
reasoning,
|
||||
service_tier: service_tier.as_deref(),
|
||||
prompt_cache_key: prompt_cache_key.as_deref(),
|
||||
text,
|
||||
access_programs: cyber_access_program::for_auth(
|
||||
client_setup.auth.as_ref(),
|
||||
prompt.cyber_access_program,
|
||||
),
|
||||
};
|
||||
|
||||
let mut extra_headers = ApiHeaderMap::new();
|
||||
if let Ok(header_value) = HeaderValue::from_str(&responses_metadata.installation_id) {
|
||||
extra_headers.insert(X_CODEX_INSTALLATION_ID_HEADER, header_value);
|
||||
}
|
||||
extra_headers.extend(build_responses_headers(
|
||||
self.state.beta_features_header.as_deref(),
|
||||
turn_state.as_ref(),
|
||||
));
|
||||
add_originator_header(&mut extra_headers, self.state.originator.as_str());
|
||||
extra_headers.extend(self.build_responses_compatibility_headers(responses_metadata));
|
||||
extra_headers.extend(build_session_headers(
|
||||
Some(responses_metadata.session_id.to_string()),
|
||||
Some(responses_metadata.thread_id.to_string()),
|
||||
));
|
||||
if let Some(header_value) = self.generate_attestation_header_for().await {
|
||||
extra_headers.insert(X_OAI_ATTESTATION_HEADER, header_value);
|
||||
}
|
||||
if let Some(header_value) = self.build_routing_hint_header(
|
||||
client_setup.auth.as_ref(),
|
||||
&model,
|
||||
service_tier.as_deref(),
|
||||
) {
|
||||
extra_headers.insert(X_CODEX_ROUTING_HINT_HEADER, header_value);
|
||||
}
|
||||
add_responses_lite_header(&mut extra_headers, model_info.use_responses_lite);
|
||||
let compact_request_timeout = client_setup
|
||||
.api_provider
|
||||
.stream_idle_timeout
|
||||
.saturating_mul(COMPACT_REQUEST_TIMEOUT_IDLE_MULTIPLIER);
|
||||
let client =
|
||||
ApiCompactClient::new(transport, client_setup.api_provider, client_setup.api_auth)
|
||||
.with_telemetry(Some(request_telemetry));
|
||||
let trace_attempt = compaction_trace.start_attempt(&payload);
|
||||
let result = client
|
||||
.compact_input(
|
||||
&payload,
|
||||
extra_headers,
|
||||
compact_request_timeout,
|
||||
turn_state.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| self.state.provider.map_api_error(error));
|
||||
trace_attempt.record_result(result.as_deref());
|
||||
result
|
||||
}
|
||||
|
||||
pub(crate) async fn create_realtime_call_with_headers(
|
||||
&self,
|
||||
sdp: String,
|
||||
@@ -1278,11 +1147,6 @@ impl Drop for ModelClientSession {
|
||||
}
|
||||
|
||||
impl ModelClientSession {
|
||||
#[expect(dead_code, reason = "the v1-only accessor is removed in the follow-up")]
|
||||
pub(crate) fn turn_state(&self) -> Arc<OnceLock<String>> {
|
||||
Arc::clone(&self.turn_state)
|
||||
}
|
||||
|
||||
fn reset_websocket_session(&mut self) {
|
||||
self.websocket_session.connection = None;
|
||||
self.websocket_session.endpoint = None;
|
||||
|
||||
Reference in new issue
Block a user