lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

receipt.rs (29059B)


      1 //! Owned operation observations. Receipt values grant no authority, prove no
      2 //! custom adapter qualification and never restart a retained signing operation.
      3 use crate::{Admission, Error};
      4 use alloc::boxed::Box;
      5 use core::{fmt, num::NonZeroU64};
      6 #[cfg(feature = "receipts")]
      7 use radroots_domain::ChatMessage;
      8 use radroots_domain::{
      9     CheckpointDigest, CheckpointRef, CommandContextData, CommandDigest, EnvelopeEventId,
     10     IssuanceWindow, MessageId, PublicKey, RecordId, SigningAttemptId, SourceId, TransactionId,
     11     UnixSeconds,
     12 };
     13 use radroots_protocol::intent::ArtifactRole;
     14 
     15 /// Installation is independent of signature and relay observations.
     16 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     17 #[non_exhaustive]
     18 pub enum BusinessInstallation {
     19     /// This effect class has no business installation.
     20     NotApplicable,
     21     /// No installation is confirmed.
     22     NotInstalled,
     23     /// Actual installation was confirmed.
     24     Installed,
     25     /// Installation completion requires reconciliation.
     26     Uncertain,
     27 }
     28 /// Issuance classification, without conflating recipients or delivery.
     29 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     30 #[non_exhaustive]
     31 pub enum Issuance {
     32     /// No retained issuance work has been bound.
     33     None,
     34     /// Retained work remains before complete obtained evidence.
     35     Pending,
     36     /// Every expected artifact has obtained evidence.
     37     Obtained,
     38     /// At least one retained invocation lacks a known obtained result.
     39     Unknown,
     40     /// Qualified evidence explicitly proves no issuance; absence alone does not.
     41     ProvablyUnissued,
     42 }
     43 /// Delivery observation progress; observed does not mean every relay accepted.
     44 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     45 #[non_exhaustive]
     46 pub enum Delivery {
     47     /// No exact publication work has started.
     48     NotStarted,
     49     /// Retained publication work awaits observations.
     50     Pending,
     51     /// The requested observation scope has completed; inspect each target.
     52     Observed,
     53     /// Publication completion remains unknown.
     54     Unknown,
     55 }
     56 /// Why a caller's observation ended, independently of retained operation state.
     57 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     58 #[non_exhaustive]
     59 pub enum WaitTermination {
     60     /// The caller received this observation, possibly of a pending operation.
     61     Returned,
     62     /// The caller stopped waiting.
     63     Cancelled,
     64     /// The caller's wait deadline elapsed.
     65     DeadlineExceeded,
     66     /// The client closed its observation scope.
     67     ClientClosed,
     68 }
     69 /// Required continuation is explicit and never permission for blind reissue.
     70 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     71 #[non_exhaustive]
     72 pub enum RecoveryRequirement {
     73     /// Continue using the original captured command and retained identity.
     74     ContinueOriginalOperation,
     75     /// Reconcile the original potential issuance using its qualified contract.
     76     ReconcileIssuance,
     77     /// Install matching already obtained evidence without releasing its claims.
     78     InstallObtainedEvidence,
     79     /// Continue retained exact publication work.
     80     ResumeDelivery,
     81     /// An operator must reconcile the original state.
     82     ManualReconciliation,
     83 }
     84 /// One exact event/target observation, separate from business success.
     85 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     86 #[non_exhaustive]
     87 pub enum TargetObservation {
     88     /// The target explicitly accepted this exact event.
     89     Accepted,
     90     /// The target explicitly rejected this exact event.
     91     Rejected,
     92     /// No matching observation arrived before the bounded attempt ended.
     93     TimedOut,
     94     /// The transport disconnected without a matching acknowledgement.
     95     Disconnected,
     96     /// Completion requires reconciliation.
     97     Unknown,
     98     /// The adapter explicitly reports that it did not attempt this target.
     99     NotAttempted,
    100 }
    101 macro_rules! copied {
    102     ($name:ident, $ty:ty, $field:ident, $doc:literal) => {
    103         #[doc=$doc]
    104         pub const fn $name(&self) -> $ty {
    105             self.$field
    106         }
    107     };
    108 }
    109 
    110 /// A protected artifact reference and its independent original issuance facts.
    111 /// No raw signed bytes, ciphertext or private command text is retained here.
    112 #[derive(Clone, Copy, Eq, PartialEq)]
    113 pub struct ArtifactObservation {
    114     role: ArtifactRole,
    115     recipient: Option<PublicKey>,
    116     expected_event: Option<EnvelopeEventId>,
    117     issuance: Issuance,
    118     attempt: Option<SigningAttemptId>,
    119     claim_transaction: Option<TransactionId>,
    120     intent_digest: Option<[u8; 32]>,
    121     capture_transaction: Option<TransactionId>,
    122     publication_transaction: Option<TransactionId>,
    123     obtained_digest: Option<[u8; 32]>,
    124     observed_at: Option<NonZeroU64>,
    125 }
    126 impl ArtifactObservation {
    127     copied!(
    128         role,
    129         ArtifactRole,
    130         role,
    131         "Exact artifact purpose, not command permission."
    132     );
    133     copied!(
    134         recipient,
    135         Option<PublicKey>,
    136         recipient,
    137         "Exact intended recipient, when private."
    138     );
    139     copied!(
    140         expected_event,
    141         Option<EnvelopeEventId>,
    142         expected_event,
    143         "Exact seal/event identity, never a logical record ID."
    144     );
    145     copied!(
    146         issuance,
    147         Issuance,
    148         issuance,
    149         "This artifact's independent issuance state."
    150     );
    151     copied!(
    152         attempt_id,
    153         Option<SigningAttemptId>,
    154         attempt,
    155         "Original full-width attempt identity."
    156     );
    157     copied!(
    158         claim_transaction_id,
    159         Option<TransactionId>,
    160         claim_transaction,
    161         "Original confirmed claim transaction."
    162     );
    163     copied!(
    164         intent_digest,
    165         Option<[u8; 32]>,
    166         intent_digest,
    167         "Exact original intent commitment."
    168     );
    169     copied!(
    170         capture_transaction_id,
    171         Option<TransactionId>,
    172         capture_transaction,
    173         "Original protected capture transaction."
    174     );
    175     copied!(
    176         obtained_digest,
    177         Option<[u8; 32]>,
    178         obtained_digest,
    179         "Digest of the exact original obtained representation."
    180     );
    181     copied!(
    182         publication_transaction_id,
    183         Option<TransactionId>,
    184         publication_transaction,
    185         "Original transaction retaining this recipient's exact publication work."
    186     );
    187     copied!(
    188         observed_at_unix_ms,
    189         Option<NonZeroU64>,
    190         observed_at,
    191         "Original optional observation; missing remains explicit."
    192     );
    193 }
    194 impl fmt::Debug for ArtifactObservation {
    195     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    196         f.write_str("ArtifactObservation(<redacted>)")
    197     }
    198 }
    199 /// Actual retained event/target observation. An empty collection reports no
    200 /// delivery observations; selecting a route is not an acknowledgement.
    201 pub struct DeliveryObservation {
    202     event: EnvelopeEventId,
    203     recipient: Option<PublicKey>,
    204     target: Box<str>,
    205     request: Box<str>,
    206     target_fingerprint: Box<str>,
    207     ordinal: u8,
    208     outcome: TargetObservation,
    209     observed_at: Option<NonZeroU64>,
    210 }
    211 impl DeliveryObservation {
    212     copied!(
    213         event_id,
    214         EnvelopeEventId,
    215         event,
    216         "Exact event whose target observation was checked."
    217     );
    218     copied!(
    219         recipient,
    220         Option<PublicKey>,
    221         recipient,
    222         "Retained recipient scope, when private."
    223     );
    224     copied!(
    225         outcome,
    226         TargetObservation,
    227         outcome,
    228         "Individual target observation; no business effect is implied."
    229     );
    230     copied!(
    231         observed_at_unix_ms,
    232         Option<NonZeroU64>,
    233         observed_at,
    234         "Original optional target observation time."
    235     );
    236     /// Borrows the exact retained target for authorized presentation.
    237     pub fn target(&self) -> &str {
    238         &self.target
    239     }
    240     /// Full original retained potential invocation identity.
    241     pub fn request_id(&self) -> &str {
    242         &self.request
    243     }
    244     /// Exact canonical target identity, independent of display labels.
    245     pub fn target_fingerprint(&self) -> &str {
    246         &self.target_fingerprint
    247     }
    248     /// Original endpoint potential invocation number, from one through twelve.
    249     pub const fn target_ordinal(&self) -> u8 {
    250         self.ordinal
    251     }
    252 }
    253 impl fmt::Debug for DeliveryObservation {
    254     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    255         f.write_str("DeliveryObservation(<redacted>)")
    256     }
    257 }
    258 
    259 /// Actual retained command family, including before installation. This is an
    260 /// observation discriminator and supplies no authority to execute a command.
    261 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
    262 #[non_exhaustive]
    263 pub enum OperationKind {
    264     /// Retained private chat command.
    265     Chat,
    266     /// Retained public listing command.
    267     Listing,
    268 }
    269 /// Actual installed business value in an original-operation observation.
    270 #[derive(Clone, Eq, PartialEq)]
    271 pub enum OperationValue {
    272     /// Original installed private message, without a public-role conversion.
    273     Chat(Box<radroots_domain::ChatMessage>),
    274     /// Original installed public revision, without a private participant.
    275     Listing(Box<radroots_domain::listing::Listing>),
    276 }
    277 impl OperationValue {
    278     /// Borrows an actual private result only.
    279     pub fn as_chat(&self) -> Option<&radroots_domain::ChatMessage> {
    280         match self {
    281             Self::Chat(v) => Some(v),
    282             Self::Listing(_) => None,
    283         }
    284     }
    285     /// Borrows an actual public result only.
    286     pub fn as_listing(&self) -> Option<&radroots_domain::listing::Listing> {
    287         match self {
    288             Self::Listing(v) => Some(v),
    289             Self::Chat(_) => None,
    290         }
    291     }
    292 }
    293 impl fmt::Debug for OperationValue {
    294     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    295         f.write_str("OperationValue(<redacted>)")
    296     }
    297 }
    298 /// Common original-operation status. Querying preserves the actual family and
    299 /// never interprets a public listing as a message, signing or dispatch right.
    300 pub type OperationStatus = OperationReceipt<OperationValue>;
    301 
    302 /// Owned observation of one original operation. It does not authenticate a
    303 /// principal or qualify a custom host. Business, issuance, delivery and caller
    304 /// wait dimensions remain independent; private payloads never enter diagnostics.
    305 pub struct OperationReceipt<T> {
    306     kind: OperationKind,
    307     context: CommandContextData,
    308     command_digest: CommandDigest,
    309     admission: Admission,
    310     admission_transaction: TransactionId,
    311     plan_transaction: Option<TransactionId>,
    312     installation_transaction: Option<TransactionId>,
    313     installed_at: Option<UnixSeconds>,
    314     issuance_window: IssuanceWindow,
    315     authority_checkpoint: CheckpointRef,
    316     operation_checkpoint: CheckpointDigest,
    317     conflicting_records: Box<[RecordId]>,
    318     conflicting_sources: Box<[SourceId]>,
    319     observed_at: UnixSeconds,
    320     business_installation: BusinessInstallation,
    321     business_result: Option<T>,
    322     message_id: Option<MessageId>,
    323     record_ids: Box<[RecordId]>,
    324     artifacts: Box<[ArtifactObservation]>,
    325     issuance: Issuance,
    326     delivery: Delivery,
    327     delivery_observations: Box<[DeliveryObservation]>,
    328     #[cfg(feature = "receipts")]
    329     delivery_attempts: Box<[radroots_storage::command::DeliveryAttemptSummary]>,
    330     wait_termination: WaitTermination,
    331     recovery: Box<[RecoveryRequirement]>,
    332     error: Option<Error>,
    333 }
    334 impl<T> OperationReceipt<T> {
    335     /// Actual original command family, independently of installed results.
    336     pub const fn kind(&self) -> OperationKind {
    337         self.kind
    338     }
    339     /// Complete original outer/target intent references. These contain no raw
    340     /// payload and grant no dispatch permission or adapter qualification.
    341     #[cfg(feature = "receipts")]
    342     pub fn delivery_attempts(&self) -> &[radroots_storage::command::DeliveryAttemptSummary] {
    343         &self.delivery_attempts
    344     }
    345     /// Original captured data; this is not an authenticated executable context.
    346     pub const fn context(&self) -> &CommandContextData {
    347         &self.context
    348     }
    349     copied!(
    350         command_digest,
    351         CommandDigest,
    352         command_digest,
    353         "Original semantic command commitment."
    354     );
    355     copied!(
    356         admission,
    357         Admission,
    358         admission,
    359         "Actual reported initial-admission disposition."
    360     );
    361     /// Reports confirmed preparation only, independently of later effects.
    362     pub const fn durable(&self) -> bool {
    363         matches!(self.admission, Admission::Confirmed)
    364     }
    365     copied!(
    366         admission_transaction_id,
    367         TransactionId,
    368         admission_transaction,
    369         "Original confirmed preparation transaction."
    370     );
    371     copied!(
    372         plan_transaction_id,
    373         Option<TransactionId>,
    374         plan_transaction,
    375         "Original complete-plan transaction, when present."
    376     );
    377     copied!(
    378         issuance_window,
    379         IssuanceWindow,
    380         issuance_window,
    381         "Original first-issue bounds; never restarted by a receipt."
    382     );
    383     copied!(
    384         installation_transaction_id,
    385         Option<TransactionId>,
    386         installation_transaction,
    387         "Original exactly-once logical installation transaction."
    388     );
    389     copied!(
    390         installed_at,
    391         Option<UnixSeconds>,
    392         installed_at,
    393         "Actual original installation observation, separate from message creation."
    394     );
    395     /// Authority/evidence checkpoint originally captured by the operation.
    396     pub const fn authority_checkpoint(&self) -> &CheckpointRef {
    397         &self.authority_checkpoint
    398     }
    399     copied!(
    400         operation_checkpoint,
    401         CheckpointDigest,
    402         operation_checkpoint,
    403         "Stable identity of this coherent retained progress observation."
    404     );
    405     /// Missing sources at the original authority checkpoint; partial coverage
    406     /// never becomes global completeness because a local query succeeded.
    407     pub fn missing_sources(&self) -> &[SourceId] {
    408         self.authority_checkpoint.missing()
    409     }
    410     /// Structured-record conflicts in this scoped observation. Empty does not
    411     /// establish complete remote history.
    412     pub fn conflicting_records(&self) -> &[RecordId] {
    413         &self.conflicting_records
    414     }
    415     /// Source conflicts in this scoped observation, separate from record IDs.
    416     pub fn conflicting_sources(&self) -> &[SourceId] {
    417         &self.conflicting_sources
    418     }
    419     copied!(
    420         observed_at,
    421         UnixSeconds,
    422         observed_at,
    423         "Actual query observation; no global freshness guarantee."
    424     );
    425     copied!(
    426         business_installation,
    427         BusinessInstallation,
    428         business_installation,
    429         "Installation outcome independently of signing and delivery."
    430     );
    431     /// Borrows the owned installed business snapshot when actually available.
    432     pub fn business_result(&self) -> Option<&T> {
    433         self.business_result.as_ref()
    434     }
    435     copied!(
    436         message_id,
    437         Option<MessageId>,
    438         message_id,
    439         "Original logical message identity, separate from signed event IDs."
    440     );
    441     /// Borrows actual structured record IDs; chat message IDs are not cast here.
    442     pub fn record_ids(&self) -> &[RecordId] {
    443         &self.record_ids
    444     }
    445     /// Borrows independent exact artifact references and issuance observations.
    446     pub fn artifacts(&self) -> &[ArtifactObservation] {
    447         &self.artifacts
    448     }
    449     copied!(
    450         issuance,
    451         Issuance,
    452         issuance,
    453         "Aggregate issuance; any unresolved invocation stays unknown."
    454     );
    455     copied!(
    456         delivery,
    457         Delivery,
    458         delivery,
    459         "Delivery progress, never a business rollback signal."
    460     );
    461     /// Borrows actual exact event/target observations.
    462     pub fn delivery_observations(&self) -> &[DeliveryObservation] {
    463         &self.delivery_observations
    464     }
    465     copied!(
    466         wait_termination,
    467         WaitTermination,
    468         wait_termination,
    469         "Caller waiting is independent of retained effects."
    470     );
    471     /// Purely changes this caller observation's wait termination. It does not
    472     /// cancel, revoke, abort, install or deliver any operation.
    473     pub fn with_wait_termination(mut self, termination: WaitTermination) -> Self {
    474         self.wait_termination = termination;
    475         self
    476     }
    477     /// Borrows explicit original-operation recovery requirements.
    478     pub fn recovery(&self) -> &[RecoveryRequirement] {
    479         &self.recovery
    480     }
    481     copied!(
    482         error,
    483         Option<Error>,
    484         error,
    485         "Fixed redacted execution cause, when known."
    486     );
    487 }
    488 impl<T> fmt::Debug for OperationReceipt<T> {
    489     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    490         f.write_str("OperationReceipt(<redacted>)")
    491     }
    492 }
    493 
    494 #[cfg(feature = "receipts")]
    495 impl<T> OperationReceipt<T> {
    496     /// Projects a structurally validated retained operation report. Only the concrete
    497     /// adapter's actual authenticated coherent query qualifies the facts. This
    498     /// conversion performs no I/O, issuance, installation or publication.
    499     fn project(
    500         snapshot: &radroots_storage::command::OperationSnapshot,
    501         kind: OperationKind,
    502         business_result: Option<T>,
    503     ) -> Self {
    504         use alloc::{vec, vec::Vec};
    505         let prepared = snapshot.prepared();
    506         let mut artifacts = Vec::with_capacity(snapshot.artifacts().len());
    507         for recipient in snapshot.artifacts() {
    508             let claim = recipient.claim();
    509             let obtained = recipient.obtained();
    510             let issuance = if obtained.is_some() {
    511                 Issuance::Obtained
    512             } else if claim.is_some() {
    513                 Issuance::Unknown
    514             } else if snapshot.bound_plan().is_some() {
    515                 Issuance::Pending
    516             } else {
    517                 Issuance::None
    518             };
    519             artifacts.push(ArtifactObservation {
    520                 role: match recipient.target() {
    521                     radroots_protocol::plan::SigningTarget::PublicEvent => {
    522                         ArtifactRole::PublicEvent
    523                     }
    524                     radroots_protocol::plan::SigningTarget::BusinessSeal(_) => {
    525                         ArtifactRole::BusinessSeal
    526                     }
    527                 },
    528                 recipient: recipient.target().recipient(),
    529                 expected_event: recipient.expected_event(),
    530                 issuance,
    531                 attempt: claim.map(|value| value.attempt_id()),
    532                 claim_transaction: claim.map(|value| value.transaction_id()),
    533                 intent_digest: claim.map(|value| *value.intent().digest()),
    534                 capture_transaction: obtained.map(|value| value.transaction_id()),
    535                 publication_transaction: snapshot
    536                     .publications()
    537                     .iter()
    538                     .map(|v| (v.evidence(), v.transaction_id()))
    539                     .chain(
    540                         snapshot
    541                             .public_publications()
    542                             .iter()
    543                             .map(|v| (v.evidence(), v.transaction_id())),
    544                     )
    545                     .find(|(e, _)| Some(*e) == obtained)
    546                     .map(|(_, tx)| tx),
    547                 obtained_digest: obtained.map(|value| *value.digest()),
    548                 observed_at: obtained.and_then(|value| value.observed_at_unix_ms()),
    549             });
    550         }
    551         let unknown = artifacts
    552             .iter()
    553             .any(|value| value.issuance == Issuance::Unknown);
    554         let install_pending = artifacts.iter().any(|value| {
    555             value.issuance == Issuance::Obtained && value.publication_transaction.is_none()
    556         });
    557         let issuance = if unknown {
    558             Issuance::Unknown
    559         } else if artifacts
    560             .iter()
    561             .all(|value| value.issuance == Issuance::Obtained)
    562         {
    563             Issuance::Obtained
    564         } else if snapshot.bound_plan().is_some() {
    565             Issuance::Pending
    566         } else {
    567             Issuance::None
    568         };
    569         let expired = !unknown
    570             && issuance != Issuance::Obtained
    571             && snapshot.observed_at() >= prepared.issuance_window().first_issue_not_after();
    572         let mut recovery = Vec::new();
    573         let observations = snapshot.delivery_observations();
    574         let attempts = snapshot.delivery_attempts();
    575         let publications = snapshot
    576             .publications()
    577             .iter()
    578             .copied()
    579             .map(radroots_storage::command::PublicationArtifact::Private)
    580             .chain(
    581                 snapshot
    582                     .public_publications()
    583                     .iter()
    584                     .copied()
    585                     .map(radroots_storage::command::PublicationArtifact::Public),
    586             )
    587             .collect::<Vec<_>>();
    588         let installed =
    589             snapshot.installation().is_some() || snapshot.listing_installation().is_some();
    590         let delivery_pending = publications
    591             .iter()
    592             .any(|work| snapshot.publication_accepted(*work) != Ok(true));
    593         let delivery_unknown = attempts.iter().any(|attempt| {
    594             attempt.intent().selected_targets().any(|target| {
    595                 !observations.iter().any(|value| {
    596                     value.work() == attempt.work()
    597                         && value.request_id() == attempt.intent().request_id()
    598                         && value.target_receipt().target() == target
    599                         && value.kind()
    600                             != radroots_storage::command::DeliveryObservationKind::Unknown
    601                 })
    602             })
    603         });
    604         let projected = observations
    605             .iter()
    606             .map(|value| {
    607                 use radroots_storage::command::DeliveryObservationKind as Kind;
    608                 DeliveryObservation {
    609                     event: value.event_id(),
    610                     recipient: value.work().evidence().target().recipient(),
    611                     target: value.target_receipt().target().uri().as_str().into(),
    612                     request: value.request_id().as_str().into(),
    613                     target_fingerprint: value
    614                         .target_receipt()
    615                         .target()
    616                         .fingerprint()
    617                         .as_str()
    618                         .into(),
    619                     ordinal: value.target_ordinal(),
    620                     observed_at: value.observed_at_unix_ms(),
    621                     outcome: match value.kind() {
    622                         Kind::Accepted => TargetObservation::Accepted,
    623                         Kind::Rejected => TargetObservation::Rejected,
    624                         Kind::TimedOut => TargetObservation::TimedOut,
    625                         Kind::Disconnected => TargetObservation::Disconnected,
    626                         Kind::Unknown => TargetObservation::Unknown,
    627                         Kind::NotAttempted => TargetObservation::NotAttempted,
    628                     },
    629                 }
    630             })
    631             .collect::<Vec<_>>();
    632         if unknown {
    633             recovery.push(RecoveryRequirement::ReconcileIssuance);
    634         }
    635         if install_pending {
    636             recovery.push(RecoveryRequirement::InstallObtainedEvidence);
    637         }
    638         if delivery_pending {
    639             recovery.push(RecoveryRequirement::ResumeDelivery);
    640         }
    641         if expired {
    642             recovery.push(RecoveryRequirement::ManualReconciliation);
    643         }
    644         if recovery.is_empty()
    645             && (!installed || issuance == Issuance::Pending || issuance == Issuance::None)
    646         {
    647             recovery.push(RecoveryRequirement::ContinueOriginalOperation);
    648         }
    649         Self {
    650             kind,
    651             context: prepared.request().command().context().clone(),
    652             command_digest: prepared.identity().command_digest(),
    653             admission: Admission::Confirmed,
    654             admission_transaction: prepared.transaction_id(),
    655             plan_transaction: snapshot.bound_plan().map(|value| value.transaction_id()),
    656             installation_transaction: snapshot
    657                 .installation()
    658                 .map(|value| value.transaction_id())
    659                 .or_else(|| snapshot.listing_installation().map(|v| v.transaction_id())),
    660             installed_at: snapshot
    661                 .installation()
    662                 .map(|value| value.installed_at())
    663                 .or_else(|| snapshot.listing_installation().map(|v| v.installed_at())),
    664             issuance_window: prepared.issuance_window(),
    665             authority_checkpoint: prepared.request().binding().input().checkpoint().clone(),
    666             operation_checkpoint: snapshot.checkpoint_digest(),
    667             conflicting_records: vec![].into_boxed_slice(),
    668             conflicting_sources: vec![].into_boxed_slice(),
    669             observed_at: snapshot.observed_at(),
    670             business_installation: if installed {
    671                 BusinessInstallation::Installed
    672             } else {
    673                 BusinessInstallation::NotInstalled
    674             },
    675             business_result,
    676             message_id: snapshot.message_id(),
    677             record_ids: vec![].into_boxed_slice(),
    678             artifacts: artifacts.into_boxed_slice(),
    679             issuance,
    680             delivery: if publications.is_empty() {
    681                 Delivery::NotStarted
    682             } else if delivery_unknown {
    683                 Delivery::Unknown
    684             } else if attempts.is_empty()
    685                 || publications
    686                     .iter()
    687                     .any(|work| !attempts.iter().any(|attempt| attempt.work() == *work))
    688             {
    689                 Delivery::Pending
    690             } else {
    691                 Delivery::Observed
    692             },
    693             delivery_observations: projected.into_boxed_slice(),
    694             delivery_attempts: attempts.to_vec().into_boxed_slice(),
    695             wait_termination: WaitTermination::Returned,
    696             recovery: recovery.into_boxed_slice(),
    697             error: if unknown {
    698                 Some(Error::retained_signing_unknown(
    699                     prepared.identity().operation_id(),
    700                 ))
    701             } else if expired {
    702                 Some(Error::retained_deadline_exceeded(
    703                     prepared.identity().operation_id(),
    704                 ))
    705             } else {
    706                 None
    707             },
    708         }
    709     }
    710 }
    711 
    712 #[cfg(feature = "receipts")]
    713 fn listing_value(
    714     snapshot: &radroots_storage::command::OperationSnapshot,
    715 ) -> Result<Option<radroots_domain::listing::Listing>, radroots_storage::command::OperationError> {
    716     use radroots_storage::command::OperationError;
    717     let Some(command) = snapshot.prepared().request().command().listing() else {
    718         return Err(OperationError::UnsupportedOperation);
    719     };
    720     let Some(installed) = snapshot.listing_installation() else {
    721         return Ok(None);
    722     };
    723     let bound = snapshot
    724         .bound_plan()
    725         .ok_or(OperationError::RecoveryRequired)?;
    726     let input = command.input();
    727     radroots_domain::listing::Listing::new(
    728         input.id(),
    729         installed.author(),
    730         installed.revision(),
    731         bound.plan().created_at(),
    732         input.published_at(),
    733         input.text().clone(),
    734         input.terms().clone(),
    735     )
    736     .map(Some)
    737     .map_err(|_| OperationError::RecoveryRequired)
    738 }
    739 #[cfg(feature = "receipts")]
    740 impl OperationReceipt<ChatMessage> {
    741     /// Projects only a structurally valid original private command. This checks
    742     /// report shape; actual authenticated storage remains the adapter's duty.
    743     pub fn try_from_snapshot(
    744         snapshot: &radroots_storage::command::OperationSnapshot,
    745     ) -> Result<Self, radroots_storage::command::OperationError> {
    746         snapshot.prepared().request().chat_command()?;
    747         Ok(Self::project(
    748             snapshot,
    749             OperationKind::Chat,
    750             snapshot.installed_message().cloned(),
    751         ))
    752     }
    753 }
    754 #[cfg(feature = "receipts")]
    755 impl OperationReceipt<radroots_domain::listing::Listing> {
    756     /// Projects actual original public result data without inventing a message,
    757     /// private participant, stock effect or current relay-head observation.
    758     pub fn try_from_snapshot(
    759         snapshot: &radroots_storage::command::OperationSnapshot,
    760     ) -> Result<Self, radroots_storage::command::OperationError> {
    761         Ok(Self::project(
    762             snapshot,
    763             OperationKind::Listing,
    764             listing_value(snapshot)?,
    765         ))
    766     }
    767 }
    768 #[cfg(feature = "receipts")]
    769 impl OperationStatus {
    770     /// Observes the actual supported command family, including before any
    771     /// installed value. This performs no authentication, issuance or dispatch.
    772     pub fn try_from_snapshot(
    773         snapshot: &radroots_storage::command::OperationSnapshot,
    774     ) -> Result<Self, radroots_storage::command::OperationError> {
    775         if snapshot.prepared().request().command().listing().is_some() {
    776             let value = listing_value(snapshot)?.map(|v| OperationValue::Listing(Box::new(v)));
    777             Ok(Self::project(snapshot, OperationKind::Listing, value))
    778         } else {
    779             snapshot.prepared().request().chat_command()?;
    780             let value = snapshot
    781                 .installed_message()
    782                 .cloned()
    783                 .map(|v| OperationValue::Chat(Box::new(v)));
    784             Ok(Self::project(snapshot, OperationKind::Chat, value))
    785         }
    786     }
    787 }