Fix concurrency bugs in unclose MV3 migration#25
Merged
Conversation
5 tasks
…rtup cleanup Agent-Logs-Url: https://github.com/wh5a/chrome/sessions/89b171b4-e2a4-4bc6-9b6e-b4407919ab0f Co-authored-by: wh5a <81014+wh5a@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on modernizing unclose for Chrome extension APIs
Fix concurrency bugs in unclose MV3 migration
May 12, 2026
There was a problem hiding this comment.
Pull request overview
This PR addresses MV3-related concurrency and lifecycle hazards in the “unclose” extension by reducing races around chrome.storage.session counters and preventing unintended history loss across extension updates.
Changes:
- Serialized background
chrome.storage.sessionmutations behind a promise queue to avoidcloseCount/actualCountraces during rapid tab events. - Adjusted initialization logic to avoid wiping session history on extension updates (wipe only on fresh install) and simplified startup initialization.
- Reduced
actualCountdecrement race in the popup by re-reading the counter immediately before writing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| unclose/bg.js | Adds a serialized write queue and updates tab event handlers to avoid concurrent counter clobbering; also stores titles even when URL hasn’t been recorded yet. |
| unclose/init.js | Gates deep-clear initialization to installs only and avoids unnecessary clear on browser startup. |
| unclose/popup.js | Re-reads actualCount immediately before decrementing to reduce stale-read writeback races. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+10
to
+12
| chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | ||
| enqueueWrite(async () => { | ||
| await ensureInitialized(); |
Contributor
Author
There was a problem hiding this comment.
Fixed in commit 360c75c. Both onUpdated and onRemoved listeners are now async and await enqueueWrite(...), so the service worker's promise chain is kept alive until each queued write finishes.
…ker alive Agent-Logs-Url: https://github.com/wh5a/chrome/sessions/88e12e2b-d875-4235-bc17-b22a6f740199 Co-authored-by: wh5a <81014+wh5a@users.noreply.github.com>
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.
actualCountfresh before decrement in popup.jsonInstalledondetails.reason === 'install'onStartupto not callstorageClear()onUpdatedandonRemovedlistenersasyncandawait enqueueWrite(...)so the MV3 service worker stays alive until each queued write completes