Skip to main content

recover_turn_draft

Function recover_turn_draft 

Source
pub async fn recover_turn_draft(conv: &mut ConversationState)
Expand description

Crash recovery: if sessions/<id>.turn exists, the process that last ran this session died with a turn open. Fold the draft into the history (engine::interrupt::recover_crashed_turn), persist that, THEN remove the draft.

Run ONLY by the holder of the session lock, after taking it (actor create, unpark and /resume; rpc and synaps server after lock_session): a draft under a lock held elsewhere belongs to a turn that is running right now. Legacy chat takes no lock and never recovers. Loading itself (resolve_or_create_session) leaves the draft alone.

The draft is removed only once the recovered history is on disk; if that save fails the draft stays, and the next holder retries (recovery is idempotent through its own marker).