(
repo: &mut atomic_repository::Repository,
options: &TurnRecordOptions<'_>,
)
| 1550 | // record_turn (the main entry point) |
| 1551 | |
| 1552 | fn align_or_repair_session_view( |
| 1553 | repo: &mut atomic_repository::Repository, |
| 1554 | options: &TurnRecordOptions<'_>, |
| 1555 | ) -> AgentResult<atomic_core::WorkingCopyId> { |
| 1556 | let working_copy = |
| 1557 | repo.require_working_copy_id() |
| 1558 | .map_err(|error| AgentError::RecordFailed { |
| 1559 | session_id: options.session.session_id.clone(), |
| 1560 | turn_number: options.turn_number, |
| 1561 | reason: format!( |
| 1562 | "Failed to resolve working-copy identity before aligning session view: {}", |
| 1563 | error |
| 1564 | ), |
| 1565 | })?; |
| 1566 | |
| 1567 | match repo.align_to_view(working_copy, &options.session.view_name) { |
| 1568 | Ok(()) => Ok(working_copy), |
| 1569 | Err(atomic_repository::RepositoryError::ViewNotFound { .. }) => { |
| 1570 | let parent = options |
| 1571 | .session |
| 1572 | .parent_view() |
| 1573 | .map(str::to_string) |
| 1574 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 1575 | |
| 1576 | match repo.create_view_from(&options.session.view_name, &parent) { |
| 1577 | Ok(()) => { |
| 1578 | log::warn!( |
| 1579 | "session view '{}' was missing at record time (SessionStart fork \ |
| 1580 | likely skipped or failed); forked it from '{}' just-in-time", |
| 1581 | options.session.view_name, |
| 1582 | parent, |
| 1583 | ); |
| 1584 | } |
| 1585 | Err(atomic_repository::RepositoryError::ViewAlreadyExists { .. }) => {} |
| 1586 | Err(error) => { |
| 1587 | return Err(AgentError::RecordFailed { |
| 1588 | session_id: options.session.session_id.clone(), |
| 1589 | turn_number: options.turn_number, |
| 1590 | reason: format!( |
| 1591 | "Session view '{}' does not exist and could not be forked \ |
| 1592 | from '{}': {} (refusing to record onto an implicitly-created \ |
| 1593 | orphan view, which would duplicate existing content)", |
| 1594 | options.session.view_name, parent, error |
| 1595 | ), |
| 1596 | }); |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | repo.align_to_view(working_copy, &options.session.view_name) |
| 1601 | .map_err(|error| AgentError::RecordFailed { |
| 1602 | session_id: options.session.session_id.clone(), |
| 1603 | turn_number: options.turn_number, |
| 1604 | reason: format!( |
| 1605 | "Failed to align to session view '{}' after forking it: {}", |
| 1606 | options.session.view_name, error |
| 1607 | ), |
| 1608 | })?; |
| 1609 | Ok(working_copy) |
no test coverage detected