mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Preserve turn attribution across recovery and compaction (#51402)
## Why Recovering an interrupted turn replaced its original trigger with `retry` and restored only its root lineage from model context. Turns suspended before that context was written could lose their attribution entirely. ## What changed - Persist regular-turn attribution in `TurnStartedEvent` and compaction resume metadata, including the trigger, parent and root turn IDs, and initiating agent path. - Restore matching attribution during recovery, keep unknown triggers absent, and retain the model-context root fallback for older records. - Reconstruct attribution from surviving turns across rollback and late completion or abort events, and clear inherited attribution when spawning a forked agent. ## Testing Add coverage for repeated cold recovery, suspension before context persistence, legacy rollouts, fresh attribution on subsequent turns, compaction checkpoints, rollback, and late terminal events. GitOrigin-RevId: 85b5763e8fbd48a1ea2c07cfda8196e63c2cd33a
This commit is contained in:
@@ -318,6 +318,7 @@ use crate::state::PendingRequestPermissions;
|
||||
use crate::state::ReasoningEffortPin;
|
||||
use crate::state::SessionServices;
|
||||
use crate::state::SessionState;
|
||||
use crate::state::TaskKind;
|
||||
#[cfg(test)]
|
||||
use crate::stream_events_utils::HandleOutputCtx;
|
||||
#[cfg(test)]
|
||||
@@ -1754,6 +1755,7 @@ impl Session {
|
||||
last_started_turn_id,
|
||||
previous_turn_settings,
|
||||
reference_context_item,
|
||||
turn_attribution,
|
||||
world_state_baseline,
|
||||
window_number,
|
||||
first_window_id,
|
||||
@@ -1809,6 +1811,7 @@ impl Session {
|
||||
reviewer_compaction_hash.as_deref(),
|
||||
);
|
||||
state.last_started_turn_id = last_started_turn_id;
|
||||
state.turn_attribution = turn_attribution;
|
||||
if let Some(world_state) = world_state_baseline {
|
||||
state.history.set_world_state_baseline(world_state);
|
||||
}
|
||||
@@ -2259,8 +2262,9 @@ impl Session {
|
||||
.trusted_guardian_reviewer
|
||||
}
|
||||
|
||||
pub(crate) async fn emit_turn_started(&self, turn_context: &TurnContext) {
|
||||
pub(crate) async fn emit_turn_started(&self, turn_context: &TurnContext, task_kind: TaskKind) {
|
||||
let event = TurnStartedEvent {
|
||||
turn_attribution: (task_kind == TaskKind::Regular).then(|| turn_context.attribution()),
|
||||
turn_id: turn_context.sub_id.clone(),
|
||||
root_turn_id: Some(
|
||||
turn_context
|
||||
@@ -4082,6 +4086,7 @@ impl Session {
|
||||
resume_metadata: Some(CompactionResumeMetadata {
|
||||
multi_agent_version: self.multi_agent_version(),
|
||||
last_started_turn_id: state.last_started_turn_id.clone(),
|
||||
turn_attribution: state.turn_attribution.clone(),
|
||||
previous_turn_settings: state.previous_turn_settings(),
|
||||
}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user