Skip to content

fix: clean up stale generationSession on failure#194

Open
YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/stale-generation-session-cleanup
Open

fix: clean up stale generationSession on failure#194
YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
YizukiAme:fix/stale-generation-session-cleanup

Conversation

@YizukiAme
Copy link
Contributor

Summary

Fixes stale generationSession in sessionStorage causing false Tavily error on retry.

Problem

When generation fails (e.g. missing Tavily API key), the generationSession in sessionStorage is not cleaned up. On page refresh, the old session with webSearch: true is reloaded and the web search step is re-triggered, producing a confusing Tavily error even if web search was disabled for the new attempt.

Fix

Added sessionStorage.removeItem('generationSession') in the catch block of startGeneration(), so failed sessions are cleaned up and don't replay stale settings.

Testing

  • One-line change, no side effects
  • tsc --noEmit passes

Closes #185

@YizukiAme YizukiAme force-pushed the fix/stale-generation-session-cleanup branch from ce5128f to 4227c6f Compare March 21, 2026 09:06
Closes THU-MAIC#185

When generation fails, the session was left in sessionStorage, causing
stale settings (e.g. webSearch: true) to replay on page refresh. Now
sessionStorage.removeItem('generationSession') is called in the catch
block so failed sessions are cleaned up.
@YizukiAme YizukiAme force-pushed the fix/stale-generation-session-cleanup branch from 4227c6f to 977eb4a Compare March 21, 2026 17:06
@wyuc
Copy link
Contributor

wyuc commented Mar 22, 2026

Thanks for the fix. One question before merging:

In the normal user flow, if someone goes back to the homepage and reconfigures (e.g. disables web search), page.tsx:295 overwrites sessionStorage synchronously before router.push, so the old session is always replaced. And if they just refresh /generation-preview, that's a retry with the same config — getting the same Tavily error is expected, not "false."

Could you clarify the exact reproduction path where a user disables web search but still hits the stale session? I might be missing something.

The cleanup itself is good hygiene regardless — just want to make sure the issue description matches the actual bug.

@YizukiAme
Copy link
Contributor Author

Thanks for the fix. One question before merging:

In the normal user flow, if someone goes back to the homepage and reconfigures (e.g. disables web search), page.tsx:295 overwrites sessionStorage synchronously before router.push, so the old session is always replaced. And if they just refresh /generation-preview, that's a retry with the same config — getting the same Tavily error is expected, not "false."

Could you clarify the exact reproduction path where a user disables web search but still hits the stale session? I might be missing something.

The cleanup itself is good hygiene regardless — just want to make sure the issue description matches the actual bug.

Thanks for the thorough review!! I originally ran into this during development — I was getting an unexpected Tavily error even though I hadn't configured or enabled web search at all, and after digging through DevTools I found that manually clearing generationSession from sessionStorage resolved it. It happened a few more times after that, so I suspected it was caused by a previously Tavily-enabled session lingering around. 🤔

The reproduction steps in the issue may not be fully accurate — the root cause might be tied to development-specific scenarios that I can't pinpoint exactly right now...? But after applying this one-line fix, I haven't run into the issue again, and the change is minimal.

If you'd like, I can try to track down and reproduce the exact trigger more rigorously. 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants