From da01036de5fb1d3058745f0a37b9e664224aa4ca Mon Sep 17 00:00:00 2001 From: NeuralFault <65365345+NeuralFault@users.noreply.github.com> Date: Sun, 17 May 2026 05:55:51 -0400 Subject: [PATCH 1/2] Update VRAM options in ComfyUI Removed 'normalvram' option --- StabilityMatrix.Core/Models/Packages/ComfyUI.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs index a4c34649d..2da85ceb0 100644 --- a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs +++ b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs @@ -221,10 +221,9 @@ IPipWheelService pipWheelService InitialValue = HardwareHelper.IterGpuInfo().Select(gpu => gpu.MemoryLevel).Max() switch { MemoryLevel.Low => "--lowvram", - MemoryLevel.Medium => "--normalvram", _ => null, }, - Options = ["--highvram", "--normalvram", "--lowvram", "--novram"], + Options = ["--highvram", "--lowvram", "--novram"], }, new() { From 62ab4c2e79912ced8f864053de8aa5b17edbc1e1 Mon Sep 17 00:00:00 2001 From: NeuralFault Date: Sun, 17 May 2026 20:58:29 -0400 Subject: [PATCH 2/2] Strip persisted ComfyUI --normalvram from settings.json on settings load --- .../Services/SettingsManager.cs | 61 +++++++++ .../Core/SettingsManagerTests.cs | 117 ++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 StabilityMatrix.Tests/Core/SettingsManagerTests.cs diff --git a/StabilityMatrix.Core/Services/SettingsManager.cs b/StabilityMatrix.Core/Services/SettingsManager.cs index a07ad9108..80c1ff315 100644 --- a/StabilityMatrix.Core/Services/SettingsManager.cs +++ b/StabilityMatrix.Core/Services/SettingsManager.cs @@ -460,6 +460,8 @@ public void SetEulaAccepted() /// protected virtual void LoadSettings(CancellationToken cancellationToken = default) { + var shouldPersistNormalizedSettings = false; + fileLock.Wait(cancellationToken); try @@ -478,6 +480,7 @@ protected virtual void LoadSettings(CancellationToken cancellationToken = defaul } Settings = DeserializeOrRecoverSettings(rawBytes); + shouldPersistNormalizedSettings = NormalizeLoadedSettings(Settings); } finally { @@ -485,6 +488,18 @@ protected virtual void LoadSettings(CancellationToken cancellationToken = defaul isLoaded = true; + if (shouldPersistNormalizedSettings) + { + try + { + SaveSettings(cancellationToken); + } + catch (Exception ex) + { + logger.LogWarning(ex, "Failed to persist normalized settings after load"); + } + } + Loaded?.Invoke(this, EventArgs.Empty); } } @@ -495,6 +510,8 @@ protected virtual void LoadSettings(CancellationToken cancellationToken = defaul /// protected virtual async Task LoadSettingsAsync(CancellationToken cancellationToken = default) { + var shouldPersistNormalizedSettings = false; + await fileLock.WaitAsync(cancellationToken).ConfigureAwait(false); try @@ -514,6 +531,7 @@ protected virtual async Task LoadSettingsAsync(CancellationToken cancellationTok } Settings = DeserializeOrRecoverSettings(rawBytes); + shouldPersistNormalizedSettings = NormalizeLoadedSettings(Settings); } finally { @@ -521,10 +539,53 @@ protected virtual async Task LoadSettingsAsync(CancellationToken cancellationTok isLoaded = true; + if (shouldPersistNormalizedSettings) + { + try + { + await SaveSettingsAsync(cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + logger.LogWarning(ex, "Failed to persist normalized settings after load"); + } + } + Loaded?.Invoke(this, EventArgs.Empty); } } + private bool NormalizeLoadedSettings(Settings settings) + { + var removedCount = 0; + + foreach (var package in settings.InstalledPackages) + { + if ( + package.PackageName?.StartsWith("ComfyUI", StringComparison.OrdinalIgnoreCase) != true + || package.LaunchArgs is not { Count: > 0 } + ) + { + continue; + } + + removedCount += package.LaunchArgs.RemoveAll(option => + option.Name.Equals("--normalvram", StringComparison.OrdinalIgnoreCase) + ); + } + + if (removedCount > 0) + { + logger.LogInformation( + "Removed {RemovedCount} obsolete ComfyUI launch args from loaded settings", + removedCount + ); + return true; + } + + return false; + } + /// /// Attempts to deserialize settings from raw bytes, falling back to sanitization /// and recovery if the JSON is corrupted. Returns default settings as a last resort. diff --git a/StabilityMatrix.Tests/Core/SettingsManagerTests.cs b/StabilityMatrix.Tests/Core/SettingsManagerTests.cs new file mode 100644 index 000000000..4c709187d --- /dev/null +++ b/StabilityMatrix.Tests/Core/SettingsManagerTests.cs @@ -0,0 +1,117 @@ +using System.Text.Json; +using Microsoft.Extensions.Logging.Abstractions; +using StabilityMatrix.Core.Models.Settings; +using StabilityMatrix.Core.Services; + +namespace StabilityMatrix.Tests.Core; + +[TestClass] +public class SettingsManagerTests +{ + private string? tempDirectory; + + [TestCleanup] + public void Cleanup() + { + if (tempDirectory is not null && Directory.Exists(tempDirectory)) + { + Directory.Delete(tempDirectory, recursive: true); + } + } + + [TestMethod] + public void TryFindLibrary_StripsObsoleteComfyNormalVramLaunchArgsAndPersists() + { + tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + Directory.CreateDirectory(tempDirectory); + + var settingsPath = Path.Combine(tempDirectory, "settings.json"); + File.WriteAllText( + settingsPath, + """ + { + "Version": 1, + "InstalledPackages": [ + { + "Id": "11111111-1111-1111-1111-111111111111", + "PackageName": "ComfyUI", + "LaunchArgs": [ + { + "Name": "--normalvram", + "Type": "Bool", + "OptionValue": true + }, + { + "Name": "--lowvram", + "Type": "Bool", + "OptionValue": false + } + ] + }, + { + "Id": "22222222-2222-2222-2222-222222222222", + "PackageName": "ComfyUI-Zluda", + "LaunchArgs": [ + { + "Name": "--normalvram", + "Type": "Bool", + "OptionValue": true + } + ] + }, + { + "Id": "33333333-3333-3333-3333-333333333333", + "PackageName": "OtherPackage", + "LaunchArgs": [ + { + "Name": "--normalvram", + "Type": "Bool", + "OptionValue": true + } + ] + } + ] + } + """ + ); + + var settingsManager = new SettingsManager(NullLogger.Instance); + settingsManager.SetLibraryDirOverride(tempDirectory); + + var wasFound = settingsManager.TryFindLibrary(); + + Assert.IsTrue(wasFound); + + var comfyPackage = settingsManager.Settings.InstalledPackages.Single(package => + package.PackageName == "ComfyUI" + ); + var zludaPackage = settingsManager.Settings.InstalledPackages.Single(package => + package.PackageName == "ComfyUI-Zluda" + ); + var otherPackage = settingsManager.Settings.InstalledPackages.Single(package => + package.PackageName == "OtherPackage" + ); + + Assert.IsFalse(comfyPackage.LaunchArgs!.Any(option => option.Name == "--normalvram")); + Assert.IsFalse(zludaPackage.LaunchArgs!.Any(option => option.Name == "--normalvram")); + Assert.IsTrue(otherPackage.LaunchArgs!.Any(option => option.Name == "--normalvram")); + + var persistedSettings = JsonSerializer.Deserialize(File.ReadAllText(settingsPath)); + + Assert.IsNotNull(persistedSettings); + + var persistedComfyPackage = persistedSettings.InstalledPackages.Single(package => + package.PackageName == "ComfyUI" + ); + var persistedZludaPackage = persistedSettings.InstalledPackages.Single(package => + package.PackageName == "ComfyUI-Zluda" + ); + var persistedOtherPackage = persistedSettings.InstalledPackages.Single(package => + package.PackageName == "OtherPackage" + ); + + Assert.IsFalse(persistedComfyPackage.LaunchArgs!.Any(option => option.Name == "--normalvram")); + Assert.IsFalse(persistedZludaPackage.LaunchArgs!.Any(option => option.Name == "--normalvram")); + Assert.IsTrue(persistedOtherPackage.LaunchArgs!.Any(option => option.Name == "--normalvram")); + } +}