Skip to content

feat(memory): add two-tier engine cache lifetime management and host RAM telemetry (#97, #98) - #100

Merged
spelech merged 10 commits into
mainfrom
feat/memory-cache-lifetimes-and-ram-telemetry
Oct 28, 2026
Merged

spelech merged 10 commits into
mainfrom
feat/memory-cache-lifetimes-and-ram-telemetry

Conversation

@spelech

@spelech spelech commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Summary

Implements Phase 1 (#97) (Engine & model cache lifetime management with configurable two-tier idle TTL and host RAM pressure relief) and Phase 2 (#98) (Host System RAM, Process Working Set, and Windows Non-Paged Kernel Pool telemetry + Unified Hardware Pill UI).

Closes #97
Closes #98

Phase 1: Two-Tier Idle Cache Eviction & Host RAM Pressure Relief (#97)

  • Settings (AppSettings.cs):
    • ModelCacheIdleTimeoutMinutes (default: 15, 0 = disabled)
    • EngineHibernationTimeoutMinutes (default: 30, 0 = disabled)
    • RamPressureThresholdPercent (default: 75, clamped 50..95)
  • Activity Tracking & Two-Tier Eviction (VramOrchestrator.cs & Program.cs):
    • Tracks per-engine activity (ollama, comfy, forge, audio) both before and after proxy middleware execution (try...finally) and on explicit engine start endpoints.
    • Tier 1 (Model Weight Unload — 15m default): Evicts Ollama loaded models (keep_alive = 0) and invokes ComfyUI POST /free ({"unload_models": true, "free_memory": true}).
    • Tier 2 (Child Engine Hibernation — 30m default): Terminates dormant child engine processes (ComfyUI, SD Forge, Kokoro) while keeping LocalLLMServerManager ready to auto-wake them on the next request.
    • Host RAM Pressure Relief (75% default): Immediately triggers Tier 1 weight eviction and Tier 2 hibernation for engines idle >= 2 minutes when host physical RAM usage reaches or exceeds the configured threshold.
  • Background Watchdog & Manual Purge (MemoryLifecycleWatchdog.cs & EngineEndpoints.cs):
    • Registered MemoryLifecycleWatchdog (BackgroundService, 30s tick with TimeProvider support) to evaluate cache lifetimes continuously.
    • Added POST /api/memory/purge and POST /api/v1/engines/purge-memory (PurgeAllMemoryCachesAsync) to force immediate model unload, idle engine hibernation, and managed GC.Collect(2, GCCollectionMode.Aggressive, true, true).

Phase 2: Host RAM, Process Working Set & Kernel Pool Telemetry + UI (#98)

  • Telemetry Provider (GpuTelemetryProvider.cs & IGpuTelemetryProvider.cs):
    • Added cross-platform GetSystemMemoryInfo() using Windows GlobalMemoryStatusEx (kernel32.dll) and GetPerformanceInfo (psapi.dll) for host physical RAM and Windows Non-Paged Kernel Pool (KernelNonpaged), Linux /proc/meminfo parsing, and GC.GetGCMemoryInfo() fallback.
    • Aggregates working set across LocalLLMServerManager and managed child engine processes (ComfyProcess, ForgeProcess, AudioProcess, OllamaProcess).
    • Expanded /api/gpu/vram and /api/v1/hardware/vram with totalRamBytes, usedRamBytes, totalRamGB, usedRamGB, ramPercent, processWorkingSetMB, nonPagedPoolMB, and active cache lifetime settings while preserving backward-compatible VRAM fields.
  • Unified Hardware Pill & Settings UI (TelemetryRibbonControl.axaml & SettingsTabControl.axaml):
    • Upgraded the 34px titlebar hardware pill to display dual compact VRAM and RAM progress bars (VRAM 0.9/16.0G | RAM 14.8/31.7G), a rich multi-line breakdown tooltip (HardwareTooltipText), and a one-click Purge Memory button (PurgeMemoryCommand).
    • Added the Memory & Cache Lifetimes configuration card to SettingsTabControl.axaml (Engines & Paths category).

Verification

  • npm run lint: 0 errors
  • npx tsc --noEmit: 0 errors
  • dotnet test LocalLLMServerManager.Tests/LocalLLMServerManager.Tests.csproj: 935 passed, 0 failed, 18 skipped
  • Playwright WASM E2E (PlaywrightWasmE2ETests) verified across Chromium and Firefox (including page.reload(), <canvas> pixel verification, /api/gpu/vram schema validation, and Purge button click interaction).
  • Documentation screenshots (docs/images/dashboard_*.png, including dashboard_settings_engines.png) regenerated and visually inspected.

@spelech
spelech merged commit c56d367 into main Oct 28, 2026
@spelech
spelech deleted the feat/memory-cache-lifetimes-and-ram-telemetry branch October 28, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant