Persist the first WIP-backed refusal for a managed run. The recovery ref must already exist before this is called. Repeated hook delivery reuses the first refusal instead of replacing its recovery root.
(
repository_root: &Path,
lifecycle: &ManagedLifecycle,
session_id: &str,
refusal: IncompleteSession,
)
| 680 | /// The recovery ref must already exist before this is called. Repeated hook |
| 681 | /// delivery reuses the first refusal instead of replacing its recovery root. |
| 682 | pub(super) fn persist_refusal( |
| 683 | repository_root: &Path, |
| 684 | lifecycle: &ManagedLifecycle, |
| 685 | session_id: &str, |
| 686 | refusal: IncompleteSession, |
| 687 | ) -> CliResult<ManagedLifecycle> { |
| 688 | let dot_dir = |
| 689 | atomic_repository::Repository::canonical_dot_dir(repository_root).map_err(|e| { |
| 690 | CliError::Internal(anyhow!( |
| 691 | "cannot resolve managed lifecycle store for refusal: {}", |
| 692 | e |
| 693 | )) |
| 694 | })?; |
| 695 | let dir = lifecycle_dir(&dot_dir); |
| 696 | let mut current = |
| 697 | load_lifecycle(&dir, &lifecycle.run_id)?.ok_or_else(|| CliError::InvalidArgument { |
| 698 | message: format!( |
| 699 | "managed lifecycle '{}' ended before its refusal could be persisted", |
| 700 | lifecycle.run_id |
| 701 | ), |
| 702 | })?; |
| 703 | if current.refusal.is_none() { |
| 704 | current.refusal = Some(persist_first_refusal( |
| 705 | &dir, |
| 706 | &lifecycle.run_id, |
| 707 | ManagedBoundaryRefusal { |
| 708 | session_id: session_id.to_string(), |
| 709 | outcome: refusal, |
| 710 | }, |
| 711 | )?); |
| 712 | current.updated_at = now_secs(); |
| 713 | save_lifecycle(&dir, ¤t)?; |
| 714 | } |
| 715 | Ok(current) |
| 716 | } |
| 717 | |
| 718 | fn resolve_dot_dir() -> CliResult<PathBuf> { |
| 719 | let cwd = std::env::current_dir().map_err(CliError::Io)?; |