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

Method upsert_session_lifecycle

atomic-core/src/pristine/txn/write/mod.rs:689–739  ·  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

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