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(onboarding): don't block the timeline choice on the engine restart
Anshgrover236759470eb4e9
diff --git a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsxindex e4a9d4f14..8baf811a0 100644--- a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx+++ b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.test.tsx@@ -256,7 +256,27 @@ describe("TimelineChoice", () => {expect(handleNextSlide).toHaveBeenCalledTimes(1);});- it("keeps the user on the step when the restart fails", async () => {+ // Regression: awaiting the restart wedged the step. A full stop/spawn cycle+ // took ~28s on a populated install and WKWebView killed its content process+ // partway through, destroying the pending promise so the click handler never+ // resumed. The step must advance without waiting for the engine.+ it("advances without waiting for the restart to finish", async () => {+ mocks.settings.deviceTier = "low";+ mocks.localFetch.mockResolvedValue({ ok: true, status: 200 });+ // A stop that never settles stands in for the multi-second real one.+ mocks.stopScreenpipe.mockImplementation(() => new Promise<void>(() => {}));+ const handleNextSlide = vi.fn();+ render(<TimelineChoice handleNextSlide={handleNextSlide} />);++ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: /keep it off/i }));+ });++ await waitFor(() => expect(handleNextSlide).toHaveBeenCalledTimes(1));+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();+ });++ it("still advances when the restart itself fails", async () => {mocks.settings.deviceTier = "low";mocks.localFetch.mockResolvedValue({ ok: true, status: 200 });mocks.spawnScreenpipe.mockRejectedValue(new Error("spawn failed"));@@ -268,10 +288,8 @@ describe("TimelineChoice", () => {fireEvent.click(screen.getByRole("button", { name: /keep it off/i }));});- expect(await screen.findByRole("alert")).toHaveTextContent(- /didn't restart/i,- );- expect(handleNextSlide).not.toHaveBeenCalled();+ // engine-startup owns surfacing engine trouble, so the step does not block+ await waitFor(() => expect(handleNextSlide).toHaveBeenCalledTimes(1));consoleError.mockRestore();});diff --git a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsxindex 83f77e8b3..9a3d449e8 100644--- a/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx+++ b/apps/screenpipe-app-tauri/components/onboarding/timeline-choice.tsx@@ -151,32 +151,34 @@ const COSTS = [* recorder kept its old behaviour until some later restart. Mirrors the* stop → wait → spawn sequence in components/settings/display-section.tsx.*- * Returns false only when a restart was needed and failed.+ * Deliberately NOT awaited by the caller. A full cycle measured ~28s on a+ * populated install (audio shutdown alone hit its 15s timeout, and a+ * `PRAGMA quick_check` took 73s), and WKWebView terminated its content process+ * partway through — which destroys the pending promise, so an awaiting click+ * handler never resumes and the button spins forever. The next slide is+ * engine-startup, which polls /health and owns the "engine is coming up" UI,+ * so it absorbs this window properly.*/-async function applyToRunningEngine(): Promise<boolean> {- let engineRunning = false;- try {- const res = await localFetch("/health", {- signal: AbortSignal.timeout(3000),- });- // /health answers 503 while a pipeline has no data yet, which still means- // an engine is up — any response at all is enough here.- engineRunning = !!res;- } catch {- // Nothing listening: first-run onboarding, engine not spawned yet.- return true;- }- if (!engineRunning) return true;+function restartRunningEngine(): void {+ void (async () => {+ try {+ await localFetch("/health", { signal: AbortSignal.timeout(3000) });+ } catch {+ // Nothing listening: first-run onboarding, engine not spawned yet, and+ // the upcoming engine-startup slide will spawn it with the new flags.+ return;+ }- try {- await commands.stopScreenpipe();- await new Promise((r) => setTimeout(r, 500));- await commands.spawnScreenpipe(null);- return true;- } catch (e) {- console.error("failed to restart screenpipe after timeline choice:", e);- return false;- }+ try {+ await commands.stopScreenpipe();+ await new Promise((r) => setTimeout(r, 500));+ await commands.spawnScreenpipe(null);+ } catch (e) {+ // Surfaced by engine-startup's own health UI rather than blocking here.+ console.error("failed to restart screenpipe after timeline choice:", e);+ posthog.capture("onboarding_timeline_restart_failed");+ }+ })();}// ─── Main ────────────────────────────────────────────────────────────────────@@ -236,13 +238,9 @@ export default function TimelineChoice({ handleNextSlide }: TimelineChoiceProps)return;}- if (!(await applyToRunningEngine())) {- posthog.capture("onboarding_timeline_choice_failed", { stage: "restart" });- setError("saved, but screenpipe didn't restart. try again to apply it.");- inFlight.current = false;- setPending(null);- return;- }+ // Kick the restart off and advance immediately — see restartRunningEngine+ // for why awaiting it wedged the step.+ restartRunningEngine();hasAdvanced.current = true;handleNextSlide();