Fix memory leak, singleton session isolation, progress simulation, and settings validation#54
Draft
Fix memory leak, singleton session isolation, progress simulation, and settings validation#54
Conversation
…validation Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [Feature] Fix memory leak in upload service callback map
Fix memory leak, singleton session isolation, progress simulation, and settings validation
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four reliability issues across upload lifecycle, session isolation, UX accuracy, and storage safety — plus a race condition in offscreen document creation.
Changes
UploadService.ts— callback memory leak + progress simulationonUploadComplete()now returns an unsubscribe function; previously callbacks were inserted with a unique key but never removed, causing unbounded map growth and duplicate badge updates across restarts+0.1steps with exponential decay(0.9 - current) * 0.1per tick — bar no longer jumps to 90% and stalls for slow uploadsNumbersApiManager.ts— singleton session isolationresetNumbersApi()which nulls the module-levelinstanceclearAuth()calls it automatically — logout now guarantees the next session gets a clean singleton with no stale queue or callbacks from the previous userStorageService.ts— storage boundary validationprivate validateSettings()called by bothsetSettings()andupdateSettings()screenshotQualitymust be a number in[0, 100];huntModeMessageandhuntModeHashtagscapped at 280 characters (null-safe); invalid values throw before reaching storageservice-worker.ts— offscreen document race conditionensureOffscreenDocument()calls via a module-level promise lock (offscreenDocumentPromise); concurrent callers (e.g. watermark + geolocation) now await the same in-flight promise instead of both racing past the context check and hittingcreateDocumenttwiceOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.