Prevent iCloud sync data from crashing Pesty - #51
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0411c24644
ℹ️ 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".
| guard seenIDs.insert(item.id).inserted else { | ||
| return false | ||
| } |
There was a problem hiding this comment.
Preserve distinct clips when repairing ID collisions
When malformed sync state contains two clips with the same UUID but different content, this guard discards the older clip solely because its ID was already seen. Since persisted state is normalized before initialSnapshot is exposed and is subsequently saved, the distinct clipboard content disappears without a deletion tombstone; repair the collision by assigning a new UUID rather than dropping the record.
AGENTS.md reference: AGENTS.md:L85-L88
Useful? React with 👍 / 👎.
| guard var existing = byID[board.id] else { | ||
| var normalized = board | ||
| normalized.items = canonicalHistory(board.items) | ||
| byID[board.id] = normalized |
There was a problem hiding this comment.
Preserve Pinboard insertion order during normalization
For iCloud-enabled users who pin an older history item after a newer one, saveToPinboard intentionally inserts the newly pinned item at index 0, but normalizing the board with canonicalHistory sorts its items by their original capture timestamps. On the next launch, loadPersistedState therefore moves the recently pinned older clip behind clips pinned earlier; deduplicate board items without reordering them, or track a separate pin-order timestamp.
Useful? React with 👍 / 👎.
| return seenContent.insert( | ||
| digestContentKey(legacyContentKey(item)) | ||
| ).inserted |
There was a problem hiding this comment.
Keep clips of different types when canonicalizing content
When history or a Pinboard legitimately contains the same textual payload as different ClipType values—for example, one .text item and one .link item—sameContent(as:) treats them as distinct, but this set uses legacyContentKey, whose default branch hashes both as the same txt: value. Loading or recording the snapshot therefore silently removes one valid entry; make the canonical content key include the clip type so it matches the app's existing content-equality semantics.
AGENTS.md reference: AGENTS.md:L85-L88
Useful? React with 👍 / 👎.
Summary
Verification