CodeIssuesPull RequestsActionsSecurityInsights
✨ AI
More
Settings

fix: duplicate session saves and API key loss on fast app close #4733

Merged⚡ AI-generatedXSccantynz wants to mergeclaude/inspiring-curie-xd4n0bmainopened Jun 21, 20260/4 tasks
ccantynzcommented Jun 21, 2026

Originally written by @ccantynz-alt on GitHub.
Imported from https://github.com/ccantynz-alt/voxlen/pull/68


Summary

Two critical data-integrity bugs fixed.

1. Duplicate history / flywheel / billable entries on Stop

DictationPanel.handleToggleDictation was recording history, flywheel session, and billable time directly when the user clicked Stop. Then setStatus("idle") triggered the autosave subscription in useTauriEvents, which did exactly the same thing. The dedup guard (alreadyInHistory text-equality check) failed whenever a grammar correction updated correctedText between the two saves — different strings, duplicate entries, double-billed time.

Fix: removed the duplicate recording from the button handler entirely. The autosave subscription in useTauriEvents is now the single source of truth for all session recording. Also removed the now-unused useHistoryStore import from DictationPanel.

2. API key silently lost if app closes within 500ms of entry

updateSetting() debounces all persistence 500ms via schedulePersist(). Entering an API key and immediately closing the app (or the app crashing) cancelled the timer before the keychain write fired — key gone on next startup.

Fix: for sttApiKey, grammarApiKey, and voxlenApiKey, updateSetting now writes to the OS keychain immediately in addition to scheduling the debounced persist.

Test plan

  • 179 tests pass
  • TypeScript clean
  • Click Stop dictation → exactly one history entry, one flywheel session, one billable entry per session
  • Enter API key, force-quit app immediately, relaunch → key still present

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ggw2m7nwT2HDNaQJqSX6Sp


Generated by Claude Code

Cross-repo impact

See what breaks downstream if this PR merges.

Analyze →
⮌ Merged

This pull request was merged into main.

c comment · e edit title · m merge · a approve · r request changes · ? shortcuts