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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(windows): the pin would not hold and the meeting alert never arrived
louis03019583ac1e118863
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs b/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rsindex 2c13f9c36..82ac432ef 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/notifications/gate.rs@@ -366,21 +366,64 @@ pub fn repeat_suppressed_now(title: &str,body: &str,) -> bool {- if matches!(notification_type, Some(t) if is_critical_type(t)) {- return false;- }- // Nothing to key on — an untitled alert can't be told apart from the next- // one, so capping it would collapse unrelated alerts together.- if title.trim().is_empty() {+ let Some((key, cooldown)) = repeat_identity(notification_type, pipe_name, title, body) else {return false;- }- let key = repeat_key(notification_type, pipe_name, title, body);- let cooldown = repeat_cooldown_ms(notification_type);+ };let now_ms = chrono::Local::now().timestamp_millis();let mut guard = ledger().lock().unwrap_or_else(|e| e.into_inner());check_and_record(&mut guard, key, now_ms, cooldown)}+/// Read the ledger *without* recording.+///+/// `/notify` looks first so a suppressed alert never writes history, then hands+/// the payload to `show_notification_panel` — the choke point every other+/// producer also reaches. When both *recorded*, the second look always found+/// what the first had written milliseconds earlier and dropped the alert. Every+/// high-priority alert arriving over http died that way, while direct callers+/// were untouched, which is what made it look intermittent rather than total.+///+/// So the early look only reads. The choke point owns the write, and an alert+/// is recorded exactly once no matter which door it came through.+pub fn repeat_suppressed_peek(+ notification_type: Option<&str>,+ pipe_name: Option<&str>,+ title: &str,+ body: &str,+) -> bool {+ let Some((key, cooldown)) = repeat_identity(notification_type, pipe_name, title, body) else {+ return false;+ };+ let now_ms = chrono::Local::now().timestamp_millis();+ let guard = ledger().lock().unwrap_or_else(|e| e.into_inner());+ repeat_suppressed(guard.get(&key).copied(), now_ms, cooldown)+}++/// The ledger key and cooldown for an alert, or `None` when it is not subject+/// to repeat suppression at all.+///+/// Critical types are exempt and are never recorded: a recording-stopped alert+/// that re-fires is re-stating an unresolved failure, and muting the second one+/// would be the exact failure mode this gate exists to prevent. An untitled+/// alert has no identity, so capping it would collapse unrelated alerts.+fn repeat_identity(+ notification_type: Option<&str>,+ pipe_name: Option<&str>,+ title: &str,+ body: &str,+) -> Option<(String, i64)> {+ if matches!(notification_type, Some(t) if is_critical_type(t)) {+ return None;+ }+ if title.trim().is_empty() {+ return None;+ }+ Some((+ repeat_key(notification_type, pipe_name, title, body),+ repeat_cooldown_ms(notification_type),+ ))+}+/// Extract the `type` field from a notification panel payload JSON string.pub fn notification_type_from_payload(payload: &str) -> Option<String> {json_field(payload, "type")@@ -861,6 +904,41 @@ mod tests {}}+ /// One alert passes two gates on its way out: `/notify` looks first so a+ /// repeat never writes history, then hands off to the choke point every+ /// producer shares. Only the choke point may record — when both did, the+ /// second look found the first look's own entry, milliseconds old, and+ /// dropped the alert. Every high-priority alert sent over http died that+ /// way; the meeting toast lost its "open note" button to it.+ #[test]+ fn looking_twice_at_one_alert_still_delivers_it() {+ let mut ledger = empty_ledger();+ let cooldown = repeat_cooldown_ms(Some("meeting"));+ let key = repeat_key(+ Some("meeting"),+ None,+ "meeting detected",+ "screenpipe is saving this meeting for transcription: Google Meet",+ );++ // `/notify` peeks: nothing recorded yet, so it passes it along.+ assert!(!repeat_suppressed(ledger.get(&key).copied(), 0, cooldown));+ assert!(+ ledger.is_empty(),+ "the peek must not write — that write is what ate the alert"+ );++ // The choke point records and delivers.+ assert!(!check_and_record(&mut ledger, key.clone(), 2, cooldown));++ // A real repeat is still stopped at the door, before it writes history.+ assert!(repeat_suppressed(+ ledger.get(&key).copied(),+ 60_000,+ cooldown+ ));+ }+/// An untitled alert has no identity, so capping it would collapse/// unrelated alerts into one.#[test]diff --git a/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs b/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rsindex 87565c6af..79c431018 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/notifications/routes.rs@@ -198,7 +198,10 @@ pub async fn send_notification(// echo here rather than expecting every producer to latch for itself. The// body is part of the identity because for some producers it carries the// only thing that tells two distinct alerts apart — see the gate's notes.- if super::gate::repeat_suppressed_now(+ // A peek, not a check-and-record: `show_notification_panel` below is the+ // choke point that records. Recording here too made that second look find+ // this one's own entry and drop every high-priority alert sent over http.+ if super::gate::repeat_suppressed_peek(Some(resolved_type.as_str()),source.pipe_name.as_deref(),&payload.title,diff --git a/crates/screenpipe-overlay-win/src/window.rs b/crates/screenpipe-overlay-win/src/window.rsindex 7b9882b6a..0f8399fe4 100644--- a/crates/screenpipe-overlay-win/src/window.rs+++ b/crates/screenpipe-overlay-win/src/window.rs@@ -222,6 +222,8 @@ struct Ctx {/// The last anchor the app pushed, so a re-push of the same value can be/// told apart from the app actually asking the pill to move.pushed_anchor: Option<Anchor>,+ /// Same, for the transcript card's pin.+ pushed_pinned: Option<bool>,dragging: bool,drag_offset: (i32, i32),animating: bool,@@ -295,6 +297,7 @@ fn run_message_loop(press_can_drag: false,toast_hovered: false,pushed_anchor: None,+ pushed_pinned: None,dragging: false,drag_offset: (0, 0),animating: false,@@ -662,12 +665,23 @@ fn resolve_anchor(window: Anchor,dragging: bool,) -> (Anchor, Option<Anchor>) {- let app_moved_it = pushed != Some(incoming);- let applied = if app_moved_it && !dragging {- incoming- } else {- window- };+ let (applied, pushed) = resolve_owned(pushed, incoming, window);+ // Nothing relocates the pill while it is under the pointer, not even a+ // genuine change: the drop decides where it lands.+ (if dragging { window } else { applied }, pushed)+}++/// The value to apply for something the *window* owns but the app also sends+/// back in every state push.+///+/// The app's copy is only as fresh as the last round-trip through its store, so+/// a value the user just changed here — where the pill sits, whether the card+/// is pinned — arrives back stale a few milliseconds later and would undo+/// itself. An echo of what the app last sent is therefore ignored in favour of+/// what the window has; only a value the app actually *changed* wins.+fn resolve_owned<T: PartialEq + Copy>(pushed: Option<T>, incoming: T, window: T) -> (T, Option<T>) {+ let app_changed_it = pushed != Some(incoming);+ let applied = if app_changed_it { incoming } else { window };(applied, Some(incoming))}@@ -696,6 +710,17 @@ fn drain_commands(hwnd: HWND) -> (bool, bool) {resolve_anchor(ctx.pushed_anchor, s.anchor, ctx.state.anchor, ctx.dragging);s.anchor = anchor;ctx.pushed_anchor = pushed;+ // The pin is the same story as the anchor: the pill toggles it+ // itself and never reports it, so the app's copy is always the+ // one from before the click. Taking it at face value unpinned+ // the card again within a frame.+ let (pinned, pushed) = resolve_owned(+ ctx.pushed_pinned,+ s.transcript_pinned,+ ctx.state.transcript_pinned,+ );+ s.transcript_pinned = pinned;+ ctx.pushed_pinned = pushed;// The caller does not own the notification either — it arrives// through show_notification and leaves on its own schedule.s.notification = ctx.state.notification.clone();@@ -1056,6 +1081,30 @@ mod tests {assert_eq!(anchor, Anchor::TopLeft);}+ /// The pin lives only in the window — clicking it reports nothing to the+ /// app — so the app's copy is always the value from before the click, and+ /// it re-sends that copy many times a second. Taking it at face value+ /// unpinned the card again within a frame of pinning it.+ #[test]+ fn pinning_the_card_survives_the_apps_stale_state_pushes() {+ // Startup: nothing pinned, app and window agree.+ let (pinned, pushed) = resolve_owned(None, false, false);+ assert!(!pinned);++ // The user clicks the pin. The window owns `true` now; the app still+ // believes `false` and keeps saying so.+ let (pinned, pushed) = resolve_owned(pushed, false, true);+ assert!(pinned, "an echo of the pre-click value must not unpin it");+ let (pinned, pushed) = resolve_owned(pushed, false, true);+ assert!(pinned, "and it must not unpin on the next push either");++ // The meeting ends: the app genuinely clears the pin, and that wins.+ let (pinned, pushed) = resolve_owned(pushed, true, true);+ assert!(pinned, "app catching up to true is a no-op");+ let (pinned, _) = resolve_owned(pushed, false, true);+ assert!(!pinned, "a real change from the app clears the pin");+ }+/// A push landing mid-drag must never teleport the pill out from under the/// pointer, even when the app really did change the anchor.#[test]