MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / upsert_session_lifecycle

Method upsert_session_lifecycle

atomic-core/src/pristine/txn/write/mod.rs:690–740  ·  view source on GitHub ↗

Reconcile lifecycle metadata for a session record. Called from agent session start/end hooks. Creates the record if the session has no ledger entries yet; otherwise updates only the fields supplied, preserving ledger data (provenance links, turn count). `ended_at: None` on a re-entered (resumed) session clears a prior end.

(
        &mut self,
        session_id: &str,
        json_path: &str,
        view_name: Option<String>,
        parent_view: Option<String>,
        ended_at: Option<i64>,
    )

Source from the content-addressed store, hash-verified

688 /// supplied, preserving ledger data (provenance links, turn count).
689 /// `ended_at: None` on a re-entered (resumed) session clears a prior end.
690 pub fn upsert_session_lifecycle(
691 &mut self,
692 session_id: &str,
693 json_path: &str,
694 view_name: Option<String>,
695 parent_view: Option<String>,
696 ended_at: Option<i64>,
697 ) -> PristineResult<()> {
698 use crate::change::session::SessionRecord;
699
700 let mut sessions = self.txn.open_table(SESSIONS)?;
701 let mut record = match sessions.get(session_id)? {
702 Some(value) => SessionRecord::from_bytes(value.value()).map_err(|e| {
703 PristineError::Serialization {
704 message: format!("session record decode: {}", e),
705 }
706 })?,
707 None => SessionRecord {
708 session_id: session_id.to_string(),
709 json_path: json_path.to_string(),
710 view_name: None,
711 parent_view: None,
712 first_provenance: None,
713 latest_provenance: None,
714 turn_count: 0,
715 started_at: chrono::Utc::now().timestamp(),
716 ended_at: None,
717 },
718 };
719
720 if record.json_path.is_empty() {
721 record.json_path = json_path.to_string();
722 }
723 if view_name.is_some() {
724 record.view_name = view_name;
725 }
726 if parent_view.is_some() {
727 record.parent_view = parent_view;
728 }
729 // Explicit assignment: Some(ts) ends the session, None clears a
730 // stale end marker when a session is re-entered.
731 record.ended_at = ended_at;
732
733 let bytes = record.to_bytes();
734 sessions.insert(session_id, bytes.as_slice())?;
735
736 // Refresh the session node's lifecycle metadata (ATOM-16).
737 drop(sessions);
738 self.emit_session_node(&record)?;
739 Ok(())
740 }
741
742 /// Store an immutable session manifest and advance its convenience head.
743 pub fn save_session_manifest(

Calls 7

emit_session_nodeMethod · 0.80
getMethod · 0.65
timestampMethod · 0.45
is_emptyMethod · 0.45
to_bytesMethod · 0.45
insertMethod · 0.45
as_sliceMethod · 0.45