| .. | .. |
|---|
| 99 | 99 | |
|---|
| 100 | 100 | /// Switch to a new session and load its messages. |
|---|
| 101 | 101 | Future<void> switchSession(String sessionId) async { |
|---|
| 102 | | - // Force-flush current session to disk before switching |
|---|
| 102 | + // Write current session DIRECTLY to disk (no debounce — prevents data loss) |
|---|
| 103 | 103 | if (_currentSessionId != null && state.isNotEmpty) { |
|---|
| 104 | | - MessageStore.save(_currentSessionId!, state); |
|---|
| 105 | | - await MessageStore.flush(); |
|---|
| 104 | + await MessageStore.writeDirect(_currentSessionId!, state); |
|---|
| 106 | 105 | } |
|---|
| 107 | 106 | |
|---|
| 108 | 107 | _currentSessionId = sessionId; |
|---|