Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Keep native cache startup bounded and suppress Turso debug logging (#6745)

Sean Ayed561e968b6f5
diff --git a/apps/web/tauri/src-tauri/README.md b/apps/web/tauri/src-tauri/README.md
index 5f7ebf1321..2f7dde9712 100644
--- a/apps/web/tauri/src-tauri/README.md
+++ b/apps/web/tauri/src-tauri/README.md
@@ -24,6 +24,14 @@ single `vite.config.ts`.
You can override the dev server host for devices/emulators by exporting
`TAURI_DEV_HOST` before running `cargo tauri …`.
+Default native logging keeps Turso at `warn`, including Debug builds: its
+per-record/page debug spans are expensive through iOS OS activity logging.
+Application and Tao debug logs remain enabled in Debug builds. An explicit
+`RUST_LOG` still overrides the defaults; opt into Turso debug logs only for a
+focused diagnostic, not startup/performance measurements. Persistent-cache startup
+and explicit integrity checks are described in the
+[cache guide](../../../../crates/client/README.md#startup-and-integrity-checks).
+
## iOS 27 scene lifecycle
Apps built with the iOS 27 SDK must use the scene lifecycle. Keep the
diff --git a/apps/web/tauri/src-tauri/src/lib.rs b/apps/web/tauri/src-tauri/src/lib.rs
index 1803e6f8e6..3336d07a3e 100644
--- a/apps/web/tauri/src-tauri/src/lib.rs
+++ b/apps/web/tauri/src-tauri/src/lib.rs
@@ -32,6 +32,7 @@ use tracing_subscriber::util::SubscriberInitExt;
use url::Url;
mod device;
+mod logging;
mod share_target;
mod staged_upload;
@@ -114,13 +115,8 @@ type Type = std::sync::OnceLock<
pub fn run() {
use tracing_subscriber::EnvFilter;
- let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
- if cfg!(debug_assertions) {
- "debug,tungstenite=info,tokio_tungstenite=info,reqwest=info,hyper=info,h2=info".into()
- } else {
- "info,tungstenite=info,tokio_tungstenite=info,reqwest=info".into()
- }
- });
+ let filter = EnvFilter::try_from_default_env()
+ .unwrap_or_else(|_| logging::default_filter(cfg!(debug_assertions)));
let fmt_layer = tracing_subscriber::fmt::layer()
.with_file(true)
diff --git a/apps/web/tauri/src-tauri/src/logging.rs b/apps/web/tauri/src-tauri/src/logging.rs
new file mode 100644
index 0000000000..4928d13c3e
--- /dev/null
+++ b/apps/web/tauri/src-tauri/src/logging.rs
@@ -0,0 +1,14 @@
+use tracing_subscriber::EnvFilter;
+
+const DEPENDENCY_FILTERS: &str =
+ "turso_core=warn,tungstenite=info,tokio_tungstenite=info,reqwest=info,hyper=info,h2=info";
+
+/// Keep per-row/page Turso spans out of the default native logging pipeline,
+/// especially iOS OS activity logging. An explicit RUST_LOG still takes priority.
+pub(super) fn default_filter(debug: bool) -> EnvFilter {
+ let level = if debug { "debug" } else { "info" };
+ EnvFilter::new(format!("{level},{DEPENDENCY_FILTERS}"))
+}
+
+#[cfg(test)]
+mod test;
diff --git a/apps/web/tauri/src-tauri/src/logging/test.rs b/apps/web/tauri/src-tauri/src/logging/test.rs
new file mode 100644
index 0000000000..5068d91f40
--- /dev/null
+++ b/apps/web/tauri/src-tauri/src/logging/test.rs
@@ -0,0 +1,41 @@
+use super::*;
+use tracing::Level;
+use tracing_subscriber::layer::SubscriberExt;
+
+#[test]
+fn defaults_suppress_turso_hot_path_logs_but_preserve_failures() {
+ for debug in [true, false] {
+ let subscriber = tracing_subscriber::registry().with(default_filter(debug));
+ tracing::subscriber::with_default(subscriber, || {
+ assert!(!tracing::enabled!(target: "turso_core::storage::btree", Level::TRACE));
+ assert!(!tracing::enabled!(target: "turso_core::storage::btree", Level::DEBUG));
+ assert!(!tracing::enabled!(target: "turso_core::storage::pager", Level::INFO));
+ assert!(tracing::enabled!(target: "turso_core::storage::pager", Level::WARN));
+ assert!(tracing::enabled!(target: "turso_core::storage::pager", Level::ERROR));
+ });
+ }
+}
+
+#[test]
+fn defaults_retain_app_debugging_and_dependency_filters() {
+ for debug in [true, false] {
+ let subscriber = tracing_subscriber::registry().with(default_filter(debug));
+ tracing::subscriber::with_default(subscriber, || {
+ assert_eq!(tracing::enabled!(target: "app_lib", Level::DEBUG), debug);
+ assert_eq!(tracing::enabled!(target: "tao", Level::DEBUG), debug);
+ assert!(tracing::enabled!(target: "app_lib", Level::INFO));
+ assert!(!tracing::enabled!(target: "app_lib", Level::TRACE));
+ assert!(!tracing::enabled!(target: "reqwest", Level::DEBUG));
+ assert!(tracing::enabled!(target: "reqwest", Level::INFO));
+ });
+ }
+}
+
+#[test]
+fn turso_debugging_can_be_explicitly_enabled() {
+ let filter = default_filter(true).add_directive("turso_core=debug".parse().unwrap());
+ tracing::subscriber::with_default(tracing_subscriber::registry().with(filter), || {
+ assert!(tracing::enabled!(target: "turso_core::storage::btree", Level::DEBUG));
+ assert!(!tracing::enabled!(target: "turso_core::storage::btree", Level::TRACE));
+ });
+}
diff --git a/crates/client/README.md b/crates/client/README.md
index 16088b7d1b..16d20787ab 100644
--- a/crates/client/README.md
+++ b/crates/client/README.md
@@ -18,6 +18,19 @@ pinned there): `apps/web/tauri/graphql_cache_plugin`, path-depending on
`cargo test -p graphql_cache_plugin` (on NixOS use the `tauri-linux` dev shell —
Tauri's Linux desktop stack needs its WebKitGTK/DBus system libraries).
+## Startup and integrity checks
+
+Normal opens validate schema, scope/version metadata, and pending mutation/optimistic
+state without running a full-file `PRAGMA quick_check`. Cached records retain their
+checked decoding and runtime corruption handling. This applies to both native
+Tauri and browser OPFS storage.
+
+`TursoStorage::check_integrity()` is an explicit, synchronous diagnostic for callers
+that need a full scan. Keep it off startup and foreground-read paths; it is not
+scheduled automatically in the background. Failures latch the existing storage
+health state without deleting records or pending mutations. Recovery/reset remains
+an explicit caller decision after closing the storage.
+
## Tests
Run from the repository root:
diff --git a/crates/client/cache-turso/src/storage.rs b/crates/client/cache-turso/src/storage.rs
index 77b47520fa..b6e3a006e2 100644
--- a/crates/client/cache-turso/src/storage.rs
+++ b/crates/client/cache-turso/src/storage.rs
@@ -564,7 +564,8 @@ impl TursoFileDatabase {
Ok(Self { path, turso_path })
}
- /// Opens and initializes or validates this database for `scope`.
+ /// Opens this database, validating compatibility and queued writes for `scope`.
+ /// Full-file integrity scans are explicit via [`TursoStorage::check_integrity`].
pub fn open(&self, scope: &str) -> Result<TursoStorage, TursoStorageError> {
let fresh = !self.path.exists();
let io: Arc<dyn IO> = Arc::new(PlatformIO::new().map_err(TursoStorageError::turso)?);
@@ -2816,7 +2817,8 @@ fn initialize(
return Ok(());
}
- validate_quick_check(connection)?;
+ // Reopening must not scan every cached record/page. Keep compatibility and
+ // pending-write validation here; full scans belong to explicit diagnostics.
validate_frozen_schema(connection)?;
let metadata = driver::query(
connection,
@@ -4225,23 +4227,6 @@ fn compatibility() -> TursoStorageError {
TursoStorageError::reset(PhysicalResetReason::Compatibility)
}
-fn validate_quick_check(connection: &Arc<Connection>) -> Result<(), TursoStorageError> {
- let rows = driver::query(connection, "PRAGMA quick_check", Vec::new())
- .map_err(TursoStorageError::initialization)?;
- validate_quick_check_rows(&rows)
-}
-
-fn validate_quick_check_rows(rows: &[Vec<Value>]) -> Result<(), TursoStorageError> {
- if rows.len() == 1
- && rows[0].len() == 1
- && required_text(&rows[0], 0).ok().as_deref() == Some("ok")
- {
- Ok(())
- } else {
- Err(TursoStorageError::reset(PhysicalResetReason::Integrity))
- }
-}
-
fn validate_queue_consistency(connection: &Arc<Connection>) -> Result<(), TursoStorageError> {
let queue = driver::query(connection, QUEUE_SELECT, Vec::new())
.map_err(TursoStorageError::initialization)?;
@@ -4794,6 +4779,7 @@ impl TursoStorage {
}
mod alternatives;
+mod integrity;
#[cfg(all(test, target_arch = "wasm32"))]
mod browser_test;
diff --git a/crates/client/cache-turso/src/storage/integrity.rs b/crates/client/cache-turso/src/storage/integrity.rs
new file mode 100644
index 0000000000..d476030755
--- /dev/null
+++ b/crates/client/cache-turso/src/storage/integrity.rs
@@ -0,0 +1,33 @@
+use super::{TursoStorage, driver, required_text};
+use crate::{PhysicalResetReason, TursoStorageError};
+use turso_core::Value;
+
+impl TursoStorage {
+ /// Explicitly scans the database with `PRAGMA quick_check`.
+ ///
+ /// This synchronous diagnostic visits all cached data and must stay off the
+ /// startup and foreground-read paths. Normal opens still validate schema,
+ /// scope/version metadata, and queued writes. This method never resets or
+ /// deletes storage; integrity failures latch the normal reset-required state.
+ pub fn check_integrity(&self) -> Result<(), TursoStorageError> {
+ self.require_healthy()?;
+ self.latch_result(
+ driver::query(&self.connection(), "PRAGMA quick_check", Vec::new())
+ .and_then(|rows| validate_quick_check_rows(&rows)),
+ )
+ }
+}
+
+fn validate_quick_check_rows(rows: &[Vec<Value>]) -> Result<(), TursoStorageError> {
+ if rows.len() == 1
+ && rows[0].len() == 1
+ && required_text(&rows[0], 0).ok().as_deref() == Some("ok")
+ {
+ Ok(())
+ } else {
+ Err(TursoStorageError::reset(PhysicalResetReason::Integrity))
+ }
+}
+
+#[cfg(test)]
+mod test;
diff --git a/crates/client/cache-turso/src/storage/integrity/test.rs b/crates/client/cache-turso/src/storage/integrity/test.rs
new file mode 100644
index 0000000000..07e1c5f486
--- /dev/null
+++ b/crates/client/cache-turso/src/storage/integrity/test.rs
@@ -0,0 +1,21 @@
+use super::*;
+use crate::storage::text;
+
+#[test]
+fn quick_check_requires_exactly_one_ok_text_row() {
+ assert!(validate_quick_check_rows(&[vec![text("ok")]]).is_ok());
+ for rows in [
+ Vec::new(),
+ vec![vec![text("corrupt")]],
+ vec![vec![text("ok")], vec![text("ok")]],
+ vec![vec![text("ok"), text("extra")]],
+ vec![vec![Value::from_i64(1)]],
+ ] {
+ assert_eq!(
+ validate_quick_check_rows(&rows)
+ .unwrap_err()
+ .physical_reset_reason(),
+ Some(PhysicalResetReason::Integrity)
+ );
+ }
+}
diff --git a/crates/client/cache-turso/src/storage/test.rs b/crates/client/cache-turso/src/storage/test.rs
index 82b602d924..79e447c188 100644
--- a/crates/client/cache-turso/src/storage/test.rs
+++ b/crates/client/cache-turso/src/storage/test.rs
@@ -1,6 +1,7 @@
use super::*;
mod predicate_cost;
+mod startup;
use cache_core::normalize::RecordUpdates;
use pollster::block_on;
use std::sync::atomic::{AtomicU8, Ordering};
@@ -478,9 +479,7 @@ fn fresh_schema_metadata_foreign_keys_quick_check_and_cascade_are_real() {
block_on(async {
let mut storage = TursoStorage::open_in_memory("schema-scope").unwrap();
assert_eq!(raw_scalar(&storage, "PRAGMA foreign_keys"), 1);
- let quick = driver::query(&storage.connection(), "PRAGMA quick_check", Vec::new()).unwrap();
- assert_eq!(quick.len(), 1);
- assert_eq!(required_text(&quick[0], 0).unwrap(), "ok");
+ storage.check_integrity().unwrap();
assert_eq!(raw_scalar(&storage, "SELECT COUNT(*) FROM meta"), 3);
let violation = driver::execute(
@@ -916,25 +915,6 @@ fn invalid_shadow_state_requests_reset_on_reopen() {
);
}
-#[test]
-fn quick_check_requires_exactly_one_ok_text_row() {
- assert!(validate_quick_check_rows(&[vec![text("ok")]]).is_ok());
- for rows in [
- Vec::new(),
- vec![vec![text("corrupt")]],
- vec![vec![text("ok")], vec![text("ok")]],
- vec![vec![text("ok"), text("extra")]],
- vec![vec![Value::from_i64(1)]],
- ] {
- assert_eq!(
- validate_quick_check_rows(&rows)
- .unwrap_err()
- .physical_reset_reason(),
- Some(PhysicalResetReason::Integrity)
- );
- }
-}
-
#[test]
fn every_metadata_mismatch_and_missing_schema_requests_physical_reset() {
block_on(async {
diff --git a/crates/client/cache-turso/src/storage/test/startup.rs b/crates/client/cache-turso/src/storage/test/startup.rs
new file mode 100644
index 0000000000..7daa09241a
--- /dev/null
+++ b/crates/client/cache-turso/src/storage/test/startup.rs
@@ -0,0 +1,65 @@
+use super::*;
+
+#[test]
+fn reopen_skips_full_integrity_scan_and_preserves_pending_writes() {
+ block_on(async {
+ let database = TursoMemoryDatabase::new("startup-without-full-scan.db");
+ let mut storage = database.open("scope").unwrap();
+ storage
+ .put_batch(vec![(key("Thing:1"), record("persisted"))])
+ .await
+ .unwrap();
+ storage.enqueue_mutation(queued("Pending")).await.unwrap();
+ let pending = storage.load_mutation_queue().await.unwrap();
+ storage.try_close().unwrap();
+
+ // Reopening must not execute quick_check. The existing driver fault
+ // stays armed until the explicitly requested diagnostic below.
+ driver::arm_reset_failure("PRAGMA quick_check");
+ let storage = database.open("scope").unwrap();
+ assert_eq!(
+ storage.get_batch(&[key("Thing:1")]).await.unwrap(),
+ vec![Some(record("persisted"))]
+ );
+ assert_eq!(storage.load_mutation_queue().await.unwrap(), pending);
+ expect_reset_reason(
+ storage.check_integrity(),
+ PhysicalResetReason::TransactionOutcomeUncertain,
+ );
+ expect_reset_reason(
+ storage.get_batch(&[key("Thing:1")]).await,
+ PhysicalResetReason::TransactionOutcomeUncertain,
+ );
+ assert_eq!(
+ storage.try_close().unwrap(),
+ TursoStorageCloseOutcome::ResetRequired(
+ PhysicalResetReason::TransactionOutcomeUncertain
+ )
+ );
+ });
+}
+
+#[test]
+fn explicit_integrity_check_preserves_records_and_pending_writes() {
+ block_on(async {
+ let mut storage = TursoStorage::open_in_memory("explicit-integrity").unwrap();
+ storage
+ .put_batch(vec![(key("Thing:1"), record("persisted"))])
+ .await
+ .unwrap();
+ storage.enqueue_mutation(queued("Pending")).await.unwrap();
+ let pending = storage.load_mutation_queue().await.unwrap();
+
+ storage.check_integrity().unwrap();
+
+ assert_eq!(
+ storage.get_batch(&[key("Thing:1")]).await.unwrap(),
+ vec![Some(record("persisted"))]
+ );
+ assert_eq!(storage.load_mutation_queue().await.unwrap(), pending);
+ assert_eq!(
+ storage.try_close().unwrap(),
+ TursoStorageCloseOutcome::Healthy
+ );
+ });
+}