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: Pi crash loop on Windows due to lru-cache ESM/CJS interop under Bun 1.3.7

Louis Beaumontde56176e57f7
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index 9cd2befcc..0f603f250 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -966,7 +966,12 @@ startDisplay: string;
/**
* Pre-formatted local time, e.g. "5:00 PM" — for display.
*/
-endDisplay: string; attendees: string[]; location: string | null; calendarName: string; isAllDay: boolean }
+endDisplay: string; attendees: string[]; location: string | null; calendarName: string; isAllDay: boolean;
+/**
+ * Source identifier: "native" for OS calendar, "ics" for ICS feeds.
+ * Used by meeting detector to merge events from multiple publishers.
+ */
+source?: string }
export type CalendarStatus = { available: boolean; authorized: boolean; authorizationStatus: string; calendarCount: number }
export type ChatGptOAuthStatus = { logged_in: boolean }
export type Credits = { amount: number }
@@ -1087,7 +1092,7 @@ chatAlwaysOnTop?: boolean;
* AppleScript detection for Chromium browsers.
*/
ignoreIncognitoWindows?: boolean }
-export type ShowRewindWindow = "Main" | { Settings: { page: string | null } } | { Search: { query: string | null } } | "Onboarding" | "Chat" | "PermissionRecovery"
+export type ShowRewindWindow = "Main" | { Home: { page: string | null } } | { Search: { query: string | null } } | "Onboarding" | "Chat" | "PermissionRecovery"
export type Suggestion = { text: string }
/**
* Sync configuration.
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index f65a7b455..401048262 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9172,7 +9172,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.2.88"
+version = "2.2.89"
dependencies = [
"anyhow",
"arboard",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/calendar.rs b/apps/screenpipe-app-tauri/src-tauri/src/calendar.rs
index 11b6f1d39..da7965073 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/calendar.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/calendar.rs
@@ -41,6 +41,14 @@ pub struct CalendarEventItem {
pub location: Option<String>,
pub calendar_name: String,
pub is_all_day: bool,
+ /// Source identifier: "native" for OS calendar, "ics" for ICS feeds.
+ /// Used by meeting detector to merge events from multiple publishers.
+ #[serde(default = "default_native_source")]
+ pub source: String,
+}
+
+fn default_native_source() -> String {
+ "native".to_string()
}
// ─── Commands ───────────────────────────────────────────────────────────────
@@ -345,6 +353,7 @@ fn calendar_event_to_item(
location: event.location,
calendar_name: event.calendar_name,
is_all_day: event.is_all_day,
+ source: "native".to_string(),
}
}
@@ -366,5 +375,6 @@ fn calendar_event_to_item_win(
location: event.location,
calendar_name: event.calendar_name,
is_all_day: event.is_all_day,
+ source: "native".to_string(),
}
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/ics_calendar.rs b/apps/screenpipe-app-tauri/src-tauri/src/ics_calendar.rs
index f2222a703..3d9540a03 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/ics_calendar.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/ics_calendar.rs
@@ -261,6 +261,7 @@ fn parse_ics_to_events(ics_text: &str, feed_name: &str) -> Vec<CalendarEventItem
location,
calendar_name: feed_name.to_string(),
is_all_day: all_day,
+ source: "ics".to_string(),
});
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
index 53b91f940..9b4e1ea0b 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
@@ -388,6 +388,51 @@ fn pi_local_install_dir() -> Option<PathBuf> {
dirs::home_dir().map(|h| h.join(".screenpipe").join("pi-agent"))
}
+/// Seed the pi-agent package.json with overrides to fix dependency resolution.
+/// `hosted-git-info` requires `lru-cache@^10`, but bun on Windows can hoist
+/// an ESM-only [email protected] that breaks CJS `require()`.
+/// Writing overrides before `bun add` ensures the correct version is used.
+fn seed_pi_package_json(install_dir: &std::path::Path) {
+ let pkg_path = install_dir.join("package.json");
+ // Only seed if package.json doesn't exist yet — don't overwrite user/bun changes
+ if pkg_path.exists() {
+ // If it exists, check if overrides are already present
+ if let Ok(contents) = std::fs::read_to_string(&pkg_path) {
+ if !contents.contains("overrides") {
+ // Merge overrides into existing package.json
+ if let Ok(mut pkg) = serde_json::from_str::<serde_json::Value>(&contents) {
+ pkg.as_object_mut().map(|obj| {
+ obj.insert(
+ "overrides".to_string(),
+ json!({
+ "hosted-git-info": {
+ "lru-cache": "^10.0.0"
+ }
+ }),
+ );
+ });
+ if let Ok(new_contents) = serde_json::to_string_pretty(&pkg) {
+ let _ = std::fs::write(&pkg_path, new_contents);
+ info!("Added lru-cache overrides to existing pi-agent package.json");
+ }
+ }
+ }
+ }
+ return;
+ }
+ let pkg_json = json!({
+ "overrides": {
+ "hosted-git-info": {
+ "lru-cache": "^10.0.0"
+ }
+ }
+ });
+ match std::fs::write(&pkg_path, serde_json::to_string_pretty(&pkg_json).unwrap_or_default()) {
+ Ok(_) => info!("Seeded pi-agent package.json with lru-cache overrides"),
+ Err(e) => warn!("Failed to seed pi-agent package.json: {}", e),
+ }
+}
+
/// Find the JS entrypoint for the locally-installed pi package.
fn find_local_pi_entrypoint() -> Option<String> {
let dir = pi_local_install_dir()?;
@@ -1485,6 +1530,9 @@ pub async fn pi_install(app: AppHandle) -> Result<(), String> {
let app_handle = app.clone();
std::thread::spawn(move || {
+ // Seed package.json with overrides to fix lru-cache resolution on Windows
+ seed_pi_package_json(&install_dir);
+
let mut cmd = std::process::Command::new(&bun);
cmd.current_dir(&install_dir)
.args(["add", PI_PACKAGE]);
@@ -1869,10 +1917,49 @@ fn ensure_bash_available() -> Option<String> {
/// Runs on a dedicated thread, never panics, never blocks the caller.
/// Sets `PI_INSTALL_DONE` when finished so `pi_start` can wait for it.
pub fn ensure_pi_installed_background() {
- // If Pi is already installed locally, mark done immediately.
- // We specifically check the local install (not global) to ensure we control the deps.
+ // If Pi is already installed locally, check if it needs the lru-cache fix.
if find_local_pi_entrypoint().is_some() {
- debug!("Pi already installed locally, skipping background install");
+ if let Some(install_dir) = pi_local_install_dir() {
+ let pkg_path = install_dir.join("package.json");
+ let needs_fix = pkg_path.exists()
+ && std::fs::read_to_string(&pkg_path)
+ .map(|c| !c.contains("overrides"))
+ .unwrap_or(false);
+ if needs_fix {
+ info!("Pi installed but missing lru-cache overrides — patching and reinstalling");
+ seed_pi_package_json(&install_dir);
+ // Delete bun.lock so bun resolves deps with new overrides
+ let _ = std::fs::remove_file(install_dir.join("bun.lock"));
+ let _ = std::fs::remove_file(install_dir.join("bun.lockb"));
+ // Trigger reinstall in background (don't block)
+ if let Some(bun) = find_bun_executable() {
+ let _ = std::thread::Builder::new()
+ .name("pi-lru-fix".to_string())
+ .spawn(move || {
+ let mut cmd = std::process::Command::new(&bun);
+ cmd.current_dir(&install_dir).args(["install"]);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x08000000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
+ match cmd.output() {
+ Ok(output) if output.status.success() => {
+ info!("Pi lru-cache fix: reinstall successful");
+ }
+ Ok(output) => {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ warn!("Pi lru-cache fix: reinstall failed: {}", stderr);
+ }
+ Err(e) => warn!("Pi lru-cache fix: bun error: {}", e),
+ }
+ });
+ }
+ } else {
+ debug!("Pi already installed locally, skipping background install");
+ }
+ }
PI_INSTALL_DONE.store(true, Ordering::SeqCst);
return;
}
@@ -1904,6 +1991,9 @@ pub fn ensure_pi_installed_background() {
info!("Pi not found — installing into {} via bun", install_dir.display());
+ // Seed package.json with overrides to fix lru-cache resolution on Windows
+ seed_pi_package_json(&install_dir);
+
let mut cmd = std::process::Command::new(&bun);
cmd.current_dir(&install_dir)
.args(["add", PI_PACKAGE]);
diff --git a/crates/screenpipe-audio/src/meeting_detector.rs b/crates/screenpipe-audio/src/meeting_detector.rs
index 39d97730a..7de09a345 100644
--- a/crates/screenpipe-audio/src/meeting_detector.rs
+++ b/crates/screenpipe-audio/src/meeting_detector.rs
@@ -42,6 +42,9 @@ pub struct CalendarSignal {
pub start_epoch_ms: i64,
pub end_epoch_ms: i64,
pub attendees: Vec<String>,
+ /// Source identifier (e.g. "native", "ics") — used to merge events from
+ /// multiple calendar publishers without overwriting each other.
+ pub source: String,
}
/// Calendar context for the currently active calendar-based meeting.
@@ -282,10 +285,19 @@ impl MeetingDetector {
}
}
- /// Replace stored calendar events and refresh the calendar meeting atomic.
+ /// Merge calendar events by source — replaces only events from the same source,
+ /// preserving events from other sources. This allows the native macOS calendar
+ /// publisher (every 60s) and ICS poller (every 10 min) to coexist without
+ /// overwriting each other's events.
pub async fn on_calendar_events(&self, events: Vec<CalendarSignal>) {
let mut state = self.state.write().await;
- state.calendar_events = events;
+ if let Some(source) = events.first().map(|e| e.source.clone()) {
+ // Remove all events from this source, then add the new ones
+ state.calendar_events.retain(|e| e.source != source);
+ state.calendar_events.extend(events);
+ } else {
+ // Empty list with no source tag — clear nothing, just skip
+ }
let active = self.is_calendar_meeting_active(&state);
self.in_calendar_meeting.store(active, Ordering::Relaxed);
}
@@ -318,9 +330,12 @@ impl MeetingDetector {
|| (last_output > 0 && (now - last_output) < window)
}
- /// Returns the first active calendar event (2+ attendees, overlapping now).
- /// Includes a 15-min early-join buffer before the event start time so that
- /// joining a meeting early (common) still triggers calendar-based detection.
+ /// Returns the first active calendar event overlapping now (with 15-min early-join buffer).
+ ///
+ /// For native calendar events: requires 2+ attendees (filters out "focus time" blocks).
+ /// For ICS events: accepts any non-all-day event, because many ICS feeds strip
+ /// attendee lists for privacy (Google public feeds, Outlook shared calendars).
+ /// The audio confirmation step in `is_calendar_meeting_active` still gates false positives.
fn active_calendar_event<'a>(
&self,
state: &'a MeetingState,
@@ -331,9 +346,17 @@ impl MeetingDetector {
.calendar_events
.iter()
.find(|e| {
+ let in_time_window =
+ (e.start_epoch_ms - buffer_ms) <= now && e.end_epoch_ms > now;
+ if !in_time_window {
+ return false;
+ }
+ // ICS feeds often lack attendees — trust the event + audio confirmation
+ if e.source == "ics" {
+ return true;
+ }
+ // Native calendar: require 2+ attendees to filter out solo blocks
e.attendees.len() >= 2
- && (e.start_epoch_ms - buffer_ms) <= now
- && e.end_epoch_ms > now
})
}
@@ -1075,6 +1098,7 @@ mod tests {
start_epoch_ms: now - 60_000, // started 1 min ago
end_epoch_ms: now + 3_600_000, // ends in 1 hour
attendees: attendees.iter().map(|s| s.to_string()).collect(),
+ source: "native".to_string(),
}
}
@@ -1087,6 +1111,7 @@ mod tests {
start_epoch_ms: now + 3_600_000, // starts in 1 hour
end_epoch_ms: now + 7_200_000, // ends in 2 hours
attendees: attendees.iter().map(|s| s.to_string()).collect(),
+ source: "native".to_string(),
}
}
@@ -1099,6 +1124,20 @@ mod tests {
start_epoch_ms: now - 7_200_000, // started 2 hours ago
end_epoch_ms: now - 3_600_000, // ended 1 hour ago
attendees: attendees.iter().map(|s| s.to_string()).collect(),
+ source: "native".to_string(),
+ }
+ }
+
+ /// Helper: create an ICS CalendarSignal (no attendees, source="ics").
+ fn calendar_ics_now(title: &str) -> CalendarSignal {
+ let now = now_millis();
+ CalendarSignal {
+ event_id: format!("ics-{}", title),
+ title: title.to_string(),
+ start_epoch_ms: now - 60_000,
+ end_epoch_ms: now + 3_600_000,
+ attendees: vec![],
+ source: "ics".to_string(),
}
}
@@ -1177,6 +1216,7 @@ mod tests {
start_epoch_ms: now + 10 * 60_000, // starts in 10 min
end_epoch_ms: now + 70 * 60_000, // ends in 70 min
attendees: vec!["Alice".to_string(), "Bob".to_string()],
+ source: "native".to_string(),
}];
detector.on_calendar_events(events).await;
@@ -1201,6 +1241,7 @@ mod tests {
start_epoch_ms: now + 20 * 60_000, // starts in 20 min
end_epoch_ms: now + 80 * 60_000,
attendees: vec!["Alice".to_string(), "Bob".to_string()],
+ source: "native".to_string(),
}];
detector.on_calendar_events(events).await;
@@ -1387,4 +1428,122 @@ mod tests {
"calendar meeting should end when the calendar event ends"
);
}
+
+ // ──────────────────────────────────────────────────────────
+ // Source-based merge (fix: native + ICS don't overwrite each other)
+ // ──────────────────────────────────────────────────────────
+
+ #[tokio::test]
+ async fn test_native_and_ics_events_merge() {
+ let detector = MeetingDetector::new();
+
+ // ICS publisher sends an event
+ let ics_events = vec![calendar_ics_now("ICS Standup")];
+ detector.on_calendar_events(ics_events).await;
+
+ // Native publisher sends a different event
+ let native_events = vec![calendar_now("Native 1:1", &["Alice", "Bob"])];
+ detector.on_calendar_events(native_events).await;
+
+ // Both should be present
+ let state = detector.state.read().await;
+ assert_eq!(
+ state.calendar_events.len(),
+ 2,
+ "should have both ICS and native events, got {:?}",
+ state.calendar_events.iter().map(|e| &e.title).collect::<Vec<_>>()
+ );
+ }
+
+ #[tokio::test]
+ async fn test_same_source_replaces_not_accumulates() {
+ let detector = MeetingDetector::new();
+
+ // Native publisher sends 2 events
+ let events1 = vec![
+ calendar_now("Morning Standup", &["Alice", "Bob"]),
+ calendar_now("Sprint Review", &["Alice", "Charlie"]),
+ ];
+ detector.on_calendar_events(events1).await;
+
+ // Native publisher refreshes (every 60s) — should replace, not append
+ let events2 = vec![calendar_now("Morning Standup", &["Alice", "Bob"])];
+ detector.on_calendar_events(events2).await;
+
+ let state = detector.state.read().await;
+ assert_eq!(
+ state.calendar_events.len(),
+ 1,
+ "same-source update should replace, not accumulate"
+ );
+ }
+
+ #[tokio::test]
+ async fn test_native_refresh_preserves_ics() {
+ let detector = MeetingDetector::new();
+
+ // ICS event first
+ let ics = vec![calendar_ics_now("ICS Meeting")];
+ detector.on_calendar_events(ics).await;
+
+ // Native publisher refreshes every 60s with its own events
+ let native = vec![calendar_now("Native Meeting", &["A", "B"])];
+ detector.on_calendar_events(native).await;
+
+ // Native refreshes again (could be empty if no native events)
+ // Empty vec has no source → should not clear anything
+ detector.on_calendar_events(vec![]).await;
+
+ let state = detector.state.read().await;
+ // ICS event should still be there, native event should still be there
+ assert_eq!(
+ state.calendar_events.len(),
+ 2,
+ "empty update should not clear events"
+ );
+ }
+
+ // ──────────────────────────────────────────────────────────
+ // ICS events without attendees (fix: ICS feeds strip attendees)
+ // ──────────────────────────────────────────────────────────
+
+ #[tokio::test]
+ async fn test_ics_event_no_attendees_triggers_meeting() {
+ let detector = MeetingDetector::new();
+
+ // ICS event with NO attendees (common with Google public feeds)
+ let events = vec![calendar_ics_now("Team Sync")];
+ detector.on_calendar_events(events).await;
+
+ // Audio confirms user is present
+ detector.on_audio_activity(&DeviceType::Output, true);
+
+ assert!(
+ detector.is_in_meeting(),
+ "ICS event without attendees should trigger meeting (feeds strip attendees)"
+ );
+ }
+
+ #[tokio::test]
+ async fn test_native_event_no_attendees_does_not_trigger() {
+ let detector = MeetingDetector::new();
+
+ // Native event with 0 attendees (e.g., "Focus Time" block)
+ let now = now_millis();
+ let events = vec![CalendarSignal {
+ event_id: "focus".to_string(),
+ title: "Focus Time".to_string(),
+ start_epoch_ms: now - 60_000,
+ end_epoch_ms: now + 3_600_000,
+ attendees: vec![],
+ source: "native".to_string(),
+ }];
+ detector.on_calendar_events(events).await;
+ detector.on_audio_activity(&DeviceType::Output, true);
+
+ assert!(
+ !detector.is_in_meeting(),
+ "native event with 0 attendees should NOT trigger (likely a focus block)"
+ );
+ }
}
diff --git a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/meeting_benchmark.rs b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/meeting_benchmark.rs
index cc0f6edef..f6a85b265 100644
--- a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/meeting_benchmark.rs
+++ b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/meeting_benchmark.rs
@@ -86,6 +86,7 @@ async fn replay_scenario(
start_epoch_ms: now_ms - 1000, // already started
end_epoch_ms: now_ms + (total_duration_secs * 1000.0) as i64,
attendees,
+ source: "native".to_string(),
}])
.await;
}
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 0984c6910..4afb5b3e9 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -915,6 +915,9 @@ impl AgentExecutor for PiExecutor {
info!("installing pi into {} via bun …", install_dir.display());
+ // Seed package.json with overrides to fix lru-cache resolution on Windows
+ seed_pi_package_json(&install_dir);
+
let mut cmd = std::process::Command::new(&bun);
cmd.current_dir(&install_dir).args(["add", PI_PACKAGE]);
@@ -990,6 +993,47 @@ fn pi_local_install_dir() -> Option<PathBuf> {
dirs::home_dir().map(|h| h.join(".screenpipe").join("pi-agent"))
}
+/// Seed the pi-agent package.json with overrides to fix dependency resolution.
+/// `hosted-git-info` requires `lru-cache@^10`, but bun on Windows can hoist
+/// an ESM-only [email protected] that breaks CJS `require()`.
+fn seed_pi_package_json(install_dir: &Path) {
+ let pkg_path = install_dir.join("package.json");
+ if pkg_path.exists() {
+ if let Ok(contents) = std::fs::read_to_string(&pkg_path) {
+ if !contents.contains("overrides") {
+ if let Ok(mut pkg) = serde_json::from_str::<serde_json::Value>(&contents) {
+ pkg.as_object_mut().map(|obj| {
+ obj.insert(
+ "overrides".to_string(),
+ json!({
+ "hosted-git-info": {
+ "lru-cache": "^10.0.0"
+ }
+ }),
+ );
+ });
+ if let Ok(new_contents) = serde_json::to_string_pretty(&pkg) {
+ let _ = std::fs::write(&pkg_path, new_contents);
+ info!("Added lru-cache overrides to existing pi-agent package.json");
+ }
+ }
+ }
+ }
+ return;
+ }
+ let pkg_json = json!({
+ "overrides": {
+ "hosted-git-info": {
+ "lru-cache": "^10.0.0"
+ }
+ }
+ });
+ match std::fs::write(&pkg_path, serde_json::to_string_pretty(&pkg_json).unwrap_or_default()) {
+ Ok(_) => info!("Seeded pi-agent package.json with lru-cache overrides"),
+ Err(e) => warn!("Failed to seed pi-agent package.json: {}", e),
+ }
+}
+
/// Find the JS entrypoint for the locally-installed pi package.
fn find_local_pi_entrypoint() -> Option<String> {
let dir = pi_local_install_dir()?;
diff --git a/crates/screenpipe-engine/src/calendar_bridge.rs b/crates/screenpipe-engine/src/calendar_bridge.rs
index dfbb04387..7e03ffb1b 100644
--- a/crates/screenpipe-engine/src/calendar_bridge.rs
+++ b/crates/screenpipe-engine/src/calendar_bridge.rs
@@ -28,6 +28,13 @@ struct CalendarEventItem {
end: String,
attendees: Vec<String>,
is_all_day: bool,
+ /// Source identifier: "native" for OS calendar, "ics" for ICS feeds.
+ #[serde(default = "default_source")]
+ source: String,
+}
+
+fn default_source() -> String {
+ "native".to_string()
}
/// Start the calendar bridge background task.
@@ -64,6 +71,7 @@ pub fn start_calendar_bridge(detector: Arc<MeetingDetector>) -> JoinHandle<()> {
start_epoch_ms: start.timestamp_millis(),
end_epoch_ms: end.timestamp_millis(),
attendees: item.attendees,
+ source: item.source,
})
})
.collect();