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): retry onboarding capture after recovery

screenpipe Windows autonomous workere5a3f4859b9a
diff --git a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.test.tsx b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.test.tsx
index 262b7ad93..e2bd093f0 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.test.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.test.tsx
@@ -275,6 +275,36 @@ describe("onboarding engine startup", () => {
expect(await screen.findByText(/engine failed to start/i)).toBeInTheDocument();
});
+ it("retries a rejected capture start after the native condition recovers", async () => {
+ mocks.startCapture
+ .mockResolvedValueOnce({
+ status: "error",
+ error: "Deepgram requires an API key",
+ })
+ .mockResolvedValue({ status: "ok", data: null });
+ mocks.localFetch.mockImplementation(async () =>
+ new Response(
+ JSON.stringify({
+ status: "degraded",
+ status_code: 503,
+ frame_status: "not_started",
+ audio_status: "not_started",
+ }),
+ { status: 503 },
+ ),
+ );
+ vi.spyOn(console, "error").mockImplementation(() => {});
+
+ render(<EngineStartup handleNextSlide={mocks.handleNextSlide} />);
+
+ await waitFor(() => expect(mocks.startCapture).toHaveBeenCalledTimes(2));
+ expect(mocks.stopCapture).not.toHaveBeenCalled();
+ await waitFor(
+ () => expect(mocks.handleNextSlide).toHaveBeenCalledTimes(1),
+ { timeout: 2000 },
+ );
+ });
+
it("ensures capture after native startup becomes reachable", async () => {
mocks.localFetch
.mockRejectedValueOnce(new Error("engine not listening yet"))
diff --git a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx
index a2a30e7ff..72e85ee31 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx
@@ -239,7 +239,7 @@ export default function EngineStartup({ handleNextSlide }: EngineStartupProps) {
if (captureSetupPromiseRef.current) return captureSetupPromiseRef.current;
captureSetupInFlightRef.current = true;
- captureSetupPromiseRef.current = (async () => {
+ const captureSetupAttempt = (async () => {
try {
const startResult = await commands.startCapture();
if (startResult.status === "error") throw new Error(startResult.error);
@@ -247,8 +247,18 @@ export default function EngineStartup({ handleNextSlide }: EngineStartupProps) {
captureSetupInFlightRef.current = false;
}
})();
+ captureSetupPromiseRef.current = captureSetupAttempt;
+
+ // Cache a successful session for the rest of this mount, but let a later
+ // healthy poll retry after a recoverable native/configuration failure.
+ // Guard by identity so an older rejection cannot clear a newer attempt.
+ captureSetupAttempt.catch(() => {
+ if (captureSetupPromiseRef.current === captureSetupAttempt) {
+ captureSetupPromiseRef.current = null;
+ }
+ });
- return captureSetupPromiseRef.current;
+ return captureSetupAttempt;
}, []);
// Assigned during render, per the ref-mirror rule in CLAUDE.md.