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

Function write_capture

atomic-agent/src/turn/capture.rs:269–303  ·  view source on GitHub ↗

Write the capture for one turn of one session, signing it first. Review R9: attempts are create-only. A retried commit within the same turn writes `turn-N.attempt-2.json` and so on instead of overwriting the previous attempt's evidence; earlier attempts stay durable for review.

(
    sessions_dir: &Path,
    session: &mut AgentSession,
    turn: u32,
    working_copy: String,
    token: &atomic_repository::GitObservationToken,
)

Source from the content-addressed store, hash-verified

267/// turn writes `turn-N.attempt-2.json` and so on instead of overwriting the
268/// previous attempt's evidence; earlier attempts stay durable for review.
269pub fn write_capture(
270 sessions_dir: &Path,
271 session: &mut AgentSession,
272 turn: u32,
273 working_copy: String,
274 token: &atomic_repository::GitObservationToken,
275) -> AgentResult<PathBuf> {
276 let key = session.ensure_mac_key();
277 let mut capture = build_capture(session, turn, working_copy, token);
278 capture.sign(&key);
279 let dir = capture_dir(sessions_dir, &session.session_id)?;
280 std::fs::create_dir_all(&dir)?;
281 // Find the first attempt slot that does not exist yet, exclusively.
282 for attempt in 1..=64u32 {
283 let path = attempt_capture_path(sessions_dir, &session.session_id, turn, attempt)?;
284 match std::fs::OpenOptions::new()
285 .write(true)
286 .create_new(true)
287 .open(&path)
288 {
289 Ok(mut file) => {
290 file.write_all(&capture.to_json()?)?;
291 file.sync_all()?;
292 return Ok(path);
293 }
294 Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
295 Err(error) => return Err(error.into()),
296 }
297 }
298 Err(crate::error::AgentError::RecordFailed {
299 session_id: session.session_id.clone(),
300 turn_number: turn,
301 reason: "too many commit attempts without a turn boundary (64)".to_string(),
302 })
303}
304
305/// Load and fully verify the capture for one turn of one session.
306///

Calls 10

build_captureFunction · 0.85
capture_dirFunction · 0.85
attempt_capture_pathFunction · 0.85
ensure_mac_keyMethod · 0.80
signMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
to_jsonMethod · 0.45
kindMethod · 0.45
cloneMethod · 0.45