Permit proven closed-control fresh sync and retry only precommit clock reads
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-16 22:29:45 +01:00
parent 2092596936
commit 052456f133
13 changed files with 1349 additions and 39 deletions
+114 -2
View File
@@ -168,6 +168,36 @@ struct Lease {
until: DateTime<Utc>,
fingerprint: String,
}
/// Proof of failure at the very first clock read, before BEGIN or any
/// durable helper mutation. Private construction prevents remote assertions.
#[derive(Debug)]
pub struct ApplyPrecommitClockError {
cause: anyhow::Error,
}
impl std::fmt::Display for ApplyPrecommitClockError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("HELPER_SYNC_PRECOMMIT_CLOCK")
}
}
impl std::error::Error for ApplyPrecommitClockError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(self.cause.as_ref())
}
}
/// Retry authority for this control call only, never for Execute. Trust/key,
/// generation, signature, binding and later storage failures are not eligible.
pub fn retryable_precommit_clock(error: &anyhow::Error) -> bool {
error
.downcast_ref::<ApplyPrecommitClockError>()
.is_some_and(|typed| {
typed.cause.chain().any(|e| {
matches!(
e.to_string().as_str(),
"TIME_STALE_RESPONSE" | "TIME_RUNTIME_NO_EVIDENCE" | "TIME_NATIVE_NO_EVIDENCE"
)
})
})
}
pub struct HelperSync<V = DefaultVerifier> {
binding: Binding,
verifier: V,
@@ -598,7 +628,9 @@ impl<V: Ed25519Verifier> HelperSync<V> {
let result = self.apply_inner(db, guard, response, raw_request, clock, boot);
if let Err(error) = &result {
self.lease = None;
persist_fault(db, error);
if error.downcast_ref::<ApplyPrecommitClockError>().is_none() {
persist_fault(db, error);
}
}
result
}
@@ -612,7 +644,9 @@ impl<V: Ed25519Verifier> HelperSync<V> {
boot: &impl BootSource,
) -> Result<Applied> {
guard.check(db)?;
let now = clock.now()?;
let now = clock
.now()
.map_err(|cause| ApplyPrecommitClockError { cause })?;
let capture = self
.capture
.as_ref()
@@ -2005,3 +2039,81 @@ pub(crate) fn nonstart221_memory_rows(
None,
)
}
/// Memory-only companion to the selected actual control regression. Verifies
/// the new retry type is possible only before durable writes, retaining the
/// exact capture and never creating a lease or retrying a signature failure.
#[doc(hidden)]
pub fn precommit_clock_contract(binding: Binding, snapshot: Snapshot) -> Result<()> {
struct Guard;
impl ExecutorLedgerGuard for Guard {
fn check(&self, _db: &Connection) -> Result<()> {
Ok(())
}
}
struct Time(DateTime<Utc>);
impl Clock for Time {
fn now(&self) -> Result<DateTime<Utc>> {
Ok(self.0)
}
}
struct Missing(&'static str);
impl Clock for Missing {
fn now(&self) -> Result<DateTime<Utc>> {
anyhow::bail!(self.0)
}
}
struct Boot(Uuid);
impl BootSource for Boot {
fn current_boot(&self) -> Result<Uuid> {
Ok(self.0)
}
}
let clock = Time(snapshot.captured_at);
let boot = Boot(snapshot.boot_id);
let raw = serde_json::to_vec(&snapshot)?;
let mut sync = HelperSync::with_verifier(binding, crate::crypto::DalekVerifier, &clock)?;
sync.capture = Some(Capture {
snapshot,
fingerprint: "unchanged".into(),
generation: 1,
});
let mut db = Connection::open_in_memory()?;
initialize(&db, &sync.binding)?;
let response = SignedResponse {
decision_bytes: vec![],
signature: vec![],
};
let before = db.total_changes();
for (code, eligible) in [
("TIME_STALE_RESPONSE", true),
("TIME_RUNTIME_GENERATION", false),
] {
let error = sync
.apply(&mut db, &Guard, &response, &[], &Missing(code), &boot)
.err()
.context("CONTROL_EXPECTED_CLOCK_OR_SIGNATURE_ERROR")?;
ensure!(
retryable_precommit_clock(&error) == eligible
&& db.total_changes() == before
&& serde_json::to_vec(
&sync
.capture
.as_ref()
.context("CONTROL_CAPTURE_LOST")?
.snapshot
)? == raw
&& sync.lease.is_none(),
"CONTROL_PRECOMMIT_CLOCK_CLASSIFICATION"
);
}
let error = sync
.apply(&mut db, &Guard, &response, &[], &clock, &boot)
.err()
.context("CONTROL_EXPECTED_CLOCK_OR_SIGNATURE_ERROR")?;
ensure!(
!retryable_precommit_clock(&error) && sync.lease.is_none(),
"CONTROL_SIGNATURE_ERROR_NOT_RETRYABLE"
);
Ok(())
}