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

Method publish_session_checkpoint

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

Atomically append one immutable checkpoint turn and advance its manifest head. Unlike import/rebuild indexing, this live publication path never rewrites prior `SESSION_TURNS` rows. Repeating the exact turn is idempotent; any conflicting row or non-contiguous append fails closed.

(
        &mut self,
        json_path: &str,
        turn: crate::change::session::SessionTurn,
    )

Source from the content-addressed store, hash-verified

643 /// prior `SESSION_TURNS` rows. Repeating the exact turn is idempotent; any
644 /// conflicting row or non-contiguous append fails closed.
645 pub fn publish_session_checkpoint(
646 &mut self,
647 json_path: &str,
648 turn: crate::change::session::SessionTurn,
649 ) -> PristineResult<crate::change::session::SessionCheckpointPublication> {
650 use crate::change::session::{
651 SessionCheckpointPublication, SessionManifest, SessionRecord,
652 };
653
654 let mut turns = self.load_session_turns_for_write(&turn.session_id)?;
655 if let Some(existing) = turns
656 .iter()
657 .find(|existing| existing.turn_number == turn.turn_number)
658 {
659 if existing != &turn {
660 return Err(PristineError::Serialization {
661 message: format!(
662 "session checkpoint turn {} conflicts for {}",
663 turn.turn_number, turn.session_id
664 ),
665 });
666 }
667 } else {
668 if turn.turn_number as usize != turns.len()
669 || turn.previous_provenance != turns.last().map(|prior| prior.provenance_hash)
670 {
671 return Err(PristineError::Serialization {
672 message: format!(
673 "session checkpoint turn {} is not an append for {}",
674 turn.turn_number, turn.session_id
675 ),
676 });
677 }
678 let record = self
679 .load_session_record_for_write(&turn.session_id)?
680 .unwrap_or_else(|| SessionRecord {
681 session_id: turn.session_id.clone(),
682 json_path: json_path.to_string(),
683 view_name: None,
684 parent_view: None,
685 first_provenance: None,
686 latest_provenance: None,
687 turn_count: 0,
688 started_at: turn.timestamp,
689 ended_at: None,
690 status: crate::change::session::SessionStatus::Active,
691 });
692 self.append_session_turn(record, turn.clone(), &turns)?;
693 self.mark_current_session_ledger_schema(&turn.session_id)?;
694 turns.push(turn.clone());
695 }
696
697 let (parent_session, fork_turn) = {
698 let heads = self.txn.open_table(SESSION_HEADS)?;
699 let manifests = self.txn.open_table(SESSION_MANIFESTS)?;
700 let lineage = match heads.get(turn.session_id.as_str())? {
701 Some(head) => match manifests.get(head.value())? {
702 Some(bytes) => {

Calls 14

lastMethod · 0.80
append_session_turnMethod · 0.80
valueMethod · 0.80
as_refMethod · 0.80
save_session_manifestMethod · 0.80
getMethod · 0.65
iterMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected