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: stop replaying completed native timeline jumps
Louis Beaumont708a3e79ce1b
diff --git a/apps/screenpipe-app-tauri/components/rewind/native-timeline-attach.test.tsx b/apps/screenpipe-app-tauri/components/rewind/native-timeline-attach.test.tsxindex d2eed4ee7..e20eb4c5f 100644--- a/apps/screenpipe-app-tauri/components/rewind/native-timeline-attach.test.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/native-timeline-attach.test.tsx@@ -11,6 +11,7 @@ const mocks = vi.hoisted(() => ({listen: vi.fn(),ensureApiReady: vi.fn(),nativeTimelineIsAvailable: vi.fn(),+ nativeTimelineNavigate: vi.fn(),getStorageMigrationActivity: vi.fn(),onMigrationActivity: (_: { payload: { busy: boolean; message: string } }) => {},}));@@ -35,7 +36,7 @@ vi.mock("posthog-js", () => ({vi.mock("@/lib/utils/tauri", () => ({commands: {nativeTimelineIsAvailable: mocks.nativeTimelineIsAvailable,- nativeTimelineNavigate: vi.fn(),+ nativeTimelineNavigate: mocks.nativeTimelineNavigate,openSearchWindow: vi.fn(),showWindow: vi.fn(),getStorageMigrationActivity: mocks.getStorageMigrationActivity,@@ -89,6 +90,7 @@ describe("native timeline startup API config", () => {beforeEach(() => {mocks.emit.mockReset().mockResolvedValue(undefined);+ mocks.nativeTimelineNavigate.mockReset().mockResolvedValue(true);mocks.listen.mockReset().mockResolvedValue(vi.fn());mocks.nativeTimelineIsAvailable.mockReset().mockResolvedValue(true);mocks.getStorageMigrationActivity.mockReset().mockResolvedValue({ busy: false, message: "" });@@ -149,6 +151,67 @@ describe("native timeline startup API config", () => {});});+ it("does not keep pulling the playhead back after a starred timestamp is accepted", async () => {+ mocks.nativeTimelineNavigate.mockResolvedValue(true);+ render(<NativeTimeline fallback={<div>react fallback</div>} />);+ await act(async () => { resolveApiReady?.(); });+ const handler = (name: string) => mocks.listen.mock.calls.find(+ ([eventName]) => eventName === name,+ )![1];+ act(() => handler("native-timeline-attached")({ payload: { windowLabel: "home", ok: true } }));+ vi.useFakeTimers();+ try {+ act(() => handler("navigate-to-timestamp")({ payload: "2026-10-02T17:00:00.000Z" }));+ await act(async () => { await vi.advanceTimersByTimeAsync(0); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(1);+ // Once the jump lands, scrubbing elsewhere must remain the user's choice.+ await act(async () => { await vi.advanceTimersByTimeAsync(9000); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(1);+ } finally {+ vi.useRealTimers();+ }+ });++ it("retries an unloaded day and stops after it selects the requested time", async () => {+ mocks.nativeTimelineNavigate.mockResolvedValueOnce(false).mockResolvedValue(true);+ render(<NativeTimeline fallback={<div>react fallback</div>} />);+ await act(async () => { resolveApiReady?.(); });+ const handler = (name: string) => mocks.listen.mock.calls.find(([eventName]) => eventName === name)![1];+ act(() => handler("native-timeline-attached")({ payload: { windowLabel: "home", ok: true } }));+ vi.useFakeTimers();+ try {+ act(() => handler("navigate-to-timestamp")({ payload: "2026-10-02T17:00:00.000Z" }));+ await act(async () => { await vi.advanceTimersByTimeAsync(0); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(1);+ await act(async () => { await vi.advanceTimersByTimeAsync(1000); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(2);+ await act(async () => { await vi.advanceTimersByTimeAsync(8000); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(2);+ } finally { vi.useRealTimers(); }+ });++ it("does not overlap a slow jump or let it clear a newer request", async () => {+ let finishOld!: (value: boolean) => void;+ mocks.nativeTimelineNavigate.mockImplementationOnce(() => new Promise<boolean>((resolve) => { finishOld = resolve; }));+ render(<NativeTimeline fallback={<div>react fallback</div>} />);+ await act(async () => { resolveApiReady?.(); });+ const handler = (name: string) => mocks.listen.mock.calls.find(([eventName]) => eventName === name)![1];+ act(() => handler("native-timeline-attached")({ payload: { windowLabel: "home", ok: true } }));+ vi.useFakeTimers();+ try {+ act(() => handler("navigate-to-timestamp")({ payload: "2026-10-02T17:00:00.000Z" }));+ await act(async () => { await vi.advanceTimersByTimeAsync(3000); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(1);+ mocks.nativeTimelineNavigate.mockResolvedValue(false);+ act(() => handler("navigate-to-timestamp")({ payload: "2026-10-03T17:00:00.000Z" }));+ await act(async () => { await vi.advanceTimersByTimeAsync(0); });+ await act(async () => { finishOld(true); });+ await act(async () => { await vi.advanceTimersByTimeAsync(1000); });+ expect(mocks.nativeTimelineNavigate).toHaveBeenCalledTimes(3);+ expect(mocks.nativeTimelineNavigate).toHaveBeenLastCalledWith("2026-10-03T17:00:00.000Z", null);+ } finally { vi.useRealTimers(); }+ });+it("routes the native timeline sidebar shortcut back to its Home shell", async () => {const onToggleSidebar = vi.fn();render(<NativeTimelineBridge onToggleSidebar={onToggleSidebar} />);diff --git a/apps/screenpipe-app-tauri/components/rewind/native-timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/native-timeline.tsxindex 80982aa56..adf0d8efe 100644--- a/apps/screenpipe-app-tauri/components/rewind/native-timeline.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/native-timeline.tsx@@ -443,45 +443,48 @@ export function NativeTimeline({const timestamp = navigation.timestamp || null;const frameId = navigation.frameId || null;+ let cancelled = false;+ let complete = false;+ let inFlight = false;+ const finish = () => {+ if (cancelled) return;+ complete = true;+ setNativePendingNavigation((pending) =>+ pending === navigation ? null : pending,+ );+ const current = useTimelineStore.getState().pendingNavigation;+ if (+ current?.timestamp === navigation.timestamp &&+ current?.frameId === navigation.frameId+ ) {+ setPendingNavigation(null);+ }+ };const timers = NATIVE_TIMELINE_NAVIGATION_RETRY_MS.map((delay) =>- window.setTimeout(() => {- // Timestamp first ensures a past-day artifact loads the right day.- // Frame id then refines a screen artifact to the exact captured frame.- if (timestamp) {- void commands.nativeTimelineNavigate(timestamp, null).catch(() => {- // A later retry runs after the native day finishes loading.- });- }- if (frameId) {- void commands.nativeTimelineNavigate(null, frameId).catch(() => {- // The target frame may not exist until the timestamp request lands.- });+ window.setTimeout(async () => {+ if (cancelled || complete || inFlight) return;+ inFlight = true;+ try {+ // Native returns false until the requested day/frame is available.+ // Once it selects the target, retries must stop: they would undo+ // any subsequent scrubbing or date change by the user.+ if (timestamp && !(await commands.nativeTimelineNavigate(timestamp, null))) return;+ if (cancelled || complete) return;+ if (frameId && !(await commands.nativeTimelineNavigate(null, frameId))) return;+ finish();+ } catch {+ // Retry only a failed or unresolved hand-off.+ } finally {+ inFlight = false;}}, delay),);timers.push(- window.setTimeout(- () => {- const current = useTimelineStore.getState().pendingNavigation;- if (- !current ||- (current.timestamp === navigation.timestamp &&- current.frameId === navigation.frameId)- ) {- setNativePendingNavigation((pending) =>- pending?.timestamp === navigation.timestamp &&- pending?.frameId === navigation.frameId- ? null- : pending,- );- setPendingNavigation(null);- }- },- NATIVE_TIMELINE_NAVIGATION_RETRY_MS.at(-1)! + 500,- ),+ window.setTimeout(finish, NATIVE_TIMELINE_NAVIGATION_RETRY_MS.at(-1)! + 500),);return () => {+ cancelled = true;for (const timer of timers) window.clearTimeout(timer);};}, [attached, available, nativePendingNavigation, setPendingNavigation]);diff --git a/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift b/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swiftindex 080d7530f..d7bf94f97 100644--- a/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift+++ b/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift@@ -581,6 +581,11 @@ final class TimelineWindowController: NSObject, NSWindowDelegate {@discardableResultstatic func navigate(frameId: String?, timestamp: String?) -> Bool {guard let model = activeNavigationModel() else { return false }+ return navigate(model: model, frameId: frameId, timestamp: timestamp)+ }++ /// True acknowledges a selected target, not merely a queued day request.+ static func navigate(model: TimelineViewModel, frameId: String?, timestamp: String?) -> Bool {if let frameId,let index = TimelineNavigation.index(ofFrameId: frameId, in: model.frames) {if model.currentIndex == index,@@ -611,7 +616,10 @@ final class TimelineWindowController: NSObject, NSWindowDelegate {model.setExternalNavigationIndex(index)} else {model.beginExternalNavigation(superseding: true)- model.changeDate(to: date, supersedePendingNavigation: true)+ if !model.isNavigating || !Calendar.current.isDate(model.currentDate, inSameDayAs: date) {+ model.changeDate(to: date, supersedePendingNavigation: true)+ }+ return false}return true}@@ -1296,7 +1304,7 @@ public func timeline_navigate(_ json: UnsafePointer<CChar>?) -> Int32 {let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {return -1}- @MainActor func run() {+ @MainActor func run() -> Int32 {let windowLabel = obj["windowLabel"] as? Stringlet frameId = obj["frameId"] as? Stringlet rawTimestamp = obj["timestamp"] as? String@@ -1322,19 +1330,19 @@ public func timeline_navigate(_ json: UnsafePointer<CChar>?) -> Int32 {),windowLabel: windowLabel)+ return 0 // Addressed search requests are retained until their host attaches.} else {- TimelineWindowController.navigate(frameId: frameId, timestamp: rawTimestamp)+ return TimelineWindowController.navigate(frameId: frameId, timestamp: rawTimestamp) ? 0 : -1}}// Return only after the native model has accepted or queued the click. The// old async dispatch returned success first, so Rust's retries could all// finish while Swift silently had no addressed model yet.if Thread.isMainThread {- MainActor.assumeIsolated { run() }+ return MainActor.assumeIsolated { run() }} else {- DispatchQueue.main.sync { MainActor.assumeIsolated { run() } }+ return DispatchQueue.main.sync { MainActor.assumeIsolated { run() } }}- return 0}/// Read-only native state used only through the feature-gated Rust E2E plugin.diff --git a/apps/screenpipe-app-tauri/src-tauri/swift/timeline_stream_tests.swift b/apps/screenpipe-app-tauri/src-tauri/swift/timeline_stream_tests.swiftindex a693f2d5b..90965760a 100644--- a/apps/screenpipe-app-tauri/src-tauri/swift/timeline_stream_tests.swift+++ b/apps/screenpipe-app-tauri/src-tauri/swift/timeline_stream_tests.swift@@ -4,6 +4,7 @@// Headless regression for the real native stream decoder and Timeline model.import Foundation+import AppKit@mainstruct TimelineStreamTests {@@ -38,6 +39,37 @@ struct TimelineStreamTests {precondition(!model.isLoading && !model.isNavigating)precondition(model.connectionError == "Timeline request timed out")model.stop()++ // Exercise the same navigation seam as the FFI without showing a window.+ _ = NSApplication.shared+ let navigationModel = TimelineViewModel(config: TimelineAPIConfig(port: 0))+ let target = Date().addingTimeInterval(-3 * 86400)+ let timestamp = TimelineTime.iso(target)+ precondition(!TimelineWindowController.navigate(model: navigationModel, frameId: nil, timestamp: timestamp),+ "requesting an unloaded day is not successful navigation")+ precondition(navigationModel.isNavigating)+ precondition(!TimelineWindowController.navigate(model: navigationModel, frameId: nil, timestamp: timestamp),+ "an in-flight day must remain retryable")+ let frames = [0, 60, 120].enumerated().map { index, offset in+ StreamTimeSeriesResponse(+ timestamp: TimelineTime.iso(target.addingTimeInterval(Double(offset))),+ devices: [DeviceFrameResponse(deviceId: "test-display", frameId: "nav-\(index)", metadata: DeviceMetadata(filePath: "/tmp/synthetic-navigation.jpg"))]+ )+ }+ navigationModel.injectForTesting(frames: frames)+ precondition(TimelineWindowController.navigate(model: navigationModel, frameId: nil, timestamp: timestamp),+ "a loaded timestamp acknowledges selection")+ precondition(navigationModel.displayFrameId == "nav-0")+ navigationModel.setIndex(0)+ precondition(navigationModel.displayFrameId == "nav-2", "user can scrub away after selection")+ precondition(TimelineWindowController.navigate(model: navigationModel, frameId: "nav-1", timestamp: nil))+ precondition(navigationModel.displayFrameId == "nav-1", "frame refinement selects the exact frame")+ precondition(!TimelineWindowController.navigate(model: navigationModel, frameId: "missing", timestamp: nil))+ let missingHost = "{\"timestamp\":\"\(timestamp)\"}"+ precondition(missingHost.withCString { timeline_navigate($0) } != 0,+ "FFI must not acknowledge a jump with no native model")+ navigationModel.stop()+ print("PASS: native navigation acknowledges selection, retries unloaded targets, exact frame and missing-host FFI")print("PASS: native stream completion, empty day, stale range, search window, navigation and error states")}}