fix(ui/security): Enforce idempotent AI fetching, secure auth handler, and memory leak guards #45
Reference in New Issue
Block a user
Delete Branch "fix/idempotent-ai-fetching"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR provides critical stabilization, memory leak resolution, and security enhancements for the NexusReader application, specifically focusing on Blazor InteractiveAuto lifecycle safety, thread-safe automated authentication token refresh, and deduplication of active AI service queries.
Key Enhancements
1. Security & Lifecycle Stabilization (
AuthenticationHeaderHandler.cs&Library.razor)NavigationManager.BaseUri, preventing potential token leakage to external services.IIdentityServiceinside a dedicated, disposableIServiceProviderscope (_serviceProvider.CreateScope()).SemaphoreSlimlock around the automatedRefreshTokenAsyncrenewal sequence to handle concurrent API requests gracefully without triggering duplicate token refresh attempts.Library.razorfromOnInitializedAsyncto client-sideOnAfterRenderAsync(firstRender: true)to avoid inevitable401 Unauthorizedresponses and logs during the server pre-rendering phase.2. Robust AI Request Deduplication (
KnowledgeService.cs)Lazy<Task<Result<KnowledgePacket>>>deduplication map by adding thorough failure handling blocks. Active requests are guaranteed to be cleaned up (TryRemove) insidefinallyand failed results pathways, ensuring future retries can run immediately if an initial request encounters an error.3. Idempotent AI UI Fetching & JSRuntime Guards
_isInteractivecheck toGroundednessBadge.razorandAiAssistantBubble.razorcomponents, deferring WebAssembly API executions and DOM updates to client-sideOnAfterRenderAsync.OnParametersSetto properly reset groundedness badges when content changes.Home.razor(for focus mode preferences) toOnAfterRenderAsync(firstRender: true), resolving startup JSInterop exceptions and eliminating layout shifts.Verification Performed
Kompilacja powiodła się.with zero compile errors (dotnet build NexusReader.slnx --no-restore).async void).fix(ui): Enforce idempotent AI data fetching and JSRuntime guardsto fix(ui/security): Enforce idempotent AI fetching, secure auth handler, and memory leak guards