commit a146bf147961815f8d196e840c51a87891bf862b parent 9930e19cd4f125ac9eac489fc9f129e0ad0854ae Author: triesap <tyson@radroots.org> Date: Sun, 18 Oct 2026 16:06:17 +0000 execution: admit ordinary retained inquiries - Execute inquiry admission and coherent reads through the configured journal - Enforce client-owned scopes and preserve original admission-stage outcomes - Retain native accepted work across observer loss and close before storage release - Verify native replay and isolation, port uncertainty, APIs and owning coverage Diffstat:
21 files changed, 1221 insertions(+), 18 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock @@ -3180,6 +3180,7 @@ dependencies = [ "radroots_protocol", "radroots_signing", "radroots_storage", + "radroots_transport", ] [[package]] diff --git a/contracts/api_baselines/radroots.txt b/contracts/api_baselines/radroots.txt @@ -23,7 +23,9 @@ impl radroots::client::Client pub async fn radroots::client::Client::attach(&self, radroots_storage::workspace::AttachmentInput, radroots_storage::workspace::AttachmentProof) -> radroots_execution::Result<radroots_execution::workspace::WorkspaceSession> pub async fn radroots::client::Client::attach_signer(&self, radroots_signing::provider::SignerHandle) -> radroots_execution::Result<radroots_execution::session::signer::SignerSession> pub async fn radroots::client::Client::close(&self) -> radroots_execution::Result<radroots::client::CloseReceipt> +pub const fn radroots::client::Client::inbox(&self) -> radroots::inbox::Inbox<'_> pub async fn radroots::client::Client::open(radroots::client::NativeConfig) -> radroots_execution::Result<Self> +pub fn radroots::client::Client::operations(&self, &radroots_execution::workspace::WorkspaceSession) -> radroots::operations::Operations<'_> pub fn radroots::client::Client::preview() -> Self pub fn radroots::client::Client::signer_session(&self) -> core::option::Option<radroots_execution::session::signer::SignerSession> pub async fn radroots::client::Client::start(&self, radroots::client::StartMode) -> radroots_execution::Result<radroots::client::SessionStatus> @@ -83,6 +85,12 @@ pub use radroots::identity::Profile pub use radroots::identity::PublicIdentity pub use radroots::identity::PublicKey pub use radroots::identity::Username +pub mod radroots::inbox +pub use radroots::inbox::InquireInput +pub use radroots::inbox::ListingRevisionRef +pub struct radroots::inbox::Inbox<'a> +impl<'a> radroots::inbox::Inbox<'a> +pub async fn radroots::inbox::Inbox<'a>::inquire(&self, radroots_execution::workspace::CommandContext, radroots_protocol::command::InquireInput) -> radroots_execution::Result<radroots_execution::receipt::OperationReceipt<radroots_domain::message::ChatMessage>> pub mod radroots::knowledge pub use radroots::knowledge::AddressableRef pub use radroots::knowledge::KnowledgeClaim @@ -114,6 +122,11 @@ pub use radroots::listing::PrepareError pub use radroots::listing::PrepareErrorKind pub use radroots::listing::PrepareRequest pub use radroots::listing::prepare +pub mod radroots::operations +pub struct radroots::operations::Operations<'a> +impl<'a> radroots::operations::Operations<'a> +pub async fn radroots::operations::Operations<'a>::get(&self, radroots_domain::identifier::OperationId) -> radroots_execution::Result<core::option::Option<radroots_execution::receipt::OperationReceipt<radroots_domain::message::ChatMessage>>> +pub async fn radroots::operations::Operations<'a>::get_matching(&self, radroots_domain::identifier::OperationId, core::option::Option<radroots_domain::identifier::CommandDigest>) -> radroots_execution::Result<core::option::Option<radroots_execution::receipt::OperationReceipt<radroots_domain::message::ChatMessage>>> pub mod radroots::signing pub use radroots::signing::ArtifactRole pub use radroots::signing::AuthorizationHeader @@ -191,7 +204,9 @@ impl radroots::client::Client pub async fn radroots::client::Client::attach(&self, radroots_storage::workspace::AttachmentInput, radroots_storage::workspace::AttachmentProof) -> radroots_execution::Result<radroots_execution::workspace::WorkspaceSession> pub async fn radroots::client::Client::attach_signer(&self, radroots_signing::provider::SignerHandle) -> radroots_execution::Result<radroots_execution::session::signer::SignerSession> pub async fn radroots::client::Client::close(&self) -> radroots_execution::Result<radroots::client::CloseReceipt> +pub const fn radroots::client::Client::inbox(&self) -> radroots::inbox::Inbox<'_> pub async fn radroots::client::Client::open(radroots::client::NativeConfig) -> radroots_execution::Result<Self> +pub fn radroots::client::Client::operations(&self, &radroots_execution::workspace::WorkspaceSession) -> radroots::operations::Operations<'_> pub fn radroots::client::Client::preview() -> Self pub fn radroots::client::Client::signer_session(&self) -> core::option::Option<radroots_execution::session::signer::SignerSession> pub async fn radroots::client::Client::start(&self, radroots::client::StartMode) -> radroots_execution::Result<radroots::client::SessionStatus> diff --git a/contracts/api_baselines/radroots_execution.txt b/contracts/api_baselines/radroots_execution.txt @@ -1,4 +1,7 @@ pub mod radroots_execution +pub mod radroots_execution::inbox +pub use radroots_execution::inbox::InquireInput +pub use radroots_execution::inbox::ListingRevisionRef pub mod radroots_execution::session pub enum radroots_execution::session::SessionState pub radroots_execution::session::SessionState::Closed @@ -15,6 +18,9 @@ pub fn radroots_execution::session::ClientSession<H>::new(H, core::num::nonzero: pub fn radroots_execution::session::ClientSession<H>::signer_session(&self) -> core::option::Option<radroots_execution::session::SignerSession> pub async fn radroots_execution::session::ClientSession<H>::start(&self) -> radroots_execution::Result<()> pub fn radroots_execution::session::ClientSession<H>::state(&self) -> radroots_execution::session::SessionState +impl<H: radroots_execution::session::SessionHost> radroots_execution::session::ClientSession<H> +pub async fn radroots_execution::session::ClientSession<H>::inquire(&self, alloc::sync::Arc<dyn radroots_storage::command::OperationJournal>, radroots_execution::workspace::CommandContext, radroots_protocol::command::InquireInput) -> radroots_execution::Result<radroots_execution::OperationReceipt<radroots_domain::message::ChatMessage>> +pub async fn radroots_execution::session::ClientSession<H>::operation(&self, alloc::sync::Arc<dyn radroots_storage::command::OperationJournal>, &radroots_execution::workspace::WorkspaceSession, radroots_domain::identifier::OperationId, core::option::Option<radroots_domain::identifier::CommandDigest>) -> radroots_execution::Result<core::option::Option<radroots_execution::OperationReceipt<radroots_domain::message::ChatMessage>>> impl<H: radroots_execution::session::SessionHost> core::clone::Clone for radroots_execution::session::ClientSession<H> pub fn radroots_execution::session::ClientSession<H>::clone(&self) -> Self pub struct radroots_execution::session::Session<H: radroots_execution::session::SessionHost> diff --git a/crates/execution/Cargo.toml b/crates/execution/Cargo.toml @@ -17,7 +17,7 @@ default = [] session = ["dep:futures"] signer_session = ["session", "dep:radroots_signing"] client_session = ["signer_session"] -workspace_session = ["client_session", "receipts"] +workspace_session = ["client_session", "receipts", "radroots_protocol/commands"] receipts = ["dep:radroots_storage", "radroots_storage/command_journal"] [dependencies] @@ -28,6 +28,7 @@ radroots_signing = { workspace = true, default-features = false, optional = true radroots_storage = { workspace = true, default-features = false, optional = true } [dev-dependencies] +radroots_transport = { workspace = true } futures = { workspace = true } radroots_event = { workspace = true, default-features = false } radroots_event_codec = { workspace = true, default-features = false } diff --git a/crates/execution/README.md b/crates/execution/README.md @@ -94,10 +94,20 @@ Closing the attachment invalidates its contexts. A custom adapter is an explicit host trust boundary and requires its own qualification; its observation cannot establish native SQL authority. An approval descriptor is not consent proof. -Package upload is not authorized. Ordinary durable command orchestration, outbox -workers, inventory authority, public listing/private chat execution, browser -attachment and new bindings remain separate requirements. Revalidating a context -is not durable admission; the authoritative transaction must recheck its scope. +`ClientSession::inquire` captures a validated inquiry from this client's own +authenticated context, calls the actual journal admission and queries its +coherent retained graph. It does not preempt original-operation lookup with a +fresh deadline check. Known failure, uncertain initial commit and a failure +after confirmed admission keep distinct original-ID dispositions. No signer or +network operation occurs in this T0 boundary. `operation` reads original progress +through an explicitly selected client-owned scope, independently of the old +first-issue deadline. The qualified concrete bounded worker owns accepted native +admission through observer loss; its close must drain accepted work. + +Package upload is not authorized. Owned signing/install/delivery continuation, +inventory authority, listing execution, browser attachment and new bindings +remain separate requirements. Revalidating a context is not durable admission; +the authoritative transaction must recheck its scope. `OperationReceipt<T>` owns the original captured scope, command and transaction diff --git a/crates/execution/src/error.rs b/crates/execution/src/error.rs @@ -192,6 +192,51 @@ pub struct Error { } impl Error { + #[cfg(feature = "workspace_session")] + pub(crate) const fn with_context(mut self, context: OperationContext) -> Self { + self.context = context; + self + } + + #[cfg(feature = "workspace_session")] + pub(crate) const fn admission_uncertain(operation: OperationId) -> Self { + Self { + code: Code::CommitUnknown, + context: OperationContext::admission_unknown(operation), + retry: RetryClass::ManualReconciliation, + detail: Some(Detail::new(crate::Field::Storage, crate::Reason::Unknown)), + } + } + + #[cfg(feature = "workspace_session")] + pub(crate) const fn operation( + error: radroots_storage::command::OperationError, + context: OperationContext, + ) -> Self { + use radroots_storage::command::OperationError as O; + let (code, retry) = match error { + O::Workspace(error) => { + return Self::workspace(error, context.operation_id()).with_context(context); + } + O::InvalidCommand => (Code::InvalidInput, RetryClass::Never), + O::InvalidEvidence => (Code::RecoveryRequired, RetryClass::ManualReconciliation), + O::Unauthorized | O::UnverifiedApproval => (Code::Unauthorized, RetryClass::Never), + O::MissingHistory => (Code::MissingHistory, RetryClass::AfterStateRefresh), + O::DeadlineExceeded => (Code::DeadlineExceeded, RetryClass::AfterStateRefresh), + O::IdempotencyConflict => (Code::IdempotencyConflict, RetryClass::Never), + O::StorageFailure => (Code::StorageFailure, RetryClass::Never), + O::RecoveryRequired | O::DeliveryAttemptLimit => { + (Code::RecoveryRequired, RetryClass::ManualReconciliation) + } + _ => (Code::RecoveryRequired, RetryClass::ManualReconciliation), + }; + Self { + code, + context, + retry, + detail: None, + } + } #[cfg(feature = "receipts")] pub(crate) const fn retained_deadline_exceeded(operation: OperationId) -> Self { Self { diff --git a/crates/execution/src/inbox.rs b/crates/execution/src/inbox.rs @@ -0,0 +1,2 @@ +//! Validated private inquiry inputs used by ordinary retained execution. +pub use radroots_protocol::command::{InquireInput, ListingRevisionRef}; diff --git a/crates/execution/src/lib.rs b/crates/execution/src/lib.rs @@ -21,6 +21,9 @@ pub mod session; #[cfg(feature = "workspace_session")] pub mod workspace; +#[cfg(feature = "workspace_session")] +pub mod inbox; + pub use diagnostic::{Detail, Field, Reason}; pub use error::{Admission, Code, Error, InvalidErrorContext, OperationContext, RetryClass}; diff --git a/crates/execution/src/receipt.rs b/crates/execution/src/receipt.rs @@ -3,10 +3,12 @@ use crate::{Admission, Error}; use alloc::boxed::Box; use core::{fmt, num::NonZeroU64}; +#[cfg(feature = "receipts")] +use radroots_domain::ChatMessage; use radroots_domain::{ - ChatMessage, CheckpointDigest, CheckpointRef, CommandContextData, CommandDigest, - EnvelopeEventId, IssuanceWindow, MessageId, PublicKey, RecordId, SigningAttemptId, SourceId, - TransactionId, UnixSeconds, + CheckpointDigest, CheckpointRef, CommandContextData, CommandDigest, EnvelopeEventId, + IssuanceWindow, MessageId, PublicKey, RecordId, SigningAttemptId, SourceId, TransactionId, + UnixSeconds, }; use radroots_protocol::intent::ArtifactRole; diff --git a/crates/execution/src/session/client.rs b/crates/execution/src/session/client.rs @@ -6,6 +6,10 @@ use std::{ sync::{Mutex, MutexGuard}, }; +#[cfg(feature = "workspace_session")] +#[path = "client_commands.rs"] +mod commands; + struct Resources<H> { host: H, signer: Shared<Mutex<Option<SignerSession>>>, diff --git a/crates/execution/src/session/client_commands.rs b/crates/execution/src/session/client_commands.rs @@ -0,0 +1,104 @@ +use super::{ClientSession, SessionHost, Shared}; +use crate::{ + Error, OperationContext, OperationReceipt, + workspace::{CommandContext, WorkspaceSession}, +}; +use radroots_domain::{ChatMessage, CommandDigest, OperationId}; +use radroots_protocol::command::{CapturedChatCommand, InquireInput}; +use radroots_storage::command::{ + AdmissionOutcome, AdmissionRequest, OperationError, OperationJournal, +}; + +impl<H: SessionHost> ClientSession<H> { + /// Captures and durably admits one inquiry through the configured journal. + /// The concrete bounded worker owns accepted T0 work after observer loss. + /// A pending receipt does not claim signing, installation or publication. + /// The journal is an explicit host trust boundary, not adapter qualification. + pub async fn inquire( + &self, + journal: Shared<dyn OperationJournal>, + context: CommandContext, + input: InquireInput, + ) -> crate::Result<OperationReceipt<ChatMessage>> { + let operation = context.data().operation_id(); + let proposed = OperationContext::proposed(Some(operation)); + let _permit = self + .session + .admit() + .map_err(|error| error.with_context(proposed))?; + { + let scopes = self + .workspaces + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !scopes.iter().any(|scope| scope.owns_context(&context)) { + return Err(Error::operation(OperationError::Unauthorized, proposed)); + } + } + let (binding, proof) = context + .captured_input() + .map_err(|error| Error::operation(error.into(), proposed))?; + let command = CapturedChatCommand::inquire(context.data().clone(), input) + .map_err(|_| Error::operation(OperationError::InvalidCommand, proposed))?; + let digest = command.digest(); + let request = AdmissionRequest::new(binding.clone(), command) + .map_err(|error| Error::operation(error, proposed))?; + // The actual admission checks the original identity before fresh + // deadline/planning; context.revalidate would reject retained replays. + let query_proof = proof + .with_secret(|secret| { + radroots_storage::workspace::AttachmentProof::from_protected_input(secret) + }) + .map_err(|error| Error::operation(error.into(), proposed))?; + let result = journal + .admit_command_and_hold(request, proof) + .await + .map_err(|error| Error::operation(error, proposed))?; + match result { + AdmissionOutcome::Unknown(_) => Err(Error::admission_uncertain(operation)), + AdmissionOutcome::Committed(_) => { + let retained = OperationContext::retained(operation); + let snapshot = journal + .operation_snapshot(binding, operation, Some(digest), query_proof) + .await + .map_err(|error| Error::operation(error, retained))? + .ok_or_else(|| Error::operation(OperationError::RecoveryRequired, retained))?; + Ok(OperationReceipt::from_snapshot(&snapshot)) + } + } + } + + /// Reads the original complete operation through a scope attached to this + /// client. Query time never renews the original first-issue deadline and + /// absence never proves an uncertain invocation was safely unissued. + pub async fn operation( + &self, + journal: Shared<dyn OperationJournal>, + scope: &WorkspaceSession, + operation: OperationId, + expected_digest: Option<CommandDigest>, + ) -> crate::Result<Option<OperationReceipt<ChatMessage>>> { + let proposed = OperationContext::proposed(Some(operation)); + let _permit = self + .session + .admit() + .map_err(|error| error.with_context(proposed))?; + { + let scopes = self + .workspaces + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !scopes.iter().any(|owned| owned.same_scope(scope)) { + return Err(Error::operation(OperationError::Unauthorized, proposed)); + } + } + let (binding, proof) = scope + .captured_input() + .map_err(|error| Error::operation(error.into(), proposed))?; + journal + .operation_snapshot(binding, operation, expected_digest, proof) + .await + .map(|snapshot| snapshot.as_ref().map(OperationReceipt::from_snapshot)) + .map_err(|error| Error::operation(error, proposed)) + } +} diff --git a/crates/execution/src/workspace.rs b/crates/execution/src/workspace.rs @@ -66,6 +66,31 @@ pub struct WorkspaceSession { attached: Shared<Attached>, } impl WorkspaceSession { + pub(crate) fn owns_context(&self, context: &CommandContext) -> bool { + Shared::ptr_eq(&self.attached, &context.attached) + } + pub(crate) fn same_scope(&self, other: &Self) -> bool { + Shared::ptr_eq(&self.attached, &other.attached) + } + pub(crate) fn captured_input( + &self, + ) -> Result<(WorkspaceBinding, AttachmentProof), WorkspaceError> { + if self.is_closed() { + return Err(WorkspaceError::Closed); + } + let proof = self + .attached + .proof + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .as_ref() + .ok_or(WorkspaceError::Closed)? + .with_secret(|secret| AttachmentProof::from_protected_input(secret))?; + if self.is_closed() { + return Err(WorkspaceError::Closed); + } + Ok((self.attached.binding.clone(), proof)) + } /// Authenticates the protected credential through a qualified host adapter. /// Supplying a custom adapter is an explicit host trust boundary; metadata /// returned by an unqualified adapter cannot qualify native SQL authority. @@ -182,6 +207,14 @@ pub struct CommandContext { attached: Shared<Attached>, } impl CommandContext { + pub(crate) fn captured_input( + &self, + ) -> Result<(WorkspaceBinding, AttachmentProof), WorkspaceError> { + WorkspaceSession { + attached: self.attached.clone(), + } + .captured_input() + } /// Borrows the exact captured descriptor without transferring authority. pub const fn data(&self) -> &CommandContextData { &self.data diff --git a/crates/execution/tests/support/workspace_commands.rs b/crates/execution/tests/support/workspace_commands.rs @@ -0,0 +1,450 @@ +// Port-model orchestration tests, not native persistence/authentication evidence. +use super::*; +use radroots_execution::inbox::InquireInput; +use radroots_execution::{Admission, Code, OperationContext, RetryClass}; +use radroots_storage::command::*; +type BoxFuture<'a, T> = radroots_storage::event::BoxFuture<'a, T>; + +type Stored = Option<(WorkspaceBinding, Vec<u8>)>; +struct Journal { + model: Shared<Model>, + trace: Mutex<Vec<&'static str>>, + stored: Mutex<Stored>, + uncertain: AtomicBool, + absent: AtomicBool, + admission_error: Mutex<Option<OperationError>>, + query_error: Mutex<Option<OperationError>>, +} +impl WorkspaceStore for Journal { + fn authenticate( + &self, + input: AttachmentInput, + proof: AttachmentProof, + ) -> BoxFuture<'_, Result<WorkspaceBinding, WorkspaceError>> { + self.model.authenticate(input, proof) + } + fn close_workspace(&self) -> BoxFuture<'_, Result<(), WorkspaceError>> { + Box::pin(async { Ok(()) }) + } +} +fn prepared(request: AdmissionRequest) -> PreparedOperation { + PreparedOperation::from_committed_store( + request, + TransactionId::from_bytes([21; 32]), + Sequence::new(1).unwrap(), + IssuanceWindow::new( + UnixSeconds::new(100).unwrap(), + UnixSeconds::new(150).unwrap(), + ) + .unwrap(), + ) + .unwrap() +} +fn journal() -> Shared<Journal> { + Shared::new(Journal { + model: new_model(), + trace: Mutex::new(Vec::new()), + stored: Mutex::new(None), + uncertain: AtomicBool::new(false), + absent: AtomicBool::new(false), + admission_error: Mutex::new(None), + query_error: Mutex::new(None), + }) +} +fn context(scope: &WorkspaceSession) -> radroots_execution::workspace::CommandContext { + scope + .command_context( + OperationId::from_bytes([22; 32]), + None, + None, + UnixSeconds::new(150).unwrap(), + ) + .unwrap() +} +fn inquiry() -> InquireInput { + InquireInput::new( + ThreadId::from_bytes([23; 32]), + key(), + None, + "private model text", + ) + .unwrap() +} +async fn attached(journal: &Shared<Journal>) -> (ClientSession<Host>, WorkspaceSession) { + let client = ClientSession::new(Host, core::num::NonZeroU16::MIN); + let scope = client + .attach_workspace(journal.clone(), input(5), proof()) + .await + .unwrap(); + client.start().await.unwrap(); + (client, scope) +} +impl OperationJournal for Journal { + fn record_delivery_observation( + &self, + _binding: WorkspaceBinding, + _proof: AttachmentProof, + _observation: DeliveryObservation, + ) -> BoxFuture<'_, Result<DeliveryObservationOutcome, OperationError>> { + panic!("unexpected journal effect") + } + fn delivery_observations( + &self, + _binding: WorkspaceBinding, + _operation: radroots_domain::OperationId, + _digest: radroots_domain::CommandDigest, + _recipient: radroots_domain::PublicKey, + _request: radroots_transport::sink::DeliveryRequestId, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Vec<DeliveryObservation>, OperationError>> { + panic!("unexpected journal effect") + } + fn prepare_delivery_attempt<'a>( + &'a self, + _request: DeliveryAttemptRequest, + _proof: AttachmentProof, + _candidate: Option<&'a EnvelopeCandidate>, + ) -> BoxFuture<'a, Result<DeliveryAttemptOutcome, OperationError>> { + panic!("unexpected journal effect") + } + fn delivery_attempt( + &self, + _binding: WorkspaceBinding, + _operation: OperationId, + _digest: CommandDigest, + _recipient: radroots_domain::PublicKey, + _request: radroots_transport::sink::DeliveryRequestId, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Option<DeliveryAttempt>, OperationError>> { + panic!("unexpected journal effect") + } + fn install_transition_and_outbox( + &self, + _request: InstallationRequest, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<InstallationOutcome, OperationError>> { + panic!("unexpected journal effect") + } + fn operation_snapshot( + &self, + _binding: WorkspaceBinding, + operation_id: OperationId, + expected_digest: Option<CommandDigest>, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Option<OperationSnapshot>, OperationError>> { + Box::pin(async move { + self.trace.lock().unwrap().push("query"); + if let Some(error) = *self.query_error.lock().unwrap() { + return Err(error); + } + if self.absent.load(Ordering::SeqCst) { + return Ok(None); + } + let retained = self.stored.lock().unwrap(); + let Some((binding, bytes)) = retained.as_ref() else { + return Ok(None); + }; + let request = AdmissionRequest::from_protected_wire(binding.clone(), bytes).unwrap(); + assert_eq!(operation_id, request.command().context().operation_id()); + assert!(expected_digest.is_none_or(|digest| digest == request.command().digest())); + let snapshot = OperationSnapshot::from_store_report( + RetainedOperation::Prepared(prepared(request)), + vec![RecipientSnapshot::from_store_report( + key(), + None, + None, + None, + )], + UnixSeconds::new(101).unwrap(), + ) + .unwrap(); + Ok(Some(snapshot)) + }) + } + fn claim_attempt( + &self, + _request: ClaimAttemptRequest, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<ClaimAttemptOutcome, OperationError>> { + panic!("unexpected journal effect") + } + fn signing_attempt( + &self, + _request: ClaimAttemptRequest, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Option<SigningAttempt>, OperationError>> { + panic!("unexpected journal effect") + } + fn capture_evidence<'a>( + &'a self, + _input: radroots_storage::workspace::AttachmentInput, + _proof: &'a AttachmentProof, + _evidence: &'a SealEvidence, + ) -> BoxFuture<'a, Result<EvidenceCaptureOutcome, OperationError>> { + panic!("unexpected journal effect") + } + fn obtained_evidence( + &self, + _request: ClaimAttemptRequest, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Option<CapturedSeal>, OperationError>> { + panic!("unexpected journal effect") + } + fn bind_signing_intents( + &self, + _binding: WorkspaceBinding, + _plan: ChatSigningPlan, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<PlanBindingOutcome, OperationError>> { + panic!("unexpected journal effect") + } + fn signing_plan( + &self, + _binding: WorkspaceBinding, + _operation_id: OperationId, + _expected_digest: CommandDigest, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Option<BoundSigningPlan>, OperationError>> { + panic!("unexpected journal effect") + } + fn admit_command_and_hold( + &self, + request: AdmissionRequest, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<AdmissionOutcome, OperationError>> { + Box::pin(async move { + self.trace.lock().unwrap().push("admit"); + let operation = request.command().context().operation_id(); + let digest = request.command().digest(); + if self.uncertain.load(Ordering::SeqCst) { + return Ok(AdmissionOutcome::Unknown(CommitAttempt::new( + request.binding().input().workspace_id(), + operation, + digest, + None, + ))); + } + if let Some(error) = *self.admission_error.lock().unwrap() { + return Err(error); + } + *self.stored.lock().unwrap() = Some(( + request.binding().clone(), + request.command().protected_wire().to_vec(), + )); + Ok(AdmissionOutcome::Committed(prepared(request))) + }) + } + fn operation( + &self, + _binding: WorkspaceBinding, + _operation_id: OperationId, + _expected_digest: Option<CommandDigest>, + _proof: AttachmentProof, + ) -> BoxFuture<'_, Result<Option<PreparedOperation>, OperationError>> { + panic!("unexpected journal effect") + } +} + +#[test] +fn only_confirmed_admission_reaches_query_and_unknown_preserves_original_id() { + block_on(async { + let journal = journal(); + let (client, scope) = attached(&journal).await; + journal.uncertain.store(true, Ordering::SeqCst); + let error = client + .inquire(journal.clone(), context(&scope), inquiry()) + .await + .unwrap_err(); + assert_eq!(error.code(), Code::CommitUnknown); + assert_eq!( + error.context(), + OperationContext::admission_unknown(OperationId::from_bytes([22; 32])) + ); + assert_eq!(error.retry(), RetryClass::ManualReconciliation); + assert_eq!(*journal.trace.lock().unwrap(), vec!["admit"]); + journal.uncertain.store(false, Ordering::SeqCst); + journal.trace.lock().unwrap().clear(); + let receipt = client + .inquire(journal.clone(), context(&scope), inquiry()) + .await + .unwrap(); + assert!(receipt.durable()); + assert!(receipt.business_result().is_none()); + assert_eq!(*journal.trace.lock().unwrap(), vec!["admit", "query"]); + journal.trace.lock().unwrap().clear(); + let queried = client + .operation( + journal.clone(), + &scope, + OperationId::from_bytes([22; 32]), + Some(receipt.command_digest()), + ) + .await + .unwrap() + .unwrap(); + assert_eq!( + queried.operation_checkpoint(), + receipt.operation_checkpoint() + ); + assert_eq!(*journal.trace.lock().unwrap(), vec!["query"]); + journal.absent.store(true, Ordering::SeqCst); + assert!( + client + .operation( + journal.clone(), + &scope, + OperationId::from_bytes([22; 32]), + None + ) + .await + .unwrap() + .is_none() + ); + let error = client + .inquire(journal.clone(), context(&scope), inquiry()) + .await + .unwrap_err(); + assert_eq!(error.code(), Code::RecoveryRequired); + assert_eq!(error.context().admission(), Admission::Confirmed); + client.close().await.unwrap(); + }); +} + +#[test] +fn port_failures_preserve_the_actual_admission_stage_and_fixed_error_contract() { + block_on(async { + let journal = journal(); + let (client, scope) = attached(&journal).await; + for (port_error, code) in [ + (OperationError::InvalidCommand, Code::InvalidInput), + (OperationError::InvalidEvidence, Code::RecoveryRequired), + (OperationError::Unauthorized, Code::Unauthorized), + (OperationError::UnverifiedApproval, Code::Unauthorized), + (OperationError::MissingHistory, Code::MissingHistory), + (OperationError::DeadlineExceeded, Code::DeadlineExceeded), + ( + OperationError::IdempotencyConflict, + Code::IdempotencyConflict, + ), + (OperationError::StorageFailure, Code::StorageFailure), + (OperationError::RecoveryRequired, Code::RecoveryRequired), + (OperationError::DeliveryAttemptLimit, Code::RecoveryRequired), + ( + OperationError::Workspace(WorkspaceError::GrantRevoked), + Code::GrantRevoked, + ), + ] { + *journal.admission_error.lock().unwrap() = Some(port_error); + let error = client + .inquire(journal.clone(), context(&scope), inquiry()) + .await + .unwrap_err(); + assert_eq!(error.code(), code); + assert_eq!(error.context().admission(), Admission::NotAdmitted); + assert_eq!( + error.context().operation_id(), + Some(OperationId::from_bytes([22; 32])) + ); + *journal.admission_error.lock().unwrap() = None; + *journal.query_error.lock().unwrap() = Some(port_error); + let error = client + .inquire(journal.clone(), context(&scope), inquiry()) + .await + .unwrap_err(); + assert_eq!(error.code(), code); + assert_eq!(error.context().admission(), Admission::Confirmed); + assert!(!format!("{error:?}").contains("private model text")); + let error = client + .operation( + journal.clone(), + &scope, + OperationId::from_bytes([22; 32]), + None, + ) + .await + .unwrap_err(); + assert_eq!(error.code(), code); + *journal.query_error.lock().unwrap() = None; + } + client.close().await.unwrap(); + }); +} + +#[test] +fn closed_and_foreign_scopes_do_not_reach_journal_and_capacity_is_not_reopened() { + block_on(async { + let journal = journal(); + let (client, scope) = attached(&journal).await; + let other = WorkspaceSession::attach(journal.clone(), input(5), proof()) + .await + .unwrap(); + assert_eq!( + client + .inquire(journal.clone(), context(&other), inquiry()) + .await + .unwrap_err() + .code(), + Code::Unauthorized + ); + assert_eq!( + client + .operation( + journal.clone(), + &other, + OperationId::from_bytes([22; 32]), + None + ) + .await + .unwrap_err() + .code(), + Code::Unauthorized + ); + let captured = context(&scope); + scope.close(); + assert_eq!( + client + .inquire(journal.clone(), captured, inquiry()) + .await + .unwrap_err() + .code(), + Code::CapabilityUnavailable + ); + assert_eq!( + client + .operation( + journal.clone(), + &scope, + OperationId::from_bytes([22; 32]), + None + ) + .await + .unwrap_err() + .code(), + Code::CapabilityUnavailable + ); + assert!(journal.trace.lock().unwrap().is_empty()); + let captured = context(&other); + client.close().await.unwrap(); + assert_eq!( + client + .inquire(journal.clone(), captured, inquiry()) + .await + .unwrap_err() + .code(), + Code::CapabilityUnavailable + ); + assert_eq!( + client + .operation( + journal.clone(), + &other, + OperationId::from_bytes([22; 32]), + None + ) + .await + .unwrap_err() + .code(), + Code::CapabilityUnavailable + ); + }); +} diff --git a/crates/execution/tests/workspace.rs b/crates/execution/tests/workspace.rs @@ -376,3 +376,6 @@ fn close_invalidates_clones_and_an_already_pending_context_revalidation() { ); }) } + +#[path = "support/workspace_commands.rs"] +mod commands; diff --git a/crates/radroots/README.md b/crates/radroots/README.md @@ -31,8 +31,20 @@ Attachment verifies its persisted credential and exact selection before returnin `WorkspaceSession`. That session constructs opaque, immutable command contexts without I/O or a clock read; admission must recheck current rights and expiry. A context does not submit a command or prove -user consent; network pairing, seller authority, complete command receipts and -durable listing/chat operations remain separate implementation requirements. +user consent. After explicit start, `client.inbox().inquire(context, input)` +durably captures a known-kind inquiry through the actual protected journal. +The returned coherent receipt reports pending preparation without claiming a +signature, installed message or relay acceptance. `client.operations(&scope)` +selects an explicitly authenticated attachment for `get(operation_id)` and +matching-digest reads. Every call enforces this client's attachment ownership +and current persisted grant. An expired retained inquiry remains queryable and +replay uses its original transaction, command, correlation and issuance window; +new expired input and conflicting reuse are refused. + +The existing bounded native worker owns accepted admission after observer loss; +client close drains it before releasing storage. Unpolled calls do nothing. +Network pairing, seller authority, owned signing/install/delivery continuation, +listing execution and browser qualification remain separate requirements. `attach_signer` observes the concrete provider only after retaining its callback scope. The first successful key freezes and later drift invalidates that scope. @@ -90,5 +102,6 @@ coherent retained snapshot for this projection. Native T2 can install a bounded logical chat result and retain independent recipient publication work; its original installation time/transaction remain separate from later work and unknown issuance. `domain::ChatMessage` is the owned private business view. -Ordinary inbox job orchestration and exact wrapping/delivery remain required -before the complete native submission workflow is available. +The ordinary inquiry boundary admits and queries T0. Owned continuation through +exact signing, native T2, wrapping and delivery remains required before the +complete native submission workflow is available. diff --git a/crates/radroots/src/client.rs b/crates/radroots/src/client.rs @@ -74,7 +74,7 @@ impl CloseReceipt { #[cfg(feature = "native")] pub struct NativeConfig { options: radroots_storage_sqlite::OpenOptions, - workspace: Option<Shared<dyn radroots_storage::workspace::WorkspaceStore>>, + workspace: Option<Shared<dyn radroots_storage::command::OperationJournal>>, } #[cfg(feature = "native")] impl NativeConfig { @@ -98,9 +98,9 @@ impl NativeConfig { } } -struct StoreHost { +pub(crate) struct StoreHost { store: Shared<dyn Storage>, - workspace: Option<Shared<dyn radroots_storage::workspace::WorkspaceStore>>, + workspace: Option<Shared<dyn radroots_storage::command::OperationJournal>>, closed: Shared<Mutex<Option<CloseReceipt>>>, } impl SessionHost for StoreHost { @@ -141,16 +141,16 @@ impl SessionHost for StoreHost { /// signing qualification, a retained operation or firm stock capability. #[derive(Clone)] pub struct Client { - session: ClientSession<StoreHost>, + pub(crate) session: ClientSession<StoreHost>, store: Shared<dyn Storage>, - workspace: Option<Shared<dyn radroots_storage::workspace::WorkspaceStore>>, + workspace: Option<Shared<dyn radroots_storage::command::OperationJournal>>, closed: Shared<Mutex<Option<CloseReceipt>>>, } impl Client { #[cfg(any(feature = "client", feature = "native"))] fn from_store( store: Shared<dyn Storage>, - workspace: Option<Shared<dyn radroots_storage::workspace::WorkspaceStore>>, + workspace: Option<Shared<dyn radroots_storage::command::OperationJournal>>, ) -> Self { let closed = Shared::new(Mutex::new(None)); let session = ClientSession::new( @@ -195,6 +195,23 @@ impl Client { pub fn state(&self) -> SessionState { self.session.state() } + pub(crate) fn journal( + &self, + ) -> crate::Result<Shared<dyn radroots_storage::command::OperationJournal>> { + self.workspace.clone().ok_or(MISSING_WORKSPACE) + } + /// Accesses private inquiry execution. Access alone performs no work. + pub const fn inbox(&self) -> crate::inbox::Inbox<'_> { + crate::inbox::Inbox::new(self) + } + /// Selects an explicitly authenticated scope for original-operation reads. + /// Every query checks that this client owns the attachment and current grant. + pub fn operations( + &self, + scope: &radroots_execution::workspace::WorkspaceSession, + ) -> crate::operations::Operations<'_> { + crate::operations::Operations::new(self, scope.clone()) + } /// Enables the selected local resource host. No background runtime, /// transport, command writer or stock authority is implicitly constructed. pub async fn start(&self, mode: StartMode) -> crate::Result<SessionStatus> { diff --git a/crates/radroots/src/inbox.rs b/crates/radroots/src/inbox.rs @@ -0,0 +1,27 @@ +//! Private inquiry commands through the client's actual protected journal. +use crate::{Client, CommandContext, OperationReceipt, Result}; +use radroots_domain::ChatMessage; +pub use radroots_execution::inbox::{InquireInput, ListingRevisionRef}; + +/// Borrowed access to one client's inquiry execution boundary. +pub struct Inbox<'a> { + client: &'a Client, +} +impl<'a> Inbox<'a> { + pub(crate) const fn new(client: &'a Client) -> Self { + Self { client } + } + /// Durably admits an inquiry and returns its actual coherent receipt. + /// Pending state does not claim signing, installation or relay acceptance. + /// Dropping observation never rolls back an accepted native transaction. + pub async fn inquire( + &self, + context: CommandContext, + input: InquireInput, + ) -> Result<OperationReceipt<ChatMessage>> { + self.client + .session + .inquire(self.client.journal()?, context, input) + .await + } +} diff --git a/crates/radroots/src/lib.rs b/crates/radroots/src/lib.rs @@ -8,8 +8,10 @@ pub mod domain; pub mod event; pub mod farm; pub mod identity; +pub mod inbox; pub mod knowledge; pub mod listing; +pub mod operations; pub mod signing; pub mod storage; pub mod sync; diff --git a/crates/radroots/src/operations.rs b/crates/radroots/src/operations.rs @@ -0,0 +1,32 @@ +//! Current authenticated reads of original retained operations. +use crate::{Client, OperationId, OperationReceipt, Result, WorkspaceSession}; +use radroots_domain::{ChatMessage, CommandDigest}; + +/// Reads are scoped to one explicit client-owned authenticated attachment. +pub struct Operations<'a> { + client: &'a Client, + scope: WorkspaceSession, +} +impl<'a> Operations<'a> { + pub(crate) const fn new(client: &'a Client, scope: WorkspaceSession) -> Self { + Self { client, scope } + } + /// Reads current original progress. Absence is not safe-nonissuance proof. + pub async fn get( + &self, + operation: OperationId, + ) -> Result<Option<OperationReceipt<ChatMessage>>> { + self.get_matching(operation, None).await + } + /// Additionally requires the original semantic command commitment. + pub async fn get_matching( + &self, + operation: OperationId, + expected: Option<CommandDigest>, + ) -> Result<Option<OperationReceipt<ChatMessage>>> { + self.client + .session + .operation(self.client.journal()?, &self.scope, operation, expected) + .await + } +} diff --git a/crates/radroots/tests/receipts.rs b/crates/radroots/tests/receipts.rs @@ -3,6 +3,9 @@ #[path = "support/receipt_plans.rs"] mod plans; +#[path = "support/receipt_client.rs"] +mod ordinary; + use radroots_domain::{ CommandContextData, CommandDigest, CorrelationId, OperationId, PublicKey, UnixSeconds, }; diff --git a/crates/radroots/tests/support/receipt_client.rs b/crates/radroots/tests/support/receipt_client.rs @@ -0,0 +1,430 @@ +use super::*; +use radroots::{ + Client, CommandContext, NativeConfig, StartMode, WorkspaceSession, inbox::InquireInput, +}; +use radroots_domain::{ChatMessage, ThreadId}; +use radroots_execution::{ + Admission, BusinessInstallation, Code, Delivery, Issuance, OperationReceipt, + RecoveryRequirement, +}; +use radroots_storage::event::SourceGeneration; +use radroots_storage_sqlite::{OpenMode, OpenOptions, Paths}; + +struct Ordinary { + fixture: Fixture, + store: Arc<NativeWorkspace>, + client: Client, + scope: WorkspaceSession, + input: AttachmentInput, + proof: AttachmentProof, +} +impl Ordinary { + async fn new() -> Self { + let fixture = Fixture::new(); + let (store, input, proof, _) = fixture.create().await; + let cache = fixture.path.parent().unwrap().join("cache"); + std::fs::create_dir(&cache).unwrap(); + let options = OpenOptions::new(Paths::from_directory(cache).unwrap(), OpenMode::Create) + .with_source_generation(SourceGeneration::new([17; 32]).unwrap(), 1) + .unwrap(); + let client = + Client::open(NativeConfig::public_read(options).with_workspace(store.as_ref().clone())) + .await + .unwrap(); + let scope = client.attach(input.clone(), copy(&proof)).await.unwrap(); + Self { + fixture, + store, + client, + scope, + input, + proof, + } + } + fn context(&self, id: u8, correlation: &str) -> CommandContext { + self.scope + .command_context_with_correlation( + OperationId::from_bytes([id; 32]), + None, + None, + UnixSeconds::new(150).unwrap(), + Some(CorrelationId::new(correlation).unwrap()), + ) + .unwrap() + } + async fn inquire( + &self, + id: u8, + text: &str, + correlation: &str, + ) -> radroots::Result<OperationReceipt<ChatMessage>> { + self.client + .inbox() + .inquire(self.context(id, correlation), input(text)) + .await + } + async fn start(&self) { + self.client.start(StartMode::LocalOnly).await.unwrap(); + } +} +fn input(text: &str) -> InquireInput { + InquireInput::new(ThreadId::from_bytes([0x66; 32]), key(), None, text).unwrap() +} + +#[tokio::test] +async fn ordinary_inquiry_confirms_actual_t0_and_current_pending_receipt_without_signing() { + let ready = Ordinary::new().await; + let before = ready + .inquire(91, "private ordinary inquiry", "first") + .await + .unwrap_err(); + assert_eq!(before.code(), Code::CapabilityUnavailable); + assert_eq!( + before.context().operation_id(), + Some(OperationId::from_bytes([91; 32])) + ); + assert_eq!(before.context().admission(), Admission::NotAdmitted); + ready.start().await; + let receipt = ready + .inquire(91, "private ordinary inquiry", "first") + .await + .unwrap(); + assert!(receipt.durable()); + assert_eq!( + receipt.business_installation(), + BusinessInstallation::NotInstalled + ); + assert!(receipt.business_result().is_none()); + assert_eq!(receipt.issuance(), Issuance::None); + assert_eq!(receipt.delivery(), Delivery::NotStarted); + assert_eq!( + receipt.recovery(), + &[RecoveryRequirement::ContinueOriginalOperation] + ); + assert!(receipt.plan_transaction_id().is_none()); + assert!( + receipt + .artifacts() + .iter() + .all(|artifact| artifact.attempt_id().is_none()) + ); + assert!(!format!("{receipt:?}").contains("private ordinary")); + let queried = ready + .client + .operations(&ready.scope) + .get_matching( + OperationId::from_bytes([91; 32]), + Some(receipt.command_digest()), + ) + .await + .unwrap() + .unwrap(); + assert_eq!( + queried.admission_transaction_id(), + receipt.admission_transaction_id() + ); + assert_eq!( + queried.operation_checkpoint(), + receipt.operation_checkpoint() + ); + let actual = ready + .store + .operation_snapshot( + ready.scope.binding().clone(), + OperationId::from_bytes([91; 32]), + None, + copy(&ready.proof), + ) + .await + .unwrap() + .unwrap(); + assert_eq!( + actual.prepared().request().command().text(), + "private ordinary inquiry" + ); + assert!(actual.bound_plan().is_none()); + assert!(actual.delivery_attempts().is_empty()); + ready.client.close().await.unwrap(); +} + +#[tokio::test] +async fn ordinary_replay_preserves_original_correlation_and_window_after_deadline() { + let ready = Ordinary::new().await; + ready.start().await; + let receipt = ready + .inquire(92, "retained inquiry", "first") + .await + .unwrap(); + ready.fixture.clock.now.store(151, Ordering::SeqCst); + let replay = ready + .inquire(92, "retained inquiry", "replacement") + .await + .unwrap(); + assert_eq!( + replay.admission_transaction_id(), + receipt.admission_transaction_id() + ); + assert_eq!(replay.issuance_window(), receipt.issuance_window()); + assert_eq!(replay.context().correlation_id().unwrap().as_str(), "first"); + assert_eq!(replay.command_digest(), receipt.command_digest()); + assert_eq!( + replay.operation_checkpoint(), + receipt.operation_checkpoint() + ); + assert_eq!(replay.error().unwrap().code(), Code::DeadlineExceeded); + let conflict = ready + .inquire(92, "changed private text", "replacement") + .await + .unwrap_err(); + assert_eq!(conflict.code(), Code::IdempotencyConflict); + assert_eq!( + conflict.context().operation_id(), + Some(OperationId::from_bytes([92; 32])) + ); + let new = ready + .inquire(93, "new expired inquiry", "first") + .await + .unwrap_err(); + assert_eq!(new.code(), Code::DeadlineExceeded); + assert!( + ready + .client + .operations(&ready.scope) + .get(OperationId::from_bytes([93; 32])) + .await + .unwrap() + .is_none() + ); + let mismatch = ready + .client + .operations(&ready.scope) + .get_matching( + OperationId::from_bytes([92; 32]), + Some(CommandDigest::from_bytes([0x55; 32])), + ) + .await + .unwrap_err(); + assert_eq!(mismatch.code(), Code::IdempotencyConflict); + ready.client.close().await.unwrap(); +} + +#[tokio::test] +async fn ordinary_context_must_belong_to_this_client_and_remain_open_and_authorized() { + let ready = Ordinary::new().await; + ready.start().await; + let other_workspace = Ordinary::new().await; + other_workspace.start().await; + assert_eq!( + other_workspace + .client + .inbox() + .inquire(ready.context(94, "other journal"), input("private")) + .await + .unwrap_err() + .code(), + Code::Unauthorized + ); + assert!( + other_workspace + .client + .operations(&other_workspace.scope) + .get(OperationId::from_bytes([94; 32])) + .await + .unwrap() + .is_none() + ); + other_workspace.client.close().await.unwrap(); + let other = Client::preview(); + other.start(StartMode::LocalOnly).await.unwrap(); + assert_eq!( + other + .inbox() + .inquire(ready.context(94, "wrong client"), input("private")) + .await + .unwrap_err() + .code(), + Code::MissingAuthority + ); + // The same persisted credential in a separately attached scope must not + // bypass this client's attachment registry, even with the exact same store. + let foreign = + WorkspaceSession::attach(ready.store.clone(), ready.input.clone(), copy(&ready.proof)) + .await + .unwrap(); + let context = foreign + .command_context( + OperationId::from_bytes([94; 32]), + None, + None, + UnixSeconds::new(150).unwrap(), + ) + .unwrap(); + assert_eq!( + ready + .client + .inbox() + .inquire(context, input("private")) + .await + .unwrap_err() + .code(), + Code::Unauthorized + ); + assert_eq!( + ready + .client + .operations(&foreign) + .get(OperationId::from_bytes([94; 32])) + .await + .unwrap_err() + .code(), + Code::Unauthorized + ); + assert!( + ready + .client + .operations(&ready.scope) + .get(OperationId::from_bytes([94; 32])) + .await + .unwrap() + .is_none() + ); + let closed_context = ready.context(94, "closed"); + ready.scope.close(); + assert_eq!( + ready + .client + .inbox() + .inquire(closed_context, input("private")) + .await + .unwrap_err() + .code(), + Code::CapabilityUnavailable + ); + let scope = ready + .client + .attach(ready.input.clone(), copy(&ready.proof)) + .await + .unwrap(); + let context = scope + .command_context( + OperationId::from_bytes([94; 32]), + None, + None, + UnixSeconds::new(150).unwrap(), + ) + .unwrap(); + ready + .store + .revoke(ready.input.clone(), &ready.proof) + .await + .unwrap(); + assert_eq!( + ready + .client + .inbox() + .inquire(context, input("private")) + .await + .unwrap_err() + .code(), + Code::GrantRevoked + ); + assert_eq!( + ready + .client + .operations(&scope) + .get(OperationId::from_bytes([94; 32])) + .await + .unwrap_err() + .code(), + Code::GrantRevoked + ); + ready.client.close().await.unwrap(); + other.close().await.unwrap(); +} + +#[tokio::test] +async fn accepted_ordinary_inquiry_survives_observer_loss_and_client_close_drains_native_t0() { + use std::{ + future::Future, + task::{Context, Poll}, + }; + let ready = Ordinary::new().await; + ready.start().await; + let inbox = ready.client.inbox(); + let (pause, release) = ready.fixture.clock.arm(0); + let mut wait = Box::pin(inbox.inquire( + ready.context(95, "lost observer"), + input("retained after wait loss"), + )); + assert!(matches!( + wait.as_mut() + .poll(&mut Context::from_waker(futures::task::noop_waker_ref())), + Poll::Pending + )); + reached(pause).await; + drop(wait); + let mut close = Box::pin(ready.client.close()); + assert!(matches!( + close + .as_mut() + .poll(&mut Context::from_waker(futures::task::noop_waker_ref())), + Poll::Pending + )); + release.send(()).unwrap(); + close.await.unwrap(); + let reopened = ready.fixture.reopen(ready.input.clone()).await; + let current = reopened + .authenticate(ready.input.clone(), &ready.proof) + .await + .unwrap(); + let snapshot = reopened + .operation_snapshot( + current, + OperationId::from_bytes([95; 32]), + None, + copy(&ready.proof), + ) + .await + .unwrap() + .unwrap(); + assert_eq!( + snapshot.prepared().request().command().text(), + "retained after wait loss" + ); + assert!(snapshot.bound_plan().is_none()); + assert!(snapshot.publications().is_empty()); + reopened.close().await.unwrap(); +} + +#[tokio::test] +async fn unpolled_ordinary_inquiry_and_post_close_admission_have_no_effect() { + let ready = Ordinary::new().await; + ready.start().await; + let inbox = ready.client.inbox(); + drop(inbox.inquire(ready.context(96, "not polled"), input("not submitted"))); + assert!( + ready + .client + .operations(&ready.scope) + .get(OperationId::from_bytes([96; 32])) + .await + .unwrap() + .is_none() + ); + let context = ready.context(96, "after close"); + ready.client.close().await.unwrap(); + let error = inbox + .inquire(context, input("not submitted")) + .await + .unwrap_err(); + assert_eq!(error.code(), Code::CapabilityUnavailable); + assert_eq!(error.context().admission(), Admission::NotAdmitted); + assert!( + ready + .client + .operations(&ready.scope) + .get(OperationId::from_bytes([96; 32])) + .await + .is_err() + ); +}