Force compact after CRRC checkpoint steering

This commit is contained in:
Meta Vens 2026-04-30 09:19:33 +01:00
commit 6fa0b7704c
8 changed files with 120 additions and 18 deletions

View file

@ -235,11 +235,12 @@ pub(crate) async fn apply_bespoke_event_handling(
EventMsg::TurnComplete(turn_complete_event) => {
// All per-thread requests are bound to a turn, so abort them.
outgoing.abort_pending_server_requests().await;
let (turn_failed, turn_was_context_compaction) = {
let state = thread_state.lock().await;
let (turn_failed, turn_was_context_compaction, force_checkpoint_compaction) = {
let mut state = thread_state.lock().await;
(
state.turn_summary.last_error.is_some(),
state.turn_summary.context_compaction_started,
state.take_epiphany_checkpoint_intervention_pending_compaction(&event_turn_id),
)
};
thread_watch_manager
@ -260,6 +261,7 @@ pub(crate) async fn apply_bespoke_event_handling(
conversation,
epiphany_invalidation_manager,
&outgoing,
force_checkpoint_compaction,
)
.await;
}
@ -1885,6 +1887,7 @@ pub(crate) async fn apply_bespoke_event_handling(
outgoing.abort_pending_server_requests().await;
let pending = {
let mut state = thread_state.lock().await;
state.clear_epiphany_checkpoint_intervention_pending_compaction();
std::mem::take(&mut state.pending_interrupts)
};
if !pending.is_empty() {

View file

@ -13975,6 +13975,16 @@ fn map_epiphany_coordinator_automation_action(
}
}
fn select_epiphany_coordinator_automation_action(
decision: &EpiphanyCoordinatorDecision,
force_checkpoint_compaction: bool,
) -> EpiphanyCoordinatorAutomationAction {
if force_checkpoint_compaction {
return EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient;
}
map_epiphany_coordinator_automation_action(decision)
}
fn map_epiphany_coordinator(
state_status: ThreadEpiphanyReorientStateStatus,
checkpoint_present: bool,
@ -16247,6 +16257,7 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
thread: Arc<CodexThread>,
epiphany_invalidation_manager: EpiphanyInvalidationManager,
outgoing: &ThreadScopedOutgoingMessageSender,
force_checkpoint_compaction: bool,
) {
let thread_id_text = thread_id.to_string();
let Some(state) = thread.epiphany_state().await else {
@ -16348,7 +16359,7 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
reorient_finding_accepted,
);
match map_epiphany_coordinator_automation_action(&coordinator) {
match select_epiphany_coordinator_automation_action(&coordinator, force_checkpoint_compaction) {
EpiphanyCoordinatorAutomationAction::None => {}
EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient => {
if let Err(err) = thread.submit(Op::Compact).await {
@ -16432,7 +16443,12 @@ pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_fo
)
.await
{
Ok(_) => {}
Ok(_) => {
thread_state
.lock()
.await
.mark_epiphany_checkpoint_intervention_pending_compaction(&turn_id);
}
Err(SteerInputError::NoActiveTurn(_))
| Err(SteerInputError::ExpectedTurnMismatch { .. })
| Err(SteerInputError::ActiveTurnNotSteerable { .. })
@ -19671,6 +19687,27 @@ mod tests {
);
}
#[test]
fn select_epiphany_coordinator_automation_forces_checkpoint_compaction_handoff() {
let decision = EpiphanyCoordinatorDecision {
action: ThreadEpiphanyCoordinatorAction::ContinueImplementation,
target_role: Some(ThreadEpiphanyRoleId::Implementation),
recommended_scene_action: None,
requires_review: false,
can_auto_run: false,
reason: "ordinary coordinator would continue".to_string(),
};
assert_eq!(
map_epiphany_coordinator_automation_action(&decision),
EpiphanyCoordinatorAutomationAction::None
);
assert_eq!(
select_epiphany_coordinator_automation_action(&decision, true),
EpiphanyCoordinatorAutomationAction::CompactRehydrateReorient
);
}
#[test]
fn map_epiphany_coordinator_launches_reorient_worker_from_crrc() {
let pressure = map_epiphany_pressure(None);

View file

@ -68,6 +68,7 @@ pub(crate) struct ThreadState {
current_turn_history: ThreadHistoryBuilder,
last_epiphany_jobs_by_job_id: HashMap<String, ThreadEpiphanyJob>,
last_epiphany_checkpoint_intervention_turn_id: Option<String>,
pending_epiphany_checkpoint_compaction_turn_id: Option<String>,
listener_thread: Option<Weak<CodexThread>>,
}
@ -101,6 +102,7 @@ impl ThreadState {
self.listener_command_tx = None;
self.current_turn_history.reset();
self.last_epiphany_jobs_by_job_id.clear();
self.pending_epiphany_checkpoint_compaction_turn_id = None;
self.listener_thread = None;
}
@ -153,6 +155,62 @@ impl ThreadState {
self.last_epiphany_checkpoint_intervention_turn_id = Some(turn_id.to_string());
true
}
pub(crate) fn mark_epiphany_checkpoint_intervention_pending_compaction(
&mut self,
turn_id: &str,
) {
self.pending_epiphany_checkpoint_compaction_turn_id = Some(turn_id.to_string());
}
pub(crate) fn take_epiphany_checkpoint_intervention_pending_compaction(
&mut self,
turn_id: &str,
) -> bool {
if self
.pending_epiphany_checkpoint_compaction_turn_id
.as_deref()
!= Some(turn_id)
{
return false;
}
self.pending_epiphany_checkpoint_compaction_turn_id = None;
true
}
pub(crate) fn clear_epiphany_checkpoint_intervention_pending_compaction(&mut self) {
self.pending_epiphany_checkpoint_compaction_turn_id = None;
}
}
#[cfg(test)]
mod tests {
use super::ThreadState;
#[test]
fn epiphany_checkpoint_intervention_pending_compaction_is_turn_scoped() {
let mut state = ThreadState::default();
assert!(state.record_epiphany_checkpoint_intervention("turn-a"));
assert!(!state.record_epiphany_checkpoint_intervention("turn-a"));
assert!(!state.take_epiphany_checkpoint_intervention_pending_compaction("turn-a"));
state.mark_epiphany_checkpoint_intervention_pending_compaction("turn-a");
assert!(!state.take_epiphany_checkpoint_intervention_pending_compaction("turn-b"));
assert!(state.take_epiphany_checkpoint_intervention_pending_compaction("turn-a"));
assert!(!state.take_epiphany_checkpoint_intervention_pending_compaction("turn-a"));
}
#[test]
fn epiphany_checkpoint_intervention_pending_compaction_can_be_cleared() {
let mut state = ThreadState::default();
state.mark_epiphany_checkpoint_intervention_pending_compaction("turn-a");
state.clear_epiphany_checkpoint_intervention_pending_compaction();
assert!(!state.take_epiphany_checkpoint_intervention_pending_compaction("turn-a"));
}
}
pub(crate) async fn resolve_server_request_on_thread_listener(