Improved settings recovery with backup-based fallbacks

This commit is contained in:
Thorsten Sommer 2026-06-21 18:26:27 +02:00
parent b064eab9cb
commit 26172ce43a
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 18 additions and 4 deletions

View File

@ -120,13 +120,13 @@ public sealed class SettingsManager
if(settingsVersion.FailureReason is not SettingsWriteBlockReason.NONE) if(settingsVersion.FailureReason is not SettingsWriteBlockReason.NONE)
{ {
this.BlockSettingsWrites(settingsVersion.FailureReason, "The settings file version could not be identified. Settings writes are blocked to avoid overwriting newer or unreadable settings."); this.BlockSettingsWrites(settingsVersion.FailureReason, "The settings file version could not be identified. Settings writes are blocked to avoid overwriting newer or unreadable settings.");
return null; return await this.TryReadCurrentVersionBackupSnapshotForBlockedSettings();
} }
if(settingsVersion.Version > CURRENT_SETTINGS_VERSION) if(settingsVersion.Version > CURRENT_SETTINGS_VERSION)
{ {
this.BlockSettingsWrites(SettingsWriteBlockReason.VERSION_NEWER_THAN_APP, $"The settings file uses the newer version '{settingsVersion.Version}'. Settings writes are blocked to avoid overwriting newer settings."); this.BlockSettingsWrites(SettingsWriteBlockReason.VERSION_NEWER_THAN_APP, $"The settings file uses the newer version '{settingsVersion.Version}'. Settings writes are blocked to avoid overwriting newer settings.");
return null; return await this.TryReadCurrentVersionBackupSnapshotForBlockedSettings();
} }
Data? settingsData; Data? settingsData;
@ -154,7 +154,7 @@ public sealed class SettingsManager
if(currentSettings.FailureReason is not SettingsWriteBlockReason.NONE) if(currentSettings.FailureReason is not SettingsWriteBlockReason.NONE)
{ {
this.BlockSettingsWrites(currentSettings.FailureReason, "The current settings file could not be safely loaded. Settings writes are blocked to avoid overwriting recoverable settings."); this.BlockSettingsWrites(currentSettings.FailureReason, "The current settings file could not be safely loaded. Settings writes are blocked to avoid overwriting recoverable settings.");
return null; return await this.TryReadCurrentVersionBackupSnapshotForBlockedSettings();
} }
settingsData = currentSettings.SettingsData!; settingsData = currentSettings.SettingsData!;
@ -231,6 +231,20 @@ public sealed class SettingsManager
return backupSettings.SettingsData; return backupSettings.SettingsData;
} }
private async Task<Data?> TryReadCurrentVersionBackupSnapshotForBlockedSettings()
{
var settingsData = await this.TryReadCurrentVersionBackupSnapshot();
if(settingsData is null)
{
this.logger.LogWarning($"No valid current-version settings backup was found while settings writes are blocked. Reason: '{this.SettingsWriteBlockReason}'.");
return null;
}
this.PrepareLoadedSettings(settingsData);
this.logger.LogWarning($"Loaded settings from the '{GetBackupSettingsFilename(CURRENT_SETTINGS_VERSION)}' backup file while settings writes remain blocked. Reason: '{this.SettingsWriteBlockReason}'.");
return settingsData;
}
private async Task<CurrentSettingsReadResult> TryDeserializeCurrentSettings(string settingsPath, string sourceDescription) private async Task<CurrentSettingsReadResult> TryDeserializeCurrentSettings(string settingsPath, string sourceDescription)
{ {
try try

View File

@ -7,5 +7,5 @@
- Changed provider confidence settings to appear in their own settings panel, because they apply to LLM, embedding, and transcription providers. - Changed provider confidence settings to appear in their own settings panel, because they apply to LLM, embedding, and transcription providers.
- Fixed chat provider, profile, and template selections not updating live after configuration plugins were changed. - Fixed chat provider, profile, and template selections not updating live after configuration plugins were changed.
- Fixed organization-managed chat templates not showing the correct icon in the chat template selection menu. - Fixed organization-managed chat templates not showing the correct icon in the chat template selection menu.
- Fixed personal settings sometimes being lost after a settings-format upgrade when an older app version was started again. AI Studio now keeps versioned settings backups, restores them automatically when needed, and warns users when settings cannot be saved safely. - Fixed personal settings sometimes being lost after a settings-format upgrade when an older app version was started again. AI Studio now keeps versioned settings backups, restores the latest compatible backup when needed, and warns users when settings cannot be saved safely.
- Fixed self-hosted provider API keys sometimes being stored under a localized name. AI Studio now uses a stable key name, keeps correct entries working, and automatically migrates known localized entries for LLM, transcription, and embedding providers. Organizations using configuration plugins do not need to change their plugins; affected users who still see an invalid API key warning should open the provider, transcription, or embedding settings and update the API key once. Thanks, Tim & Eric, for the detailed bug report and testing help. - Fixed self-hosted provider API keys sometimes being stored under a localized name. AI Studio now uses a stable key name, keeps correct entries working, and automatically migrates known localized entries for LLM, transcription, and embedding providers. Organizations using configuration plugins do not need to change their plugins; affected users who still see an invalid API key warning should open the provider, transcription, or embedding settings and update the API key once. Thanks, Tim & Eric, for the detailed bug report and testing help.