Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend/onboarding): leave the brain dump on the first Skip click, and only once (#15927)

Reinier van der Leer2649128836ab
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx
index 7c15aa1a75..71fb00f143 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/brain-dump.test.tsx
@@ -347,6 +347,32 @@ function finalizeReturns(response: {
return bodies;
}
+// A voice take is judged too thin, and the skip's record goes unanswered
+// until `release()`, so any step change that waits on it never happens.
+function holdSkipRecord() {
+ const skipBodies: unknown[] = [];
+ let release!: () => void;
+ const held = new Promise<void>((resolve) => {
+ release = resolve;
+ });
+ server.use(
+ getFinalizeBrainDumpMockHandler200(async (info) => {
+ const body = (await info.request.json()) as { input_mode: string };
+ if (body.input_mode !== "skipped") {
+ return {
+ status: "failed" as const,
+ error_code: "insufficient_content",
+ input_mode: "voice" as const,
+ };
+ }
+ skipBodies.push(body);
+ await held;
+ return { status: "completed" as const, input_mode: "skipped" as const };
+ }),
+ );
+ return { skipBodies, release };
+}
+
// Lands the wizard on the step the pillboxes / the brain dump share.
function landOnPainPointsStep() {
window.sessionStorage.setItem(
@@ -497,6 +523,30 @@ describe("onboarding brain dump — skip", () => {
expect(await screen.findByTestId("step-hire")).toBeDefined();
expect(window.sessionStorage.getItem(INTRO_PATH_KEY)).toBe("B");
});
+
+ // SECRT-2982: while the first skip waited on its record the button stayed
+ // up, the second click recorded a second skip, and both advanced past Hire.
+ it("moves to Hire on the click, once, however often it is clicked", async () => {
+ const skip = holdSkipRecord();
+ landOnPainPointsStep();
+
+ render(<OnboardingPage />);
+ await screen.findByText(DUMP_HEADLINE);
+
+ await userEvent.dblClick(
+ screen.getByRole("button", { name: "Skip for now" }),
+ );
+
+ expect(await screen.findByTestId("step-hire")).toBeDefined();
+ await waitFor(() => expect(skip.skipBodies).toHaveLength(1));
+ skip.release();
+ // Room for a second skip's advance to land, had one been sent.
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ expect(skip.skipBodies).toHaveLength(1);
+ expect(useOnboardingWizardStore.getState().currentStep).toBe(
+ NO_PAYWALL_STEPS.hire,
+ );
+ });
});
describe("onboarding brain dump — finishing a take", () => {
@@ -828,6 +878,24 @@ describe("onboarding brain dump — insufficient content", () => {
expect(recordingStoreState.parts).toHaveLength(1);
});
+ it("moves on from 'Continue without it' before the skip is recorded", async () => {
+ const skip = holdSkipRecord();
+
+ await recordAndSend();
+ await screen.findByText("We didn't catch enough of that.");
+ await userEvent.click(
+ screen.getByRole("button", { name: "Continue without it" }),
+ );
+
+ expect(await screen.findByTestId("step-hire")).toBeDefined();
+ expect(window.sessionStorage.getItem(INTRO_PATH_KEY)).toBe("B");
+ await waitFor(() => expect(skip.skipBodies).toHaveLength(1));
+ // Already gone while the record is unanswered, so Back to the step
+ // cannot offer the abandoned take again.
+ expect(recordingStoreState.parts).toHaveLength(0);
+ skip.release();
+ });
+
it("opens the typed composer from the recovery screen", async () => {
finalizeReturns({ status: "failed", error_code: "no_usable_speech" });
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpRecorder.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpRecorder.test.ts
index 3e2c5e94f2..4138c7a10b 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpRecorder.test.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpRecorder.test.ts
@@ -48,6 +48,7 @@ vi.mock("@/services/onboarding/brain-dump-analytics", () => ({
trackBrainDump: vi.fn(),
}));
+import { saveMeta } from "../recordingStore";
import { useBrainDumpRecorder } from "../useBrainDumpRecorder";
// Stopping is not instant: `onstop` fires after the encoder drains, and
@@ -588,4 +589,45 @@ describe("useBrainDumpRecorder", () => {
expect(track.stop).toHaveBeenCalled();
});
+
+ // Back, or a skip while "Record again" runs, can leave the step while the
+ // mic is still opening; the unmount cleanup has already run by then.
+ it.each(["the permission prompt", "the take's first record"])(
+ "closes a microphone the step left during %s",
+ async (gate) => {
+ vi.stubGlobal("MediaRecorder", ChunkingMediaRecorder);
+ ChunkingMediaRecorder.latest = null;
+ const track = { stop: vi.fn() };
+ let release!: () => void;
+ const held = new Promise<void>((resolve) => {
+ release = resolve;
+ });
+ stubGetUserMedia(
+ vi.fn(async () => {
+ if (gate === "the permission prompt") await held;
+ return { getTracks: () => [track] };
+ }),
+ );
+ if (gate === "the take's first record") {
+ vi.mocked(saveMeta).mockImplementationOnce(() => held);
+ }
+ const { result, unmount } = renderHook(() => useBrainDumpRecorder());
+
+ const starting = result.current.start();
+ await act(async () => {
+ for (let tick = 0; tick < 10; tick++) await Promise.resolve();
+ });
+ unmount();
+ let started: boolean | undefined;
+ await act(async () => {
+ release();
+ started = await starting;
+ });
+
+ expect(started).toBe(false);
+ expect(track.stop).toHaveBeenCalled();
+ expect(ChunkingMediaRecorder.latest).toBeNull();
+ expect(savedMeta).toEqual([]);
+ },
+ );
});
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts
index 91c70c4720..56b84d3e73 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/__tests__/useBrainDumpStep.test.ts
@@ -984,6 +984,58 @@ describe("useBrainDumpStep — skip", () => {
expect(window.sessionStorage.getItem(INTRO_PATH_KEY)).toBe("A");
});
+ // The wizard moves on before the skip is recorded, so the guard is all
+ // that stops a second skip from advancing it again, past Hire.
+ it("advances once when a second skip lands before the first is recorded", async () => {
+ const recording = deferred<ReturnType<typeof completed>>();
+ finalizeBrainDump.mockReturnValue(recording.promise);
+ const { result } = await renderStep();
+
+ await act(async () => {
+ void result.current.handleSkip();
+ void result.current.handleSkip();
+ await Promise.resolve();
+ });
+ await act(async () => {
+ recording.resolve(completed());
+ await Promise.resolve();
+ });
+
+ expect(finalizeBrainDump).toHaveBeenCalledTimes(1);
+ expect(useOnboardingWizardStore.getState().currentStep).toBe(2);
+ });
+
+ // Back from Hire remounts the step while the skipped take may still be
+ // unfinalized on disk; offering it there would hand back what was refused.
+ it("does not offer back a skipped take whose cleanup is still running", async () => {
+ recorderState.recordingId = "rec-skipped";
+ const lookup = deferred<null>();
+ getMetaById.mockReturnValueOnce(lookup.promise);
+ const first = await renderStep();
+ await act(async () => {
+ void first.result.current.handleSkip();
+ await Promise.resolve();
+ });
+ first.unmount();
+
+ recorderState.recordingId = null;
+ recorderState.findRecoverable.mockResolvedValue({
+ recordingId: "rec-skipped",
+ mimeType: "audio/webm",
+ durationSecs: 30,
+ });
+ getParts.mockResolvedValue([part(0, "rec-skipped")]);
+ const back = await renderStep();
+
+ expect(back.result.current.screen).toBe("rest");
+ expect(back.result.current.recoverable).toBeNull();
+
+ await act(async () => {
+ lookup.resolve(null);
+ await Promise.resolve();
+ });
+ });
+
// Being unable to say "no thanks" because the network is down would be
// absurd — path B is the safe default anyway.
it("lets the user through even when the skip call fails", async () => {
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpRecorder.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpRecorder.ts
index f3a4395dd6..d2910a5556 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpRecorder.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpRecorder.ts
@@ -69,7 +69,14 @@ export function useBrainDumpRecorder() {
const queue = useUploadQueue();
- useEffect(() => stopTracks, []);
+ const unmountedRef = useRef(false);
+ useEffect(() => {
+ unmountedRef.current = false;
+ return () => {
+ unmountedRef.current = true;
+ stopTracks();
+ };
+ }, []);
function stopTracks() {
if (timerRef.current) clearInterval(timerRef.current);
@@ -121,6 +128,12 @@ export function useBrainDumpRecorder() {
}
return false;
}
+ // Back during the prompt, or a skip during "Record again", can leave the
+ // step before the mic opens, and its unmount cleanup has already run.
+ if (unmountedRef.current) {
+ stream.getTracks().forEach((track) => track.stop());
+ return false;
+ }
const recordingId = newRecordingId();
const mimeType = pickMimeType();
@@ -145,6 +158,10 @@ export function useBrainDumpRecorder() {
durationSecs: 0,
finalized: false,
});
+ if (unmountedRef.current) {
+ stopTracks();
+ return false;
+ }
const recorder = new MediaRecorder(stream, { mimeType });
recorder.ondataavailable = function handleChunk(event) {
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts
index 7eaecf5c0c..ee0f9dcebc 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/BrainDumpStep/useBrainDumpStep.ts
@@ -29,6 +29,10 @@ export type ScreenState =
| "failed"
| "insufficient";
+// Takes a skip left behind whose local cleanup is still running. Module scope,
+// so the remount that Back from Hire causes does not offer one back.
+const releasingTakeIDs = new Set<string>();
+
export function useBrainDumpStep() {
const nextStep = useOnboardingWizardStore((s) => s.nextStep);
const setStepBusy = useOnboardingWizardStore((s) => s.setStepBusy);
@@ -57,7 +61,8 @@ export function useBrainDumpStep() {
const retryCountRef = useRef(0);
// A submit in flight owns the screen: "Skip for now" must not race
// `completeAndAdvance` to `nextStep()`, or the wizard advances twice and
- // lands past the last step with nothing to render.
+ // lands past the last step with nothing to render. A skip takes it for
+ // good, since it leaves the step.
const isSubmittingRef = useRef(false);
const activeTakeActionRef = useRef<{
action: "submit" | "discard";
@@ -67,7 +72,7 @@ export function useBrainDumpStep() {
useEffect(() => {
async function checkForRecovery() {
const meta = await recorder.findRecoverable();
- if (!meta) return;
+ if (!meta || releasingTakeIDs.has(meta.recordingId)) return;
const parts = await getParts(meta.recordingId).catch(() => []);
if (parts.length === 0) return;
setRecoverable(meta);
@@ -328,13 +333,25 @@ export function useBrainDumpStep() {
}
async function handleSkip() {
- // A skip that lands while the dump is being submitted would advance
- // the wizard a second time behind `completeAndAdvance`.
+ // A skip that lands while the dump is being submitted, or behind
+ // another skip, would advance the wizard a second time, past Hire.
if (isSubmittingRef.current) return;
+ isSubmittingRef.current = true;
trackBrainDump("brain_dump_skipped");
const recordedId = recorder.recordingId;
- // Best effort: a failed skip-record still has to let the user
- // through — being unable to say "no thanks" would be absurd.
+ recorder.resetQueue();
+ setIntroPath("B");
+ if (recordedId) releasingTakeIDs.add(recordedId);
+ // Nothing below can change where a skip goes, so the user is not kept
+ // waiting on it.
+ nextStep();
+ // Someone who talked for minutes and then skipped leaves multi-MB
+ // blobs behind, and an unfinalized meta row makes the next visit
+ // offer back a take they explicitly abandoned.
+ if (recordedId) {
+ await releaseTake(recordedId);
+ releasingTakeIDs.delete(recordedId);
+ }
try {
await finalizeBrainDump({
recording_id: recordedId ?? crypto.randomUUID(),
@@ -343,18 +360,11 @@ export function useBrainDumpStep() {
} catch {
// Path B is the safe default anyway.
}
- // Someone who talked for minutes and then skipped leaves multi-MB
- // blobs behind, and an unfinalized meta row makes the next visit
- // offer back a take they explicitly abandoned.
if (recordedId) {
- await releaseTake(recordedId);
await discardBrainDump({ recording_id: recordedId }).catch(
() => undefined,
);
}
- recorder.resetQueue();
- setIntroPath("B");
- nextStep();
}
// IndexedDB is only cleared once the server has confirmed the dump —