(
repo: &mut atomic_repository::Repository,
options: &TurnRecordOptions<'_>,
)
| 970 | // record_turn (the main entry point) |
| 971 | |
| 972 | fn align_or_repair_session_view( |
| 973 | repo: &mut atomic_repository::Repository, |
| 974 | options: &TurnRecordOptions<'_>, |
| 975 | ) -> AgentResult<atomic_core::WorkingCopyId> { |
| 976 | let working_copy = |
| 977 | repo.require_working_copy_id() |
| 978 | .map_err(|error| AgentError::RecordFailed { |
| 979 | session_id: options.session.session_id.clone(), |
| 980 | turn_number: options.turn_number, |
| 981 | reason: format!( |
| 982 | "Failed to resolve working-copy identity before aligning session view: {}", |
| 983 | error |
| 984 | ), |
| 985 | })?; |
| 986 | |
| 987 | match repo.align_to_view(working_copy, &options.session.view_name) { |
| 988 | Ok(()) => Ok(working_copy), |
| 989 | Err(atomic_repository::RepositoryError::ViewNotFound { .. }) => { |
| 990 | let parent = options |
| 991 | .session |
| 992 | .parent_view() |
| 993 | .map(str::to_string) |
| 994 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 995 | |
| 996 | match repo.create_view_from(&options.session.view_name, &parent) { |
| 997 | Ok(()) => { |
| 998 | log::warn!( |
| 999 | "session view '{}' was missing at record time (SessionStart fork \ |
| 1000 | likely skipped or failed); forked it from '{}' just-in-time", |
| 1001 | options.session.view_name, |
| 1002 | parent, |
| 1003 | ); |
| 1004 | } |
| 1005 | Err(atomic_repository::RepositoryError::ViewAlreadyExists { .. }) => {} |
| 1006 | Err(error) => { |
| 1007 | return Err(AgentError::RecordFailed { |
| 1008 | session_id: options.session.session_id.clone(), |
| 1009 | turn_number: options.turn_number, |
| 1010 | reason: format!( |
| 1011 | "Session view '{}' does not exist and could not be forked \ |
| 1012 | from '{}': {} (refusing to record onto an implicitly-created \ |
| 1013 | orphan view, which would duplicate existing content)", |
| 1014 | options.session.view_name, parent, error |
| 1015 | ), |
| 1016 | }); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | repo.align_to_view(working_copy, &options.session.view_name) |
| 1021 | .map_err(|error| AgentError::RecordFailed { |
| 1022 | session_id: options.session.session_id.clone(), |
| 1023 | turn_number: options.turn_number, |
| 1024 | reason: format!( |
| 1025 | "Failed to align to session view '{}' after forking it: {}", |
| 1026 | options.session.view_name, error |
| 1027 | ), |
| 1028 | })?; |
| 1029 | Ok(working_copy) |
no test coverage detected