Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(app): stop reporting self-healed DB quarantines as unresolved (#6888)

Ezra Ellettecb37a2f3424f
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/db_self_heal.rs b/apps/screenpipe-app-tauri/src-tauri/src/db_self_heal.rs
index 8338087c7..9c94b800c 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/db_self_heal.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/db_self_heal.rs
@@ -39,6 +39,29 @@ use tracing::{info, warn};
use crate::notifications::client;
use crate::notifications::store::NotificationPriority;
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub enum LaunchSelfHealOutcome {
+ RecordingResumed,
+ QuarantineUnresolved,
+ QuarantineResolvedStartupFailed,
+}
+
+pub async fn finish_launch_quarantine<Failure, Report, ReportFuture>(
+ outcome: LaunchSelfHealOutcome,
+ on_failure: Failure,
+ report: Report,
+) where
+ Failure: FnOnce(),
+ Report: FnOnce() -> ReportFuture,
+ ReportFuture: std::future::Future<Output = ()>,
+{
+ if outcome != LaunchSelfHealOutcome::QuarantineUnresolved {
+ return;
+ }
+ on_failure();
+ report().await;
+}
+
/// Why a launch-time quarantine was not self-healed. Recorded so the decision
/// is auditable in logs instead of looking like the check never ran.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -214,23 +237,30 @@ where
/// Full launch path: resolve the quarantine when it is safe to, then bring
/// recording back through the same entry point the health watchdog uses.
///
-/// Returns true when recording was resumed, so the caller can skip the
-/// recovery notification it would otherwise publish.
+/// Launch observed a durable marker, then `try_resolve_quarantine` skipped.
+/// A marker that vanished in between is a resolved quarantine, not an
+/// unresolved one, so startup continues; every other skip stays fail-closed.
+fn launch_outcome_after_skip(reason: SelfHealSkip) -> Option<LaunchSelfHealOutcome> {
+ if reason == SelfHealSkip::NotQuarantined {
+ return None;
+ }
+ info!(
+ reason = reason.as_str(),
+ "db self-heal: keeping the fail-closed launch path"
+ );
+ Some(LaunchSelfHealOutcome::QuarantineUnresolved)
+}
+
+/// Distinguishes an unresolved quarantine from a post-resolution startup
+/// failure, so the caller reports only durable quarantine failures.
pub async fn try_self_heal_at_launch(
app: AppHandle,
database_path: PathBuf,
notify_user: bool,
-) -> bool {
- match try_resolve_quarantine(&database_path).await {
- Ok(()) => {}
- Err(reason) => {
- if reason != SelfHealSkip::NotQuarantined {
- info!(
- reason = reason.as_str(),
- "db self-heal: keeping the fail-closed launch path"
- );
- }
- return false;
+) -> LaunchSelfHealOutcome {
+ if let Err(reason) = try_resolve_quarantine(&database_path).await {
+ if let Some(outcome) = launch_outcome_after_skip(reason) {
+ return outcome;
}
}
@@ -246,7 +276,7 @@ pub async fn try_self_heal_at_launch(
error = %error,
"db self-heal: quarantine cleared but the first start failed — leaving it to the watchdog"
);
- return false;
+ return LaunchSelfHealOutcome::QuarantineResolvedStartupFailed;
}
if notify_user {
@@ -258,7 +288,7 @@ pub async fn try_self_heal_at_launch(
NotificationPriority::Normal,
);
}
- true
+ LaunchSelfHealOutcome::RecordingResumed
}
#[cfg(test)]
@@ -306,6 +336,45 @@ mod tests {
}
}
+ #[test]
+ fn marker_removed_before_self_heal_does_not_report_quarantine() {
+ assert_eq!(
+ launch_outcome_after_skip(SelfHealSkip::NotQuarantined),
+ None
+ );
+ for reason in [
+ SelfHealSkip::AlreadyLatchedThisProcess,
+ SelfHealSkip::UnreadableMarker,
+ ] {
+ assert_eq!(
+ launch_outcome_after_skip(reason),
+ Some(LaunchSelfHealOutcome::QuarantineUnresolved)
+ );
+ }
+ }
+
+ #[tokio::test]
+ async fn launch_quarantine_reports_only_when_quarantine_remains() {
+ for (outcome, expected_failures) in [
+ (LaunchSelfHealOutcome::RecordingResumed, 0),
+ (LaunchSelfHealOutcome::QuarantineUnresolved, 1),
+ (LaunchSelfHealOutcome::QuarantineResolvedStartupFailed, 0),
+ ] {
+ let mut boot_errors = 0;
+ let mut recovery_reports = 0;
+
+ finish_launch_quarantine(
+ outcome,
+ || boot_errors += 1,
+ || async { recovery_reports += 1 },
+ )
+ .await;
+
+ assert_eq!(boot_errors, expected_failures);
+ assert_eq!(recovery_reports, expected_failures);
+ }
+ }
+
#[tokio::test]
async fn launch_path_refuses_every_unproven_io_error_code() {
// None; generic IOERR; READ, WRITE, FSYNC, TRUNCATE, DATA, and
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index e19c72cc9..d44b837e1 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -1861,9 +1861,6 @@ async fn main() {
if launch_db_quarantined {
// Preserve the cross-launch fail-closed boundary before any
// server, SQLite pool, watchdog, or capture thread is started.
- crate::health::set_boot_error(
- "database remains quarantined after a SQLite hard fault; run `screenpipe db recover` while screenpipe is closed",
- );
crate::health::set_recording_status(crate::health::RecordingStatus::Error);
}
@@ -2332,20 +2329,30 @@ async fn main() {
let recovery_app = app_handle.clone();
let automatic_recovery = headless_startup;
tauri::async_runtime::spawn(async move {
- if crate::db_self_heal::try_self_heal_at_launch(
+ let self_heal_outcome = crate::db_self_heal::try_self_heal_at_launch(
self_heal_app,
self_heal_db_path,
!automatic_recovery,
)
- .await
+ .await;
+ crate::db_self_heal::finish_launch_quarantine(
+ self_heal_outcome,
+ || {
+ crate::health::set_boot_error(
+ "database remains quarantined after a SQLite hard fault; run `screenpipe db recover` while screenpipe is closed",
+ );
+ },
+ || crate::db_relaunch::surface_quarantined_recovery_at_launch(
+ &launch_db_path,
+ !automatic_recovery,
+ ),
+ )
+ .await;
+ if self_heal_outcome
+ != crate::db_self_heal::LaunchSelfHealOutcome::QuarantineUnresolved
{
return;
}
- crate::db_relaunch::surface_quarantined_recovery_at_launch(
- &launch_db_path,
- !automatic_recovery,
- )
- .await;
if automatic_recovery {
let recovery = crate::db_recovery_notifications::
start_headless_quarantined_database_recovery(