Persist a managed-agent refusal without creating a turn or provenance. The first incomplete outcome wins. Repeated turn-end/session-end hooks therefore return the same recovery object and cannot duplicate or rewrite forensic state.
(
&mut self,
session_id: &str,
json_path: &str,
view_name: Option<String>,
parent_view: Option<String>,
incomplete: &crate::change::session::IncompleteS
| 960 | /// therefore return the same recovery object and cannot duplicate or |
| 961 | /// rewrite forensic state. |
| 962 | pub fn mark_session_incomplete( |
| 963 | &mut self, |
| 964 | session_id: &str, |
| 965 | json_path: &str, |
| 966 | view_name: Option<String>, |
| 967 | parent_view: Option<String>, |
| 968 | incomplete: &crate::change::session::IncompleteSession, |
| 969 | ) -> PristineResult<crate::change::session::IncompleteSession> { |
| 970 | use crate::change::session::{SessionRecord, SessionStatus}; |
| 971 | |
| 972 | let mut sessions = self.txn.open_table(SESSIONS)?; |
| 973 | let mut record = match sessions.get(session_id)? { |
| 974 | Some(value) => SessionRecord::from_bytes(value.value()).map_err(|e| { |
| 975 | PristineError::Serialization { |
| 976 | message: format!("session record decode: {}", e), |
| 977 | } |
| 978 | })?, |
| 979 | None => SessionRecord { |
| 980 | session_id: session_id.to_string(), |
| 981 | json_path: json_path.to_string(), |
| 982 | view_name: None, |
| 983 | parent_view: None, |
| 984 | first_provenance: None, |
| 985 | latest_provenance: None, |
| 986 | turn_count: 0, |
| 987 | started_at: chrono::Utc::now().timestamp_millis(), |
| 988 | ended_at: None, |
| 989 | status: SessionStatus::Active, |
| 990 | }, |
| 991 | }; |
| 992 | |
| 993 | if record.json_path.is_empty() { |
| 994 | record.json_path = json_path.to_string(); |
| 995 | } |
| 996 | if view_name.is_some() { |
| 997 | record.view_name = view_name; |
| 998 | } |
| 999 | if parent_view.is_some() { |
| 1000 | record.parent_view = parent_view; |
| 1001 | } |
| 1002 | |
| 1003 | let existing = record.status.incomplete().cloned(); |
| 1004 | let persisted = if let Some(existing) = existing { |
| 1005 | existing |
| 1006 | } else { |
| 1007 | record.status = SessionStatus::Incomplete(incomplete.clone()); |
| 1008 | incomplete.clone() |
| 1009 | }; |
| 1010 | |
| 1011 | let bytes = record.to_bytes(); |
| 1012 | sessions.insert(session_id, bytes.as_slice())?; |
| 1013 | drop(sessions); |
| 1014 | self.emit_session_node(&record)?; |
| 1015 | Ok(persisted) |
| 1016 | } |
| 1017 | |
| 1018 | /// Attach durable turn boundaries and the semantic outcome to an already |
| 1019 | /// indexed turn row (CB-12A, RFC §10.1/§10.2). |