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(permissions): prevent false positive permission-lost events

Louis Beaumont954ffa893263
diff --git a/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx b/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx
index 1aaa8142e..0d3f306cc 100644
--- a/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx
@@ -26,9 +26,28 @@ export function usePermissionMonitor() {
// Don't show multiple times in quick succession
if (hasShownRef.current) return;
- hasShownRef.current = true;
- console.log("Permission lost detected:", { screen_recording, microphone });
+ console.log("Permission lost event received:", { screen_recording, microphone });
+
+ // Double-check permissions before showing modal to avoid false positives
+ // The backend already requires 3 consecutive failures, but let's verify once more
+ try {
+ const currentPerms = await commands.doPermissionsCheck(false);
+ const screenOk = currentPerms.screenRecording === "granted" || currentPerms.screenRecording === "notNeeded";
+ const micOk = currentPerms.microphone === "granted" || currentPerms.microphone === "notNeeded";
+
+ if (screenOk && micOk) {
+ console.log("Permission check passed on frontend verification, skipping modal");
+ return;
+ }
+
+ console.log("Permission loss confirmed:", { screenOk, micOk });
+ } catch (error) {
+ console.error("Failed to verify permissions:", error);
+ // Continue to show modal if we can't verify
+ }
+
+ hasShownRef.current = true;
// Track the event
posthog.capture("permission_lost", {
diff --git a/screenpipe-app-tauri/src-tauri/src/permissions.rs b/screenpipe-app-tauri/src-tauri/src/permissions.rs
index d868cbf51..2d0e23082 100644
--- a/screenpipe-app-tauri/src-tauri/src/permissions.rs
+++ b/screenpipe-app-tauri/src-tauri/src/permissions.rs
@@ -349,6 +349,13 @@ pub async fn start_permission_monitor(app: tauri::AppHandle) {
let mut last_mic_ok = true;
let mut last_accessibility_ok = true;
+ // Track consecutive failures to avoid false positives from transient TCC issues
+ // macOS preflight() can return false transiently even when permission is granted
+ let mut screen_fail_count = 0u32;
+ let mut mic_fail_count = 0u32;
+ let mut accessibility_fail_count = 0u32;
+ const REQUIRED_CONSECUTIVE_FAILURES: u32 = 3; // Require 3 consecutive failures (~90 seconds)
+
info!("permission monitor started");
loop {
@@ -359,15 +366,38 @@ pub async fn start_permission_monitor(app: tauri::AppHandle) {
let mic_ok = perms.microphone.permitted();
let accessibility_ok = perms.accessibility.permitted();
- // Check if any permission was lost (was OK, now not OK)
- let screen_lost = last_screen_ok && !screen_ok;
- let mic_lost = last_mic_ok && !mic_ok;
- let accessibility_lost = last_accessibility_ok && !accessibility_ok;
+ // Update consecutive failure counts
+ if screen_ok {
+ screen_fail_count = 0;
+ } else if last_screen_ok || screen_fail_count > 0 {
+ screen_fail_count += 1;
+ }
+
+ if mic_ok {
+ mic_fail_count = 0;
+ } else if last_mic_ok || mic_fail_count > 0 {
+ mic_fail_count += 1;
+ }
+
+ if accessibility_ok {
+ accessibility_fail_count = 0;
+ } else if last_accessibility_ok || accessibility_fail_count > 0 {
+ accessibility_fail_count += 1;
+ }
+
+ // Only trigger when we have REQUIRED_CONSECUTIVE_FAILURES in a row
+ // This prevents false positives from transient TCC database issues
+ let screen_confirmed_lost = screen_fail_count == REQUIRED_CONSECUTIVE_FAILURES;
+ let mic_confirmed_lost = mic_fail_count == REQUIRED_CONSECUTIVE_FAILURES;
+ let accessibility_confirmed_lost = accessibility_fail_count == REQUIRED_CONSECUTIVE_FAILURES;
- if screen_lost || mic_lost || accessibility_lost {
+ if screen_confirmed_lost || mic_confirmed_lost || accessibility_confirmed_lost {
warn!(
- "permission lost - screen: {} -> {}, mic: {} -> {}, accessibility: {} -> {}",
- last_screen_ok, screen_ok, last_mic_ok, mic_ok, last_accessibility_ok, accessibility_ok
+ "permission confirmed lost after {} consecutive failures - screen: {} (fails: {}), mic: {} (fails: {}), accessibility: {} (fails: {})",
+ REQUIRED_CONSECUTIVE_FAILURES,
+ screen_ok, screen_fail_count,
+ mic_ok, mic_fail_count,
+ accessibility_ok, accessibility_fail_count
);
// Emit event to frontend