Skip to content

[Bug]: Stale generationSession in sessionStorage causes false Tavily error on retry #185

@YizukiAme

Description

@YizukiAme

Bug Description

When a classroom generation fails on the /generation-preview page (e.g., due to a missing Tavily API key), the stale generationSession in sessionStorage is not cleaned up.

If the user then refreshes the page or navigates back to /generation-preview, the old session (with webSearch: true) is reloaded and the web search step is re-triggered — even if the user didn't enable web search this time. This produces a confusing error:

Tavily API key is not configured. Set it in Settings → Web Search or set TAVILY_API_KEY env var.

Root Cause

In app/generation-preview/page.tsx, the catch block (line ~727) does not call sessionStorage.removeItem('generationSession'). The session is only cleaned up on success (line 724) or when the user clicks "Back" (line 747).

Steps to Reproduce

  1. Enable "Web Search" in generation settings (without configuring a Tavily API key)
  2. Start classroom generation → it will fail with the Tavily error
  3. Go back to the homepage, disable "Web Search", and start a new generation
  4. Refresh the /generation-preview page → the old session with webSearch: true is loaded → same Tavily error appears

Expected Behavior

Failed generation sessions should be cleaned up so that refreshing /generation-preview doesn't replay stale settings.

Suggested Fix

Add sessionStorage.removeItem('generationSession') in the catch block of startGeneration():

     } catch (err) {
       if (err instanceof DOMException && err.name === 'AbortError') {
         log.info('[GenerationPreview] Generation aborted');
         return;
       }
+      sessionStorage.removeItem('generationSession');
       setError(err instanceof Error ? err.message : String(err));
     }

Deployment Method

Local development (pnpm dev)

Browser

Chrome


Note: This is a one-line fix — just add sessionStorage.removeItem('generationSession') in the catch block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions