docs: update DEBUGGING.md with config race condition fix

This commit is contained in:
2026-02-06 22:41:00 -08:00
committed by Naomi Carrigan
parent 2c64ef089e
commit e8b8ee17fa
+30 -1
View File
@@ -62,8 +62,37 @@ console.log("[Tauri Listener] message");
- Config file gets reset to defaults - Config file gets reset to defaults
- Settings don't persist between sessions - Settings don't persist between sessions
- Model selection is lost - Model selection is lost
- Config appears to work, then randomly resets
**POTENTIAL CAUSES:** **ACTUAL ROOT CAUSE (FIXED!):**
The config store had a **critical race condition bug** in `src/lib/stores/config.ts`. The pattern used everywhere was:
```typescript
// ❌ BUGGY CODE
let currentConfig = defaultConfig;
config.subscribe((c) => (currentConfig = c))(); // <-- Immediate unsubscribe!
return currentConfig;
```
**Why this caused config loss:**
- The `()` at the end immediately unsubscribes from the store
- This creates a race condition - sometimes you get the value, sometimes you don't
- When it fails, it returns `defaultConfig` instead of your actual config
- This is why your settings would randomly disappear!
**The fix:**
```typescript
// ✅ CORRECT CODE
function getCurrentConfig(): HikariConfig {
let currentConfig: HikariConfig = defaultConfig;
const unsubscribe = config.subscribe((c) => (currentConfig = c));
unsubscribe(); // <-- Proper cleanup after getting value
return currentConfig;
}
```
**POTENTIAL CAUSES (if the above is fixed):**
### 1. Missing `#[serde(default)]` Attribute ### 1. Missing `#[serde(default)]` Attribute