Skip to content

[Website] Prevent stale thumbnail captures from overwriting saved metadata - #4167

Merged
adamziel merged 3 commits into
trunkfrom
adamziel/prevent-stale-thumbnail-captures
Jul 25, 2026
Merged

[Website] Prevent stale thumbnail captures from overwriting saved metadata#4167
adamziel merged 3 commits into
trunkfrom
adamziel/prevent-stale-thumbnail-captures

Conversation

@adamziel

@adamziel adamziel commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Background

#4142 bounds page loading and gives modern-screenshot three seconds to render. That prevents one capture from hanging forever. It does not order results.

A saved Playground keeps its site metadata in wp-runtime.json inside that site's OPFS directory. Every open tab has its own Redux copy of the record, while all tabs write to the same OPFS file. #4152 made those writes atomic: OpfsSiteStorage.update() takes an origin-wide Web Lock keyed by site slug, reads the latest record, merges only the supplied patch, and writes it back. A thumbnail update therefore cannot restore an old name or runtime setting from that tab's Redux state.

The lock only serializes writes. It cannot know when captureSiteThumbnail() started. An old iframe can finish after a newer capture and then acquire the lock with a valid { thumbnail } patch, replacing the newer image.

This change

Before passing a thumbnail patch to OpfsSiteStorage.update(), this PR requires that the request is still the latest one for that site in the current tab, its boot signal has not been aborted, and Redux still owns the client that started it.

The initial OPFS copy now returns its own success result. Thumbnail capture no longer infers that copy's outcome from initialOpfsSyncPending, whose value can change independently.

Two live tabs remain valid writers. Their per-site Web Lock serializes thumbnail updates, and the last completed live-tab write wins.

Testing

The focused tests resolve captures out of order, replace and abort clients, and fail an initial OPFS copy after the metadata flag changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Prevents stale or cancelled thumbnail captures and background OPFS syncs from overwriting current site metadata by validating capture recency, abort state, and client ownership before persisting.

Changes:

  • Add per-site capture tokens + Redux client ownership checks before writing thumbnail metadata.
  • Plumb getState/signal into thumbnail capture and gate capture on initial OPFS sync success (returning an explicit boolean).
  • Add focused Vitest coverage for out-of-order captures, client replacement/abort, and OPFS copy failure behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/playground/website/src/lib/state/redux/persist-temporary-site.ts Passes getState through to enable ownership checks during persistence.
packages/playground/website/src/lib/state/redux/capture-site-thumbnail.ts Adds capture tokening, abort checks, and Redux client ownership validation before persisting thumbnails.
packages/playground/website/src/lib/state/redux/capture-site-thumbnail.spec.ts Adds tests for overlapping captures, client replacement, and abort behavior.
packages/playground/website/src/lib/state/redux/boot-site-client.ts Makes initial OPFS background sync return success/failure and only captures thumbnails on success.
packages/playground/website/src/lib/state/redux/boot-site-client.spec.ts Adds a regression test ensuring thumbnail capture does not run when initial OPFS copy fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/playground/website/src/lib/state/redux/capture-site-thumbnail.spec.ts Outdated
Comment thread packages/playground/website/src/lib/state/redux/capture-site-thumbnail.ts Outdated
@adamziel
adamziel merged commit 21ba68d into trunk Jul 25, 2026
@adamziel
adamziel deleted the adamziel/prevent-stale-thumbnail-captures branch July 25, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment