From 86f1f59bd36d7d621bf41ec483af3d30b63195d4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 31 Aug 2026 17:39:20 +0000 Subject: [PATCH] feat(hotpath): fill runtime-core db/io coverage gaps Co-authored-by: Zack Jackson --- .../src/db/connection/facade.rs | 23 +++++++++++++++++++ .../src/db/connection/query_write.rs | 9 ++++++++ .../src/store/memory/crud/add.rs | 2 ++ .../src/store/memory/crud/commands.rs | 5 ++++ .../src/store/memory/crud/commit.rs | 8 +++++++ .../src/store/memory/crud/feedback.rs | 3 +++ .../src/store/memory/crud/lineage.rs | 6 +++++ .../src/store/memory/crud/project.rs | 3 +++ 8 files changed, 59 insertions(+) diff --git a/crates/tracedecay-runtime-core/src/db/connection/facade.rs b/crates/tracedecay-runtime-core/src/db/connection/facade.rs index a53805d25c..92e29092f6 100644 --- a/crates/tracedecay-runtime-core/src/db/connection/facade.rs +++ b/crates/tracedecay-runtime-core/src/db/connection/facade.rs @@ -47,6 +47,7 @@ impl DatabaseWriterConnection<'_> { } impl DatabaseEngineWriteConnection { + #[hotpath::measure(label = "runtime_core.db.write_conn.query")] pub async fn query

( &self, sql: &str, @@ -58,6 +59,7 @@ impl DatabaseEngineWriteConnection { self.conn.query(sql, params).await } + #[hotpath::measure(label = "runtime_core.db.write_conn.execute")] pub async fn execute

(&self, sql: &str, params: P) -> crate::db::engine::Result where P: crate::db::engine::IntoParams, @@ -65,10 +67,12 @@ impl DatabaseEngineWriteConnection { self.conn.execute(sql, params).await } + #[hotpath::measure(label = "runtime_core.db.write_conn.execute_batch")] pub async fn execute_batch(&self, sql: &str) -> crate::db::engine::Result<()> { self.conn.execute_batch(sql).await } + #[hotpath::measure(label = "runtime_core.db.write_conn.long_lease_begin")] pub(crate) async fn authorized_long_lease_transaction( &self, ) -> crate::db::engine::Result { @@ -109,6 +113,7 @@ impl crate::db::engine::Executor for DatabaseEngineWriteConnection { } impl DatabaseEngineReadConnection { + #[hotpath::measure(label = "runtime_core.db.read_conn.query")] pub async fn query

( &self, sql: &str, @@ -129,6 +134,7 @@ impl DatabaseEngineReadConnection { } } + #[hotpath::measure(label = "runtime_core.db.read_conn.snapshot_begin")] pub async fn read_snapshot(&self) -> crate::db::engine::Result { self.conn .read_snapshot() @@ -162,6 +168,7 @@ impl crate::db::engine::QueryExecutor for DatabaseEngineReadConnection { } impl DatabaseEngineReadSnapshot { + #[hotpath::measure(label = "runtime_core.db.snapshot.query")] pub async fn query

( &self, sql: &str, @@ -198,6 +205,7 @@ impl crate::db::engine::QueryExecutor for DatabaseEngineReadSnapshot { } impl DatabaseEngineLongLeaseTransaction { + #[hotpath::measure(label = "runtime_core.db.long_lease.batch")] pub(crate) async fn execute_authority_revalidated_batch( &self, sql: &str, @@ -207,10 +215,12 @@ impl DatabaseEngineLongLeaseTransaction { .await } + #[hotpath::measure(label = "runtime_core.db.long_lease.commit")] pub(crate) async fn commit(self) -> crate::db::engine::Result<()> { self.transaction.commit().await } + #[hotpath::measure(label = "runtime_core.db.long_lease.rollback")] pub(crate) async fn rollback(self) -> crate::db::engine::Result<()> { self.transaction.rollback().await } @@ -251,6 +261,7 @@ impl<'a> DatabaseMemoryTransaction<'a> { Self::Write(transaction) } + #[hotpath::measure(label = "runtime_core.db.memory_txn.query")] pub async fn query

( &self, sql: &str, @@ -265,6 +276,7 @@ impl<'a> DatabaseMemoryTransaction<'a> { } } + #[hotpath::measure(label = "runtime_core.db.memory_txn.execute")] pub async fn execute

(&self, sql: &str, params: P) -> crate::db::engine::Result where P: crate::db::engine::IntoParams, @@ -277,6 +289,7 @@ impl<'a> DatabaseMemoryTransaction<'a> { } } + #[hotpath::measure(label = "runtime_core.db.memory_txn.execute_batch")] pub async fn execute_batch(&self, sql: &str) -> crate::db::engine::Result<()> { match self { Self::Read(_) => Err(crate::db::engine::Error::Runtime( @@ -286,6 +299,7 @@ impl<'a> DatabaseMemoryTransaction<'a> { } } + #[hotpath::measure(label = "runtime_core.db.memory_txn.commit")] pub async fn commit(self) -> Result<()> { match self { Self::Read(snapshot) => { @@ -301,6 +315,7 @@ impl<'a> DatabaseMemoryTransaction<'a> { } } + #[hotpath::measure(label = "runtime_core.db.memory_txn.rollback")] pub async fn rollback(self) -> Result<()> { match self { Self::Read(snapshot) => { @@ -364,6 +379,7 @@ impl crate::db::engine::DatabaseAttachmentExecutor for DatabaseMemoryTransaction } impl DatabaseWriteTransaction<'_> { + #[hotpath::measure(label = "runtime_core.db.write_txn.execute")] pub async fn execute

(&self, sql: &str, params: P) -> crate::db::engine::Result where P: crate::db::engine::IntoParams, @@ -371,6 +387,7 @@ impl DatabaseWriteTransaction<'_> { self.transaction.execute(sql, params).await } + #[hotpath::measure(label = "runtime_core.db.write_txn.query")] pub async fn query

( &self, sql: &str, @@ -382,14 +399,17 @@ impl DatabaseWriteTransaction<'_> { self.transaction.query(sql, params).await } + #[hotpath::measure(label = "runtime_core.db.write_txn.execute_batch")] pub async fn execute_batch(&self, sql: &str) -> crate::db::engine::Result<()> { self.transaction.execute_batch(sql).await } + #[hotpath::measure(label = "runtime_core.db.write_txn.execute_batch")] pub async fn execute_batch_engine(&self, sql: &str) -> crate::db::engine::Result<()> { self.transaction.execute_batch(sql).await } + #[hotpath::measure(label = "runtime_core.db.write_txn.execute")] pub async fn execute_engine

(&self, sql: &str, params: P) -> crate::db::engine::Result where P: crate::db::engine::IntoParams, @@ -397,6 +417,7 @@ impl DatabaseWriteTransaction<'_> { self.transaction.execute(sql, params).await } + #[hotpath::measure(label = "runtime_core.db.write_txn.query")] pub async fn query_engine

( &self, sql: &str, @@ -408,6 +429,7 @@ impl DatabaseWriteTransaction<'_> { self.transaction.query(sql, params).await } + #[hotpath::measure(label = "runtime_core.db.write_txn.commit")] pub async fn commit(self) -> Result<()> { let Self { transaction, @@ -498,6 +520,7 @@ impl DatabaseWriteTransaction<'_> { }) } + #[hotpath::measure(label = "runtime_core.db.write_txn.rollback")] pub async fn rollback(self) -> Result<()> { let Self { transaction, diff --git a/crates/tracedecay-runtime-core/src/db/connection/query_write.rs b/crates/tracedecay-runtime-core/src/db/connection/query_write.rs index 25b2b863d7..86fc651d2c 100644 --- a/crates/tracedecay-runtime-core/src/db/connection/query_write.rs +++ b/crates/tracedecay-runtime-core/src/db/connection/query_write.rs @@ -7,6 +7,7 @@ use super::{ impl Database { /// Runs a bounded scalar inspection on the retained runtime, projecting the /// first column of the first row. + #[hotpath::measure(label = "runtime_core.db.query_scalar")] async fn query_scalar(&self, operation: &str, sql: &str, params: P) -> Result where T: crate::db::engine::FromValue, @@ -79,6 +80,7 @@ impl Database { self.execute_write_engine(operation, sql, params).await } + #[hotpath::measure(label = "runtime_core.db.execute_write")] pub async fn execute_write_engine

( &self, operation: &str, @@ -102,6 +104,7 @@ impl Database { /// Executes a SQL batch atomically through the canonical writer broker. #[doc(hidden)] + #[hotpath::measure(label = "runtime_core.db.execute_write_batch")] pub async fn execute_write_batch(&self, operation: &str, sql: &str) -> Result<()> { let transaction = self.begin_write_transaction(operation).await?; transaction @@ -120,6 +123,7 @@ impl Database { /// The retained client guard stays alive for the entire transaction, and /// the exact write authority is checked before writer admission and again /// continuously by the runtime's authority-revalidated batch execution. + #[hotpath::measure(label = "runtime_core.db.authority_batch")] pub async fn execute_authority_revalidated_batch( &self, operation: &str, @@ -165,6 +169,7 @@ impl Database { /// /// Writable handles opened for the same database share one `DatabaseInner`, /// so this guard coordinates MCP, dashboard, and automation mutations. + #[hotpath::measure(label = "runtime_core.db.writer.lane_wait")] pub async fn writer(&self) -> tokio::sync::MutexGuard<'_, ()> { self.inner.writer.lock().await } @@ -198,6 +203,7 @@ impl Database { /// Opens an isolated writer while holding the process-local writer lane. /// The handle cannot escape the guard, preventing raw DML from bypassing /// serialization or joining a transaction on the retained reader. + #[hotpath::measure(label = "runtime_core.db.writer.open")] pub async fn writer_connection(&self, operation: &str) -> Result> { let guard = self.writer().await; let conn = self.open_writer_connection_unguarded(operation).await?; @@ -210,6 +216,7 @@ impl Database { /// Starts a query-only snapshot on a separate connection that cannot join /// a transaction running on the retained writable connection. + #[hotpath::measure(label = "runtime_core.db.snapshot.begin")] pub(crate) async fn begin_isolated_read_snapshot( &self, operation: &str, @@ -247,6 +254,7 @@ impl Database { /// Starts an immediate transaction that owns the canonical writer lane. /// Dropping the returned capability rolls back before releasing the lane. + #[hotpath::measure(label = "runtime_core.db.write_txn.begin")] pub async fn begin_write_transaction( &self, operation: &str, @@ -274,6 +282,7 @@ impl Database { /// transaction lease while continuously making progress. The runtime's /// long-lease policy renews that lease only after successful commands; /// idle transactions, revoked authority, and shutdown still cancel it. + #[hotpath::measure(label = "runtime_core.db.write_txn.begin_bulk")] pub async fn begin_bulk_write_transaction( &self, operation: &str, diff --git a/crates/tracedecay-runtime-core/src/store/memory/crud/add.rs b/crates/tracedecay-runtime-core/src/store/memory/crud/add.rs index 21e62d48fc..31ea0adcdf 100644 --- a/crates/tracedecay-runtime-core/src/store/memory/crud/add.rs +++ b/crates/tracedecay-runtime-core/src/store/memory/crud/add.rs @@ -61,6 +61,7 @@ fn classification_similarity( Ok(project_memory_millionths(similarity)) } +#[hotpath::measure(label = "runtime_core.memory.add_candidates")] async fn candidates_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -136,6 +137,7 @@ async fn candidates_tx( Ok(candidates) } +#[hotpath::measure(label = "runtime_core.memory.add_classify")] pub(super) async fn classify_project_memory_add_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, diff --git a/crates/tracedecay-runtime-core/src/store/memory/crud/commands.rs b/crates/tracedecay-runtime-core/src/store/memory/crud/commands.rs index 1e3b3b3985..66024b6bef 100644 --- a/crates/tracedecay-runtime-core/src/store/memory/crud/commands.rs +++ b/crates/tracedecay-runtime-core/src/store/memory/crud/commands.rs @@ -50,6 +50,7 @@ pub(super) fn project_memory_feedback_delta(action: ProjectMemoryFactFeedbackAct } } +#[hotpath::measure(label = "runtime_core.memory.feedback_projection")] pub(super) async fn project_memory_update_feedback_projection_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -198,6 +199,7 @@ pub(super) fn commit_receipt_json(outcome: &'static str, receipt: &FactCommitRec }) } +#[hotpath::measure(label = "runtime_core.memory.commit_receipt")] pub(super) async fn project_memory_commit_receipt_from_operation_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -304,6 +306,7 @@ pub(in crate::store::memory) async fn load_mutable_project_memory_fact_tx( } } +#[hotpath::measure(label = "runtime_core.memory.replay_add")] async fn project_memory_replay_add_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -527,6 +530,7 @@ pub(in crate::store::memory) async fn add_project_memory_fact_tx( ProjectMemoryFactAddOutcomeV1::added(fact, canonical_receipt, replayed) } +#[hotpath::measure(label = "runtime_core.memory.replay_update")] async fn project_memory_replay_update_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -677,6 +681,7 @@ pub(in crate::store::memory) async fn update_project_memory_fact_tx( ) } +#[hotpath::measure(label = "runtime_core.memory.replay_remove")] async fn project_memory_replay_remove_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, diff --git a/crates/tracedecay-runtime-core/src/store/memory/crud/commit.rs b/crates/tracedecay-runtime-core/src/store/memory/crud/commit.rs index 6593445f74..b2d661b4e1 100644 --- a/crates/tracedecay-runtime-core/src/store/memory/crud/commit.rs +++ b/crates/tracedecay-runtime-core/src/store/memory/crud/commit.rs @@ -55,6 +55,7 @@ fn assertion_header_json(assertion: &FactAssertionV1) -> FactStoreResult ) } +#[hotpath::measure(label = "runtime_core.memory.commit_fact")] pub(super) async fn commit_fact_tx( transaction: &Transaction<'_>, batch: &FactWriteBatch, @@ -115,6 +116,7 @@ pub(super) async fn commit_fact_tx( }) } +#[hotpath::measure(label = "runtime_core.memory.last_event")] pub(super) async fn current_last_event( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -142,6 +144,7 @@ pub(super) async fn current_last_event( )?)?)) } +#[hotpath::measure(label = "runtime_core.memory.append_order_check")] async fn ensure_append_order( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -181,6 +184,7 @@ async fn ensure_append_order( Ok(()) } +#[hotpath::measure(label = "runtime_core.memory.replay_check")] async fn batch_is_exact_replay( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -211,6 +215,7 @@ async fn batch_is_exact_replay( Ok(true) } +#[hotpath::measure(label = "runtime_core.memory.collision_check")] async fn batch_identity_collision( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -302,6 +307,7 @@ async fn fact_identity_matches( /// probe binds, kept clear of `SQLite`'s default variable ceiling. const REFERENCED_ANCHOR_BATCH: usize = 500; +#[hotpath::measure(label = "runtime_core.memory.anchors_ensure")] async fn ensure_referenced_anchors( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -354,6 +360,7 @@ async fn ensure_referenced_anchors( Ok(()) } +#[hotpath::measure(label = "runtime_core.memory.anchor_upsert")] async fn insert_or_verify_anchor( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -472,6 +479,7 @@ pub(super) async fn anchor_matches( Ok(stored == expected) } +#[hotpath::measure(label = "runtime_core.memory.assertion_insert")] async fn insert_assertion( transaction: &Transaction<'_>, owner: &OwnerKey, diff --git a/crates/tracedecay-runtime-core/src/store/memory/crud/feedback.rs b/crates/tracedecay-runtime-core/src/store/memory/crud/feedback.rs index b2f6ce2dfc..db8cabe017 100644 --- a/crates/tracedecay-runtime-core/src/store/memory/crud/feedback.rs +++ b/crates/tracedecay-runtime-core/src/store/memory/crud/feedback.rs @@ -188,6 +188,7 @@ fn project_memory_feedback_action( } #[allow(clippy::too_many_arguments)] +#[hotpath::measure(label = "runtime_core.memory.feedback_history")] async fn project_memory_record_feedback_history_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -227,6 +228,7 @@ async fn project_memory_record_feedback_history_tx( Ok(()) } +#[hotpath::measure(label = "runtime_core.memory.replay_feedback")] async fn project_memory_replay_feedback_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1, @@ -484,6 +486,7 @@ pub(in crate::store::memory) async fn inspect_project_memory_fact_controlled_tx( inspect_project_memory_fact_inner_tx(transaction, target, Some(read_control)).await } +#[hotpath::measure(label = "runtime_core.memory.fact_inspect")] async fn inspect_project_memory_fact_inner_tx( transaction: &Transaction<'_>, target: &ProjectMemoryFactIdV1, diff --git a/crates/tracedecay-runtime-core/src/store/memory/crud/lineage.rs b/crates/tracedecay-runtime-core/src/store/memory/crud/lineage.rs index 2924146691..5fb0026d5a 100644 --- a/crates/tracedecay-runtime-core/src/store/memory/crud/lineage.rs +++ b/crates/tracedecay-runtime-core/src/store/memory/crud/lineage.rs @@ -16,6 +16,7 @@ use tracedecay_domain::{ use tracedecay_store::{ FactCommitOutcome, FactCommitReceipt, FactStoreError, FactStoreResult, FactWriteBatch, }; +#[hotpath::measure(label = "runtime_core.memory.purged_projection_check")] pub(super) async fn payload_is_purged_projection( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -55,6 +56,7 @@ pub(super) async fn payload_is_purged_projection( )) } +#[hotpath::measure(label = "runtime_core.memory.event_refs_ensure")] pub(super) async fn ensure_event_references( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -215,6 +217,7 @@ async fn owned_fact_exists( .await } +#[hotpath::measure(label = "runtime_core.memory.event_insert")] pub(super) async fn insert_event( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -348,6 +351,7 @@ impl Projection { } } +#[hotpath::measure(label = "runtime_core.memory.projection_publish")] pub(super) async fn publish_current_projection( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -473,6 +477,7 @@ pub(in crate::store::memory) async fn load_current_projection( })) } +#[hotpath::measure(label = "runtime_core.memory.receipt_outcome")] pub(super) async fn receipt_outcome( transaction: &Transaction<'_>, owner: &OwnerKey, @@ -508,6 +513,7 @@ pub(super) async fn receipt_outcome( }) } +#[hotpath::measure(label = "runtime_core.memory.fact_identity_ensure")] pub(super) async fn ensure_fact_identity( transaction: &Transaction<'_>, owner: &OwnerKey, diff --git a/crates/tracedecay-runtime-core/src/store/memory/crud/project.rs b/crates/tracedecay-runtime-core/src/store/memory/crud/project.rs index e47295e26d..febd721076 100644 --- a/crates/tracedecay-runtime-core/src/store/memory/crud/project.rs +++ b/crates/tracedecay-runtime-core/src/store/memory/crud/project.rs @@ -48,6 +48,7 @@ pub(in crate::store::memory) async fn list_project_memory_facts_controlled_tx( list_project_memory_facts_inner_tx(transaction, query, Some(read_control)).await } +#[hotpath::measure(label = "runtime_core.memory.project_list")] async fn list_project_memory_facts_inner_tx( transaction: &Transaction<'_>, query: &ProjectMemoryFactListQueryV1, @@ -254,6 +255,7 @@ pub(in crate::store::memory) async fn find_project_memory_fact_by_content_digest .await } +#[hotpath::measure(label = "runtime_core.memory.project_find_digest")] async fn find_project_memory_fact_by_content_digest_inner_tx( transaction: &Transaction<'_>, query: &ProjectMemoryFactContentDigestQueryV1, @@ -618,6 +620,7 @@ pub(in crate::store::memory) async fn commit_batch_tx( } } +#[hotpath::measure(label = "runtime_core.memory.active_fact_count")] pub(super) async fn active_fact_count_tx( transaction: &Transaction<'_>, owner: &FactOwnerV1,