commit 74b0163bc79d86b935755fdaa4b47d761f7dfa93
parent edfe5aa061a79b07433047743999ad75a6aa60f1
Author: triesap <tyson@radroots.org>
Date: Mon, 26 Oct 2026 04:54:31 +0000
execution: own shared stock acceptance admission tasks
- Capture original acceptance through the exact client-owned scope.
- Retain task inputs, permits and byte reservations through settlement.
- Preserve unknown admission and original identity after accepted task loss.
- Verify ownership, refusal, lifecycle, portability and source contracts.
Diffstat:
7 files changed, 382 insertions(+), 2 deletions(-)
diff --git a/contracts/api_baselines/radroots_execution.txt b/contracts/api_baselines/radroots_execution.txt
@@ -40,6 +40,7 @@ pub async fn radroots_execution::session::ClientSession<H>::correct_stock_pool(&
pub async fn radroots_execution::session::ClientSession<H>::create_stock_pool(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_execution::workspace::CommandContext, radroots_storage::inventory::InventoryCheckpointRef, radroots_protocol::command::stock::CreatePoolInput) -> radroots_execution::Result<radroots_storage::inventory::InventoryOutcome>
pub async fn radroots_execution::session::ClientSession<H>::inventory_operation(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::OperationId, core::option::Option<radroots_domain::identifier::CommandDigest>) -> radroots_execution::Result<core::option::Option<radroots_storage::inventory::InventoryReceipt>>
pub async fn radroots_execution::session::ClientSession<H>::map_stock_option(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_execution::workspace::CommandContext, radroots_storage::inventory::InventoryCheckpointRef, radroots_protocol::command::stock_mapping::MapOptionInput) -> radroots_execution::Result<radroots_storage::inventory::InventoryOutcome>
+pub async fn radroots_execution::session::ClientSession<H>::prepare_stock_acceptance(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_execution::workspace::CommandContext, radroots_storage::inventory::InventoryCheckpointRef, radroots_storage::workspace::seller_stock::source::StockSourceCheckpointRef, radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef, radroots_protocol::command::order_acceptance::AcceptOrderInput) -> radroots_execution::Result<radroots_storage::inventory::acceptance::StockAcceptanceOutcome>
pub async fn radroots_execution::session::ClientSession<H>::stock_option_mapping(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::stock::mapping::OptionMappingKey) -> radroots_execution::Result<core::option::Option<radroots_domain::stock::mapping::OptionPoolMapping>>
pub async fn radroots_execution::session::ClientSession<H>::stock_pool(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::PoolId) -> radroots_execution::Result<core::option::Option<radroots_domain::stock::PoolView>>
pub async fn radroots_execution::session::ClientSession<H>::stock_preparation_abort(&self, alloc::sync::Arc<dyn radroots_storage::inventory::InventoryStore>, &radroots_execution::workspace::WorkspaceSession, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::OperationId, radroots_domain::identifier::CommandDigest) -> radroots_execution::Result<core::option::Option<radroots_storage::inventory::abort::StockAbortReceipt>>
diff --git a/contracts/architecture/decisions/shared_sdk_refactor.v1.json b/contracts/architecture/decisions/shared_sdk_refactor.v1.json
@@ -796,6 +796,9 @@
},
"execution": {
"ordinary_inventory_owner": {
+ "owned_acceptance_method": "prepare_stock_acceptance",
+ "acceptance_is_preparation_only": true,
+ "lost_accepted_admission_is_unknown": true,
"execution": "radroots_execution.ClientSession",
"facade": "radroots.Client",
"selected_workspace_views_share_owner": true,
diff --git a/crates/execution/README.md b/crates/execution/README.md
@@ -154,3 +154,13 @@ each publication work item and across its independently selected retries,
without erasing another recipient's pending state or weakening the full policy.
These projections perform no transport or participant signer invocation and
never renew a scheduling lease.
+
+`ClientSession::prepare_stock_acceptance` captures the existing seller command
+from its exact client-owned scope and preserves the supplied independent stock,
+private-source and listing minima. The bounded target task retains captured
+inputs, proof, resource permit and byte reservation through store settlement
+after observer loss; close drains accepted work. Missing or refused task hosts
+execute no fallback. Loss of an accepted admission task preserves the original
+ID with unknown T0 and manual reconciliation. The result is preparation only;
+the concrete store still authenticates consent and actual atomic holds. This
+low-level method does not supply complete ordinary commerce orchestration.
diff --git a/crates/execution/src/session/client_inventory.rs b/crates/execution/src/session/client_inventory.rs
@@ -11,19 +11,61 @@ use radroots_domain::{
stock::{OptionMappingKey, OptionPoolMapping, PoolView},
};
use radroots_protocol::command::{
- CapturedInventoryCommand, CapturedOptionMapping, CapturedPoolCorrection, CapturedPoolCreation,
- CreatePoolInput, MapOptionInput, PoolCorrectionInput,
+ AcceptOrderInput, CapturedInventoryCommand, CapturedOptionMapping, CapturedOrderAcceptance,
+ CapturedPoolCorrection, CapturedPoolCreation, CreatePoolInput, MapOptionInput,
+ PoolCorrectionInput,
};
use radroots_storage::{
command::OperationError,
inventory::{
InventoryCheckpointRef, InventoryOutcome, InventoryReceipt, InventoryRequest,
InventoryStore, StockAbortOutcome, StockAbortReceipt, StockAbortRequest,
+ StockAcceptanceOutcome, StockAcceptanceRequest,
},
workspace::{AttachmentProof, WorkspaceBinding},
};
impl<H: SessionHost + 'static> ClientSession<H> {
+ /// Captures original acceptance and owns its T0 admission until settlement.
+ /// A preparation report claims no signature, installed agreement or delivery.
+ /// Concrete store authentication/consent and actual atomic effects remain
+ /// authoritative; supplied minima and command metadata grant nothing.
+ #[allow(clippy::too_many_arguments)]
+ pub async fn prepare_stock_acceptance(
+ &self,
+ store: Shared<dyn InventoryStore>,
+ scope: &WorkspaceSession,
+ context: CommandContext,
+ minimum: InventoryCheckpointRef,
+ sources: radroots_storage::workspace::seller_stock::StockSourceCheckpointRef,
+ listings: radroots_storage::workspace::seller_stock::StockListingCheckpointRef,
+ input: AcceptOrderInput,
+ ) -> crate::Result<StockAcceptanceOutcome> {
+ let operation = context.data().operation_id();
+ let proposed = OperationContext::proposed(Some(operation));
+ if !scope.owns_context(&context) {
+ return Err(Error::operation(OperationError::Unauthorized, proposed));
+ }
+ self.run_stock_with_loss(
+ scope,
+ proposed,
+ Error::admission_uncertain(operation),
+ move |binding, proof| {
+ // Capture only after reserving work and byte capacity, before
+ // submission. No store, signer or transport runs in capture.
+ let request = CapturedOrderAcceptance::new(context.data().clone(), input)
+ .map_err(|_| OperationError::InvalidCommand)
+ .and_then(|command| {
+ StockAcceptanceRequest::capture(
+ binding, minimum, sources, listings, &command,
+ )
+ });
+ Box::pin(async move { store.prepare_stock_acceptance(request?, proof).await })
+ },
+ )
+ .await
+ }
+
/// Captures pool creation from this client's own selected attachment.
/// Actual authority, conservation and commit remain the store's obligation.
pub async fn create_stock_pool(
diff --git a/crates/execution/tests/support/workspace_acceptance.rs b/crates/execution/tests/support/workspace_acceptance.rs
@@ -0,0 +1,283 @@
+//! Controlled accepted-task ownership, not native consent/stock qualification.
+use super::*;
+use radroots_domain::{ExpectedOrder, OrderId, RecordId, TermsDigest};
+use radroots_protocol::command::{AcceptOrderInput, AllocationSelection};
+use radroots_storage::workspace::seller_stock::{
+ StockListingCheckpointRef, StockSourceCheckpointRef,
+};
+
+fn selected_store() -> Shared<Store> {
+ let store = store();
+ *store.model.binding.lock().unwrap() = WorkspaceBinding::from_authenticated_host(
+ input(5),
+ radroots_storage::workspace::WorkspaceScope::SellerStockOwner,
+ ActorRef::new(key(), ActorRole::Seller, None, Some(input(5).grant_id())),
+ "device",
+ Sequence::new(1).unwrap(),
+ UnixSeconds::new(200).unwrap(),
+ UnixSeconds::new(100).unwrap(),
+ )
+ .unwrap();
+ store
+}
+fn context(scope: &WorkspaceSession) -> radroots_execution::workspace::CommandContext {
+ scope
+ .command_context(
+ operation(),
+ Some(ExpectedOrder::new(
+ OrderId::from_bytes([84; 32]),
+ None,
+ Sequence::new(0).unwrap(),
+ None,
+ input(5).checkpoint().clone(),
+ )),
+ None,
+ UnixSeconds::new(150).unwrap(),
+ )
+ .unwrap()
+}
+fn source(scope: &WorkspaceSession) -> StockSourceCheckpointRef {
+ StockSourceCheckpointRef::from_host_metadata(
+ scope.binding().input().authority(),
+ Sequence::new(2).unwrap(),
+ Some(CheckpointDigest::from_bytes([22; 32])),
+ )
+ .unwrap()
+}
+fn listing(scope: &WorkspaceSession) -> StockListingCheckpointRef {
+ StockListingCheckpointRef::from_host_metadata(
+ scope.binding().input().authority(),
+ Sequence::new(3).unwrap(),
+ Some(CheckpointDigest::from_bytes([33; 32])),
+ )
+ .unwrap()
+}
+fn acceptance() -> AcceptOrderInput {
+ AcceptOrderInput::new(
+ RecordId::from_bytes([85; 32]),
+ TermsDigest::from_bytes([86; 32]),
+ AllocationSelection::automatic(),
+ )
+}
+
+#[test]
+fn accepted_acceptance_keeps_inputs_budget_and_permit_after_observer_loss_until_settlement() {
+ block_on(async {
+ let store = selected_store();
+ let tasks = Shared::new(Tasks::default());
+ let client = ClientSession::new_with_task_host(
+ Host,
+ core::num::NonZeroU16::new(8).unwrap(),
+ tasks.clone(),
+ );
+ let scope = client
+ .attach_workspace(store.clone(), input(5), proof())
+ .await
+ .unwrap();
+ client.start().await.unwrap();
+ drop(client.prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance(),
+ ));
+ assert!(tasks.queued.lock().unwrap().is_empty());
+ let mut first = Box::pin(client.prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance(),
+ ));
+ let mut second = Box::pin(client.prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance(),
+ ));
+ assert!(futures::poll!(first.as_mut()).is_pending());
+ assert!(futures::poll!(second.as_mut()).is_pending());
+ assert_eq!(tasks.queued.lock().unwrap().len(), 2);
+ assert!(store.calls.lock().unwrap().is_empty());
+ assert_eq!(
+ client
+ .prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance()
+ )
+ .await
+ .unwrap_err()
+ .code(),
+ Code::CapabilityUnavailable
+ );
+ drop(first);
+ drop(second);
+ let mut close = Box::pin(client.close());
+ assert!(futures::poll!(close.as_mut()).is_pending());
+ let mut jobs = core::mem::take(&mut *tasks.queued.lock().unwrap());
+ store.waiting.store(true, Ordering::SeqCst);
+ assert!(futures::poll!(jobs[0].as_mut()).is_pending());
+ assert!(futures::poll!(close.as_mut()).is_pending());
+ store.waiting.store(false, Ordering::SeqCst);
+ store.waker.wake();
+ for task in jobs {
+ task.await;
+ }
+ let calls = store.calls.lock().unwrap().clone();
+ assert_eq!(calls.len(), 2);
+ assert_eq!(calls[0], calls[1]);
+ assert_eq!(calls[0].0, operation());
+ close.await.unwrap();
+ });
+}
+
+#[test]
+fn host_and_foreign_context_scope_or_closed_scope_refuse_without_dispatch() {
+ block_on(async {
+ let store = selected_store();
+ let tasks = Shared::new(Tasks::default());
+ let client = ClientSession::new_with_task_host(
+ Host,
+ core::num::NonZeroU16::new(8).unwrap(),
+ tasks.clone(),
+ );
+ let scope = client
+ .attach_workspace(store.clone(), input(5), proof())
+ .await
+ .unwrap();
+ let foreign = WorkspaceSession::attach(store.clone(), input(5), proof())
+ .await
+ .unwrap();
+ client.start().await.unwrap();
+ for (selected, captured) in [(&foreign, context(&foreign)), (&scope, context(&foreign))] {
+ assert_eq!(
+ client
+ .prepare_stock_acceptance(
+ store.clone(),
+ selected,
+ captured,
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance()
+ )
+ .await
+ .unwrap_err()
+ .code(),
+ Code::Unauthorized
+ );
+ }
+ tasks.refuse.store(true, Ordering::SeqCst);
+ assert_eq!(
+ client
+ .prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance()
+ )
+ .await
+ .unwrap_err()
+ .code(),
+ Code::CapabilityUnavailable
+ );
+ tasks.refuse.store(false, Ordering::SeqCst);
+ let captured = context(&scope);
+ scope.close();
+ assert_eq!(
+ client
+ .prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ captured,
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance()
+ )
+ .await
+ .unwrap_err()
+ .code(),
+ Code::CapabilityUnavailable
+ );
+ client.close().await.unwrap();
+ let no_host = ClientSession::new(Host, core::num::NonZeroU16::MIN);
+ let scope = no_host
+ .attach_workspace(store.clone(), input(5), proof())
+ .await
+ .unwrap();
+ no_host.start().await.unwrap();
+ assert_eq!(
+ no_host
+ .prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance()
+ )
+ .await
+ .unwrap_err()
+ .code(),
+ Code::CapabilityUnavailable
+ );
+ no_host.close().await.unwrap();
+ assert!(store.calls.lock().unwrap().is_empty());
+ assert!(tasks.queued.lock().unwrap().is_empty());
+ });
+}
+
+#[test]
+fn lost_accepted_acceptance_task_preserves_original_identity_and_unknown_admission() {
+ block_on(async {
+ let store = selected_store();
+ let tasks = Shared::new(Tasks::default());
+ let client =
+ ClientSession::new_with_task_host(Host, core::num::NonZeroU16::MIN, tasks.clone());
+ let scope = client
+ .attach_workspace(store.clone(), input(5), proof())
+ .await
+ .unwrap();
+ client.start().await.unwrap();
+ let mut observed = Box::pin(client.prepare_stock_acceptance(
+ store.clone(),
+ &scope,
+ context(&scope),
+ minimum(&scope),
+ source(&scope),
+ listing(&scope),
+ acceptance(),
+ ));
+ assert!(futures::poll!(observed.as_mut()).is_pending());
+ // Deliberately nonconforming host: silence cannot prove no T0 commit.
+ drop(tasks.queued.lock().unwrap().pop().unwrap());
+ let error = observed.await.unwrap_err();
+ assert_eq!(error.code(), Code::CommitUnknown);
+ assert_eq!(
+ error.context().admission(),
+ radroots_execution::Admission::Unknown
+ );
+ assert_eq!(error.context().operation_id(), Some(operation()));
+ assert_eq!(error.retry(), RetryClass::ManualReconciliation);
+ assert!(store.calls.lock().unwrap().is_empty());
+ client.close().await.unwrap();
+ });
+}
diff --git a/crates/execution/tests/support/workspace_inventory.rs b/crates/execution/tests/support/workspace_inventory.rs
@@ -2,6 +2,8 @@
use super::*;
use radroots_execution::{Code, RetryClass, session::tasks::TaskHost};
use radroots_storage::{command::OperationError, inventory::*};
+#[path = "workspace_acceptance.rs"]
+mod acceptance;
#[derive(Default)]
struct Tasks {
@@ -46,6 +48,35 @@ impl WorkspaceStore for Store {
}
}
impl InventoryStore for Store {
+ fn prepare_stock_acceptance(
+ &self,
+ request: StockAcceptanceRequest,
+ proof: AttachmentProof,
+ ) -> radroots_storage::event::BoxFuture<'_, Result<StockAcceptanceOutcome, OperationError>>
+ {
+ Box::pin(async move {
+ assert_eq!(proof.with_secret(|bytes| *bytes), [7; 32]);
+ assert_eq!(request.binding().input(), &input(5));
+ assert_eq!(request.minimum_checkpoint().revision().get(), 0);
+ assert_eq!(request.source_checkpoint().revision().get(), 2);
+ assert_eq!(request.listing_checkpoint().revision().get(), 3);
+ self.calls
+ .lock()
+ .unwrap()
+ .push((request.attempt().operation_id(), request.command().digest()));
+ poll_fn(|cx| {
+ self.waker.register(cx.waker());
+ if self.waiting.load(Ordering::SeqCst) {
+ Poll::Pending
+ } else {
+ Poll::Ready(())
+ }
+ })
+ .await;
+ // Port mechanics only; this reports no actual T0 or SQL effect.
+ Ok(StockAcceptanceOutcome::Unknown(request.attempt()))
+ })
+ }
fn abort_proven_unissued(
&self,
request: StockAbortRequest,
diff --git a/tools/xtask/src/architecture/decision_package.rs b/tools/xtask/src/architecture/decision_package.rs
@@ -409,6 +409,9 @@ struct Execution {
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct OrdinaryInventoryOwner {
+ owned_acceptance_method: String,
+ acceptance_is_preparation_only: bool,
+ lost_accepted_admission_is_unknown: bool,
execution: String,
facade: String,
selected_workspace_views_share_owner: bool,
@@ -1087,6 +1090,10 @@ fn validate_values(v: &Values, limits: &BTreeMap<String, u64>) -> Result<(), Str
fn validate_execution(e: &Execution, p: &Protocol, c: &Cutover) -> Result<(), String> {
require(
e.ordinary_inventory_owner.execution == "radroots_execution.ClientSession"
+ && e.ordinary_inventory_owner.owned_acceptance_method == "prepare_stock_acceptance"
+ && e.ordinary_inventory_owner.acceptance_is_preparation_only
+ && e.ordinary_inventory_owner
+ .lost_accepted_admission_is_unknown
&& e.ordinary_inventory_owner.facade == "radroots.Client"
&& e.ordinary_inventory_owner
.selected_workspace_views_share_owner
@@ -1443,6 +1450,9 @@ mod tests {
#[test]
fn ordinary_inventory_keeps_selected_owner_and_accepted_task_lifetime() {
for (field, bad) in [
+ ("owned_acceptance_method", json!("inline_fallback")),
+ ("acceptance_is_preparation_only", json!(false)),
+ ("lost_accepted_admission_is_unknown", json!(false)),
("execution", json!("application")),
("facade", json!("native_backend")),
("selected_workspace_views_share_owner", json!(false)),