commit 57659af2ca92fe08b27c15c37f7995cf214253b2
parent 4a79700fc420253090e3fb21315d8a5613015680
Author: triesap <tyson@radroots.org>
Date: Mon, 12 Oct 2026 01:40:11 +0000
service_sqlite: preserve initialization commit failures
- Prevent successful cleanup from hiding failed initialization commits or rollbacks.
- Retain cleanup attempts, identity checks, writer authority and existing schema/API boundaries.
- Verify real deferred foreign-key failure, original cause, failed-state cleanup and valid commits.
- Requalify the exact prior candidate with Rust 1.99.0 format, check, package tests, Clippy and architecture controls.
Diffstat:
3 files changed, 144 insertions(+), 3 deletions(-)
diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml
@@ -2,6 +2,34 @@ schema_version = 1
architecture_id = "radroots.crates.release.v1"
[[deviation]]
+id = "RCRV1-DEV-026"
+date = "2026-10-12"
+status = "closed"
+approval = "The user approved the full successor refactor and local verified checkpoints; this is prospective reevaluation of an earlier uncommitted candidate."
+affected_steps = ["010", "130"]
+spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#repository_policy"]
+source_evidence = [
+ "The actual service initializer returned success after a real deferred foreign-key commit failure, while no product, metadata or ledger tables were durably present.",
+ "Result::or combines commit or rollback errors with later successful hook removal and connection close, allowing cleanup to mask failure.",
+ "The earlier uncommitted candidate replaces these three combinations with Result::and and tests failed and valid deferred commits; its prior evidence does not authorize or qualify current adoption.",
+]
+replacement_action = "Reevaluate and qualify the contained initializer correction before further dependent SQLite orchestration: attempt every cleanup, preserve failure rather than false success, retain authority and pathname checks, and keep schema and public API contracts unchanged."
+verification = [
+ "Validate this standalone deviation and confirm exact baseline-source equality to the original actual reproduction without rewriting its history.",
+ "Revalidate the precise candidate hash and run real failed/valid deferred commits, retained SQLite cause, failed-state removal, authority release and successful durable product/metadata inspection.",
+ "Run fresh exact Rust 1.99.0 scoped format, all-target check, full package tests and warnings-as-errors Clippy, then stage only the verified coherent owner paths.",
+]
+unresolved_risk = "The exact earlier candidate is prospectively verified locally. Published consumer adoption and Linux/successor qualification remain separate and pending."
+normative_architecture_change = false
+adr_required = false
+closure_evidence = [
+ "Five exact committed source blobs still match the original actual false-success reproduction; its original authority and limited historical claim are preserved.",
+ "The unchanged candidate passed a fresh real failed/valid deferred-foreign-key regression, including SQLite cause 787, failed-file removal, authority release and valid metadata/product rows.",
+ "Exact Rust 1.99.0 scoped format, all-target check, full service-SQLite tests and all-target warnings-as-errors Clippy passed on local macOS arm64. The unit suite reports 255 passed and five ignored; integration/documentation checks passed and ignored process-entry cases remain unclaimed.",
+ "Every cleanup is attempted before combining results; Result::and preserves commit/rollback/cleanup failure. Schema, public APIs, dependencies and protected-state ownership are unchanged.",
+]
+
+[[deviation]]
id = "RCRV1-DEV-025"
date = "2026-10-12"
status = "closed"
diff --git a/crates/service_sqlite/README.md b/crates/service_sqlite/README.md
@@ -66,6 +66,12 @@ and bounded row count. Integrity diagnostics use a borrowed-byte cap over the
exact `PRAGMA integrity_check(1)` operation and never convert an unbounded
diagnostic to UTF-8.
+Initialization reports success only after its governed commit and cleanup
+succeed. Hook removal and connection close are attempted even when commit or
+rollback fails; successful cleanup cannot hide an earlier failure. A failed
+commit's SQLite cause survives successful cleanup and cannot grant initialized
+state or writer authority.
+
Cancelling a host transaction before the runner enables outer commit
quarantines its connection and leaves no authoritative transaction effect. A
service-operation error is returned only after rollback is confirmed; an
diff --git a/crates/service_sqlite/src/initialize.rs b/crates/service_sqlite/src/initialize.rs
@@ -1000,7 +1000,7 @@ mod supported {
authority.validate_for(paths)?;
let close = connection.close().await;
authority.validate_for(paths)?;
- if let Err(source) = rollback.or(remove).or(close) {
+ if let Err(source) = rollback.and(remove).and(close) {
return Err(initialization_error(InitializationCause::with_source(
InitializationFailureKind::SchemaInitializationFailed,
source,
@@ -1016,7 +1016,7 @@ mod supported {
let remove = gate.remove(&mut connection).await;
let close = connection.close().await;
authority.validate_for(paths)?;
- rollback.or(remove).or(close).map_err(|source| {
+ rollback.and(remove).and(close).map_err(|source| {
initialization_error(InitializationCause::with_source(
InitializationFailureKind::SchemaInitializationFailed,
source,
@@ -1039,7 +1039,7 @@ mod supported {
authority.validate_for(paths)?;
let closed = connection.close().await;
authority.validate_for(paths)?;
- committed.or(removed).or(closed).map_err(|source| {
+ committed.and(removed).and(closed).map_err(|source| {
initialization_error(InitializationCause::with_source(
InitializationFailureKind::SchemaInitializationFailed,
source,
@@ -1393,6 +1393,113 @@ mod supported {
}
#[tokio::test(flavor = "current_thread")]
+ async fn deferred_foreign_key_commit_failure_is_reported_without_initialized_state() {
+ use sqlx::{Connection, sqlite::SqliteConnectOptions};
+
+ const PARENT: &str = "CREATE TABLE initialization_parent (id INTEGER PRIMARY KEY)";
+ const CHILD: &str = "CREATE TABLE initialization_child (id INTEGER PRIMARY KEY, parent_id INTEGER NOT NULL REFERENCES initialization_parent(id) DEFERRABLE INITIALLY DEFERRED)";
+
+ for valid_parent in [false, true] {
+ let root = tempfile::tempdir().expect("root");
+ let paths = paths(root.path(), "deferred-commit");
+ prepare(&paths);
+ let metadata = metadata(&paths);
+ let objects = [
+ ("initialization_parent", PARENT),
+ ("initialization_child", CHILD),
+ ]
+ .into_iter()
+ .map(|(name, sql)| {
+ crate::SchemaObject::new(
+ crate::SchemaObjectKind::Table,
+ name,
+ name,
+ sql,
+ crate::SchemaObject::computed_digest(
+ crate::SchemaObjectKind::Table,
+ name,
+ name,
+ sql,
+ )
+ .expect("schema object digest"),
+ )
+ .expect("schema object")
+ })
+ .collect();
+ let result = initialize_database(
+ &paths,
+ OpenMode::Initialize,
+ &metadata,
+ &schema_catalog(objects),
+ move |initializer| {
+ Box::pin(async move {
+ sqlx::query(PARENT).execute(&mut *initializer).await?;
+ sqlx::query(CHILD).execute(&mut *initializer).await?;
+ if valid_parent {
+ sqlx::query("INSERT INTO initialization_parent(id) VALUES (1)")
+ .execute(&mut *initializer)
+ .await?;
+ }
+ sqlx::query(
+ "INSERT INTO initialization_child(id, parent_id) VALUES (1, 1)",
+ )
+ .execute(&mut *initializer)
+ .await?;
+ Ok::<(), sqlx::Error>(())
+ })
+ },
+ )
+ .await;
+ if valid_parent {
+ let mut authority = result.expect("valid deferred foreign key commits");
+ let mut connection = SqliteConnection::connect_with(
+ &SqliteConnectOptions::new()
+ .filename(paths.state_database())
+ .read_only(true)
+ .create_if_missing(false),
+ )
+ .await
+ .expect("inspect initialized state");
+ crate::metadata::verify_database_metadata(
+ &mut connection,
+ &metadata.identity(),
+ )
+ .await
+ .expect("metadata committed with product state");
+ assert_eq!(
+ sqlx::query_scalar::<_, i64>("SELECT COUNT(*) FROM initialization_child")
+ .fetch_one(&mut connection)
+ .await
+ .expect("committed child"),
+ 1
+ );
+ connection.close().await.expect("close inspection");
+ authority.release().expect("release initialized authority");
+ } else {
+ let error = result.expect_err("a failed commit cannot initialize state");
+ assert_eq!(error.kind(), ServiceSqliteErrorKind::Create);
+ let cause = error
+ .source()
+ .and_then(Error::source)
+ .and_then(|source| source.downcast_ref::<sqlx::Error>())
+ .expect("original SQLite commit error remains available");
+ assert_eq!(
+ cause
+ .as_database_error()
+ .and_then(|error| error.code())
+ .as_deref(),
+ Some("787")
+ );
+ assert!(!paths.state_database().exists());
+ let mut authority = WriterAuthority::acquire(&paths, OpenMode::Initialize)
+ .expect("failed initialization releases authority")
+ .expect("initialize authority");
+ authority.release().expect("release reacquired authority");
+ }
+ }
+ }
+
+ #[tokio::test(flavor = "current_thread")]
async fn transaction_control_and_attachments_are_rejected_before_sqlite_compilation() {
for scenario in ["commit", "rollback_begin", "attach_detach"] {
let root = tempfile::tempdir().expect("root");