Create a forked session from a parent at a turn boundary. The child inherits the parent's turn records through `fork_turn` as an immutable ledger prefix. No provenance graphs or session rows are copied — the child manifest references the parent by content hash. Returns `(parent_manifest_hash, child_manifest_hash)`.
(
&self,
parent_session_id: &str,
fork_turn: u32,
child_session_id: &str,
)
| 919 | /// |
| 920 | /// Returns `(parent_manifest_hash, child_manifest_hash)`. |
| 921 | pub fn fork_session( |
| 922 | &self, |
| 923 | parent_session_id: &str, |
| 924 | fork_turn: u32, |
| 925 | child_session_id: &str, |
| 926 | ) -> Result<(Hash, Hash), RepositoryError> { |
| 927 | self.ensure_project_identity(atomic_core::kg::project_id::MintReason::Upgrade)?; |
| 928 | // Resolve the parent ledger and manifest. |
| 929 | let (parent_record, parent_turns) = |
| 930 | self.get_session_ledger(parent_session_id)?.ok_or_else(|| { |
| 931 | RepositoryError::Database(format!( |
| 932 | "parent session not found: {}", |
| 933 | parent_session_id |
| 934 | )) |
| 935 | })?; |
| 936 | |
| 937 | let last_parent_turn = parent_record.turn_count.saturating_sub(1); |
| 938 | if fork_turn > last_parent_turn && parent_record.turn_count > 0 { |
| 939 | return Err(RepositoryError::Database(format!( |
| 940 | "fork turn {} exceeds parent turn {} for session {}", |
| 941 | fork_turn, last_parent_turn, parent_session_id |
| 942 | ))); |
| 943 | } |
| 944 | |
| 945 | let parent_manifest = self |
| 946 | .publish_session_manifest(parent_session_id) |
| 947 | .map_err(|e| RepositoryError::Database(format!("parent manifest: {}", e)))?; |
| 948 | |
| 949 | // Seed the child session record with the inherited ledger prefix: |
| 950 | // turns 0..=fork_turn from the parent. The child reuses the parent's |
| 951 | // immutable turn rows — we copy the references, not the provenance. |
| 952 | let inherited: Vec<atomic_core::change::session::SessionTurn> = parent_turns |
| 953 | .into_iter() |
| 954 | .filter(|t| t.turn_number <= fork_turn) |
| 955 | .map(|mut t| { |
| 956 | t.session_id = child_session_id.to_string(); |
| 957 | t |
| 958 | }) |
| 959 | .collect(); |
| 960 | |
| 961 | let child_json_path = self |
| 962 | .dot_dir |
| 963 | .join("sessions") |
| 964 | .join(format!("{}.json", child_session_id)) |
| 965 | .to_string_lossy() |
| 966 | .to_string(); |
| 967 | |
| 968 | let mut txn = self |
| 969 | .pristine |
| 970 | .write_txn() |
| 971 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 972 | for turn in &inherited { |
| 973 | txn.index_inherited_turn(child_session_id, &child_json_path, turn) |
| 974 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 975 | } |
| 976 | // Create the child record even when no turns are inherited. |
| 977 | if inherited.is_empty() { |
| 978 | txn.index_empty_session( |
nothing calls this directly
no test coverage detected