Skip to main content

recover_crashed_turn

Function recover_crashed_turn 

Source
pub fn recover_crashed_turn(
    messages: &mut Vec<SharedMessage>,
    draft: &TurnDraft,
) -> bool
Expand description

Fold an in-flight turn draft left by a process that died mid-turn (agent_core::core::session_draft) into the loaded history.

The saved history is valid (it is only ever saved at round boundaries), so recovery only APPENDS — the cached prefix is untouched:

  • the history already ends with an interruption marker → the turn was already concluded (aborted, or recovered before): nothing to do;
  • it ends with an assistant message → the turn completed (its final history was saved) and only the draft’s removal was lost: nothing to do;
  • otherwise the turn was cut off: the partial reply is appended as a real assistant message — only when the draft belongs to exactly this history (base_len), never a stale one — then the Crash marker.

Returns whether messages changed. Either way the caller removes the draft once the result is saved.