fix: prevent localStorage quota overflow in plugin safety cache#1326
Open
OnlookerRs wants to merge 1 commit intokwaroran:mainfrom
Open
fix: prevent localStorage quota overflow in plugin safety cache#1326OnlookerRs wants to merge 1 commit intokwaroran:mainfrom
OnlookerRs wants to merge 1 commit intokwaroran:mainfrom
Conversation
cubicj
approved these changes
Apr 8, 2026
Collaborator
cubicj
left a comment
There was a problem hiding this comment.
Verified. The try-catch + purge-and-retry correctly downgrades the crash into a one-time cache rebuild, and the read path also cleans stale entries. safety- prefix is only used here, so purge is safe.
One thing left open: orphan entries from old plugin versions still accumulate until the quota is hit. This fix reacts when that happens, but doesn't prevent the buildup itself. Worth considering as a follow-up, but out of scope here.
Approving — thanks for the contribution!
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.
PR Checklist
Summary
checkCodeSafetyinpluginSafety.tsstores the fullmodifiedCodein localStorage for each plugin, keyed by code hash (safety-${hash}). When plugins are updated, old entries are never removed and new ones accumulate indefinitely. Once localStorage quota is exceeded, the unhandledQuotaExceededErrorfromlocalStorage.setItemcrashescheckCodeSafety, which in turn crashesloadV2Plugin, preventing all plugins (including V3) from loading.This affects all platforms, environments with smaller quotas (e.g. Safari iOS at 5 MB) hit it sooner, but any environment will eventually reach the limit given enough plugin updates.
Related Issues
None
Changes
localStorage.getItem+JSON.parse) in try-catch; removes stale entry on checkerVersion mismatch or parse failurelocalStorage.setItem) in try-catch; on quota error, purges allsafety-*entries and retries oncepurgeSafetyCachehelper that removes allsafety-*localStorage entries except an optional keep keyImpact
safety-*keys are touched; no other localStorage data is affectedAdditional Notes
The
safety-*cache entries can be large (hundreds of KB each for big plugins) because they store the entire transformed source code. A single large plugin updated a few times can consume over 1 MB of orphaned cache entries. This fix is reactive (purge on quota error) rather than proactive, keeping the change minimal and preserving the existing caching strategy.Footnotes
Modifies the behavior of prompting, requesting, or handling responses from AI models. ↩
Over 80% of the code is AI generated. ↩