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

Function captured_commit_of_open_turn

atomic-agent/src/record/mod.rs:1206–1253  ·  view source on GitHub ↗

The commit the in-flight turn of `session` ended on, when the latest commit-time capture authenticates it. Both turn boundaries sit on a detached HEAD (the session's Draft view, RFC §8.1) in the same working copy, HEAD moved to a different tree, and the capture verifies for this session, turn, working copy, parent HEAD and committed tree. A commit that moved a branch, or switched branches, is not

(
    repo: &atomic_repository::Repository,
    repo_root: &Path,
    session: &crate::turn::session::AgentSession,
)

Source from the content-addressed store, hash-verified

1204/// and committed tree. A commit that moved a branch, or switched branches,
1205/// is not this case.
1206fn captured_commit_of_open_turn(
1207 repo: &atomic_repository::Repository,
1208 repo_root: &Path,
1209 session: &crate::turn::session::AgentSession,
1210) -> Option<OpenTurnCommit> {
1211 let turn = session.turn_count.saturating_add(1);
1212 let boundary_start = session.boundary_start.as_ref()?;
1213 let start_git = boundary_start.git.as_ref()?;
1214 let boundary_end = capture_turn_boundary(repo, repo_root, &session.session_id, turn)?;
1215 let end_git = boundary_end.git.as_ref()?;
1216 if start_git.head_symref.is_some() || end_git.head_symref.is_some() {
1217 return None;
1218 }
1219 if boundary_start.working_copy != boundary_end.working_copy {
1220 return None;
1221 }
1222 let parent_oid = start_git.head_oid.clone()?;
1223 let commit_oid = end_git.head_oid.clone()?;
1224 if parent_oid == commit_oid || start_git.head_tree == end_git.head_tree {
1225 return None;
1226 }
1227 let capture = crate::turn::capture::verify_capture(
1228 &sessions_dir_for(repo_root),
1229 session,
1230 turn,
1231 &boundary_end.working_copy,
1232 Some(parent_oid.as_str()),
1233 end_git.head_tree.as_deref(),
1234 boundary_start.at,
1235 );
1236 match capture {
1237 Ok(Some(_)) => Some(OpenTurnCommit {
1238 boundary_end,
1239 parent_oid,
1240 commit_oid,
1241 }),
1242 Ok(None) => None,
1243 Err(error) => {
1244 log::warn!(
1245 "Commit-time capture failed authentication for session {} turn {}: {}",
1246 session.session_id,
1247 turn,
1248 error
1249 );
1250 None
1251 }
1252 }
1253}
1254
1255/// The change an interrupted turn end already recorded for the turn that is
1256/// still in flight.

Calls 6

capture_turn_boundaryFunction · 0.85
verify_captureFunction · 0.85
sessions_dir_forFunction · 0.85
as_refMethod · 0.80
cloneMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected