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(onboarding): reschedule engine auto-advance (#5317)

Ezra Ellette4d4a29847d93
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 815b32f6c..4298fdb95 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.test.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.test.tsx
@@ -113,6 +113,44 @@ describe("onboarding engine startup", () => {
);
});
+ it("reschedules the advance when dependencies change during the ready delay", async () => {
+ mocks.localFetch.mockImplementation(async () =>
+ new Response(
+ JSON.stringify({
+ status: "healthy",
+ status_code: 200,
+ frame_status: "ok",
+ audio_status: "ok",
+ }),
+ { status: 200 },
+ ),
+ );
+ const initialNextSlide = vi.fn();
+ const replacementNextSlide = vi.fn();
+
+ const { rerender } = render(
+ <EngineStartup handleNextSlide={initialNextSlide} />,
+ );
+
+ await waitFor(() =>
+ expect(mocks.capture).toHaveBeenCalledWith(
+ "onboarding_engine_started",
+ expect.any(Object),
+ ),
+ );
+
+ // A settings/context update changes the callback identity while the
+ // completed-state delay is pending. The cleanup cancels the first timer;
+ // the replacement effect must still be allowed to schedule another one.
+ rerender(<EngineStartup handleNextSlide={replacementNextSlide} />);
+
+ await waitFor(
+ () => expect(replacementNextSlide).toHaveBeenCalledTimes(1),
+ { timeout: 2000 },
+ );
+ expect(initialNextSlide).not.toHaveBeenCalled();
+ });
+
it("does not advance when the startup command reports an error", async () => {
mocks.localFetch.mockRejectedValue(new Error("engine not listening yet"));
mocks.spawnScreenpipe.mockResolvedValue({
diff --git a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx
index df46cbe60..3ce828590 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/engine-startup.tsx
@@ -108,6 +108,7 @@ export default function EngineStartup({ handleNextSlide }: EngineStartupProps) {
const [bootPhase, setBootPhase] = useState<BootPhaseSnapshot | null>(null);
const hasAdvancedRef = useRef(false);
+ const hasReportedReadyRef = useRef(false);
const mountTimeRef = useRef(Date.now());
// The preceding permissions screen checks macOS TCC directly before it
@@ -279,16 +280,24 @@ export default function EngineStartup({ handleNextSlide }: EngineStartupProps) {
// follow this screen added another wait before users could finish setup.
useEffect(() => {
if (state !== "running" || hasAdvancedRef.current) return;
- hasAdvancedRef.current = true;
- posthog.capture("onboarding_engine_started", {
- time_spent_ms: Date.now() - mountTimeRef.current,
- });
+ if (!hasReportedReadyRef.current) {
+ hasReportedReadyRef.current = true;
+ posthog.capture("onboarding_engine_started", {
+ time_spent_ms: Date.now() - mountTimeRef.current,
+ });
+ }
// Keep the completed progress visible briefly before advancing.
+ // Dependencies can change while this timer is pending (for example when
+ // settings finish hydrating). React then cancels this timer and re-runs the
+ // effect. Do not mark the transition complete until the replacement timer
+ // actually fires, or the completed engine screen can remain forever.
const elapsed = Date.now() - mountTimeRef.current;
const delay = Math.max(0, 1200 - elapsed);
const timer = setTimeout(async () => {
+ if (hasAdvancedRef.current) return;
+ hasAdvancedRef.current = true;
try {
await ensureDefaultPreset();
} catch {}