mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
d927f61208
## Why This adds the `remote_compaction_v2` client path so remote compaction can run through the normal Responses stream and install a `context_compaction` item that trigger a compaction. The goal is to migrate some of the compaction logic on the client side We keeps the v2 transport behind a feature flag while letting follow-up requests reuse the compacted context instead of falling back to the legacy compaction item shape. ## What changed - add `ResponseItem::ContextCompaction` and refresh the generated app-server / schema / TypeScript fixtures that expose response items on the wire - add `core/src/compact_remote_v2.rs` to send compaction through the standard streamed Responses client, require exactly one `context_compaction` output item, and install that item into compacted history - route manual compact and auto-compaction through the v2 path when `remote_compaction_v2` is enabled, while keeping the existing remote compaction path as the fallback - preserve the new item type across history retention, follow-up request construction, telemetry, rollout persistence, and rollout-trace normalization - add targeted coverage for the feature flag, `context_compaction` serialization, rollout-trace normalization, and remote-compaction follow-up behavior ## Verification - added protocol tests for `context_compaction` serialization/deserialization in `protocol/src/models.rs` - added rollout-trace coverage for `context_compaction` normalization in `rollout-trace/src/reducer/conversation_tests.rs` - added remote compaction integration coverage for v2 follow-up reuse and mixed compaction output streams in `core/tests/suite/compact_remote.rs` --------- Co-authored-by: Codex <noreply@openai.com>
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use std::sync::Arc;
|
|
|
|
use super::SessionTask;
|
|
use super::SessionTaskContext;
|
|
use crate::session::turn_context::TurnContext;
|
|
use crate::state::TaskKind;
|
|
use codex_protocol::user_input::UserInput;
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
#[derive(Clone, Copy, Default)]
|
|
pub(crate) struct CompactTask;
|
|
|
|
impl SessionTask for CompactTask {
|
|
fn kind(&self) -> TaskKind {
|
|
TaskKind::Compact
|
|
}
|
|
|
|
fn span_name(&self) -> &'static str {
|
|
"session_task.compact"
|
|
}
|
|
|
|
async fn run(
|
|
self: Arc<Self>,
|
|
session: Arc<SessionTaskContext>,
|
|
ctx: Arc<TurnContext>,
|
|
input: Vec<UserInput>,
|
|
_cancellation_token: CancellationToken,
|
|
) -> Option<String> {
|
|
let session = session.clone_session();
|
|
let _ = if crate::compact::should_use_remote_compact_task(ctx.provider.info()) {
|
|
session.services.session_telemetry.counter(
|
|
"codex.task.compact",
|
|
/*inc*/ 1,
|
|
&[("type", "remote")],
|
|
);
|
|
if ctx
|
|
.features
|
|
.enabled(codex_features::Feature::RemoteCompactionV2)
|
|
{
|
|
crate::compact_remote_v2::run_remote_compact_task(session.clone(), ctx).await
|
|
} else {
|
|
crate::compact_remote::run_remote_compact_task(session.clone(), ctx).await
|
|
}
|
|
} else {
|
|
session.services.session_telemetry.counter(
|
|
"codex.task.compact",
|
|
/*inc*/ 1,
|
|
&[("type", "local")],
|
|
);
|
|
crate::compact::run_compact_task(session.clone(), ctx, input).await
|
|
};
|
|
None
|
|
}
|
|
}
|