Skip to content

Ensure site storage cache rolls back on persistence failures#94

Merged
Brian-S-Poon merged 1 commit into
mainfrom
codex/update-screendimmersitestorage-method
Nov 15, 2025
Merged

Ensure site storage cache rolls back on persistence failures#94
Brian-S-Poon merged 1 commit into
mainfrom
codex/update-screendimmersitestorage-method

Conversation

@Brian-S-Poon
Copy link
Copy Markdown
Owner

Summary

  • delay ScreenDimmerSiteStorage cache updates until site level persistence completes and restore the previous cache on error
  • extend storage tests to cover pending and rejection scenarios for the site cache

Testing

  • npm test

Codex Task

@Brian-S-Poon Brian-S-Poon merged commit 82b3024 into main Nov 15, 2025
2 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/popup/site-storage.js
Comment on lines 37 to +46
async function persist(nextLevels) {
const normalized = normalizeLevels(nextLevels);
await storage.setSiteLevels(normalized);
cache = normalized;
return getCache();
const previousCache = cache;
try {
await storage.setSiteLevels(normalized);
cache = normalized;
return getCache();
} catch (error) {
cache = previousCache;
throw error;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Deferring cache update drops concurrent site changes

The new persist postpones cache assignment until setSiteLevels resolves and restores the previous object on failure. Because upsert/remove copy from cache to build the next payload, any second call invoked while the first write is still pending will read the stale pre‑update cache. If both promises resolve successfully, whichever finishes last will overwrite the stored levels and the in‑memory cache with only its own changes, silently discarding the earlier update (e.g. quickly editing two different hosts in the manager). The previous implementation updated cache optimistically so subsequent calls merged pending changes; this change reintroduces lost updates unless writes are serialized or merged explicitly.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant