From 6f06115b163865de7d92c116267077e6dfd6c36b Mon Sep 17 00:00:00 2001 From: todortodorovic <95745674+todortodorovic@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:11:27 +0200 Subject: [PATCH] fix(truapi): stop registering product statement allowances for background renewal The renewal ledger refuses every product grant by design (d956dda37), but the merge in 9b8b33999 kept the jam branch's tracking call in the SSO responder, so each product statement allocation logged a failed attempt to record a renewal target. Drop the call; product grants stay provisioned on demand. --- .../src/runtime/signing_host/sso_responder.rs | 14 ------- .../signing_host/tests/allowance_keys.rs | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/rust/crates/truapi/src/runtime/signing_host/sso_responder.rs b/rust/crates/truapi/src/runtime/signing_host/sso_responder.rs index e214c20a6a..6294c7fdb8 100644 --- a/rust/crates/truapi/src/runtime/signing_host/sso_responder.rs +++ b/rust/crates/truapi/src/runtime/signing_host/sso_responder.rs @@ -931,9 +931,6 @@ pub async fn allocate_statement_store_allowance( product_id: &str, policy: OnExistingAllowancePolicy, ) -> Result { - #[cfg(any(test, not(target_arch = "wasm32")))] - use super::allowance_renewal::{self, StatementRenewalTarget}; - signing_host.require_current_product_session(session, product_id)?; let entropy = signing_host.root_entropy()?; let allowance = @@ -958,17 +955,6 @@ pub async fn allocate_statement_store_allowance( policy, ) .await?; - #[cfg(any(test, not(target_arch = "wasm32")))] - if let Err(reason) = allowance_renewal::track( - signing_host, - vec![StatementRenewalTarget::ProductStatementAllowance { - product_id: product_id.to_string(), - }], - ) - .await - { - warn!(%product_id, %reason, "failed to record statement-store renewal target"); - } signing_host.require_current_product_session(session, product_id)?; Ok(StatementStoreAllocation { secret: allowance.secret.to_bytes().to_vec(), diff --git a/rust/crates/truapi/src/runtime/signing_host/tests/allowance_keys.rs b/rust/crates/truapi/src/runtime/signing_host/tests/allowance_keys.rs index 9142ca0c54..7b7df515ed 100644 --- a/rust/crates/truapi/src/runtime/signing_host/tests/allowance_keys.rs +++ b/rust/crates/truapi/src/runtime/signing_host/tests/allowance_keys.rs @@ -97,6 +97,23 @@ fn sent_rpc_count(platform: &StubPlatform) -> usize { platform.sent_rpc.lock().expect("rpc list mutex poisoned").len() } +/// The `WARN` events emitted while this is the thread's subscriber. +#[derive(Clone, Default)] +struct Warnings(Arc>>); + +impl tracing_subscriber::Layer for Warnings { + fn on_event(&self, event: &tracing::Event<'_>, _: tracing_subscriber::layer::Context<'_, S>) { + if *event.metadata().level() != tracing::Level::WARN { + return; + } + let mut fields = Vec::new(); + event.record(&mut |field: &tracing::field::Field, value: &dyn core::fmt::Debug| { + fields.push(format!("{field}={value:?}")) + }); + self.0.lock().expect("warnings mutex poisoned").push(fields.join(" ")); + } +} + fn secret_key() -> StatementStoreAllowanceKey { StatementStoreAllowanceKey::from_secret_bytes(SECRET.to_vec()).expect("64-byte secret") } @@ -145,6 +162,29 @@ fn a_second_proof_in_the_same_session_sends_nothing_to_the_chain() { ); } +/// Product allowances are provisioned on demand for an authorized request and +/// never renewed in the background, so issuing one must not ask the renewal +/// ledger to keep it. The ledger refuses every product grant, so the attempt +/// would only fail and log a warning on each allocation. +#[test] +fn issuing_an_allowance_does_not_register_it_for_background_renewal() { + use tracing_subscriber::layer::SubscriberExt as _; + + let signing_host = active_signing_host(chain_with_allocated_slot()); + let warnings = Warnings::default(); + + // With a single live dispatcher, tracing caches a callsite's interest from + // the first thread to reach it, which may be a parallel test without a + // subscriber. A second one makes it ask every live dispatcher instead. + let _second_dispatcher = tracing::Dispatch::new(tracing_subscriber::Registry::default()); + tracing::subscriber::with_default( + tracing_subscriber::Registry::default().with(warnings.clone()), + || allowance_key(&signing_host), + ); + + assert_eq!(*warnings.0.lock().expect("warnings mutex poisoned"), Vec::::new()); +} + #[test] fn a_new_period_looks_the_allowance_up_again() { let signing_host = active_signing_host(Arc::new(StubPlatform::default()));