fix(connections): make the tag library report its refusals and survive a broken store - #2622
Merged
Conversation
…e a broken store Claude-Session: https://claude.ai/code/session_01L81TaoPWxkLd15CGw2riPq
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
TagStorageisGroupStorage's sibling and carried the same four defects, found while fixingthose in #2619. The store is now the same shape as the group store, so the two cannot drift apart
again on the next reader.
What was wrong
One unreadable entry replaced the whole library with the presets.
loadTagscaught the decodeerror, returned
ConnectionTag.presetsand cached them. Every mutation rewrites the whole array,so the next tag operation persisted the presets over the user's own tags. Worse than losing them
to an empty list: the store then looks healthy, because a fresh install looks exactly like that.
A refused tag was discarded without a word.
addTagreturned early on a name the libraryalready held. The create sheet dismissed anyway and selected the tag that was already there, with
its colour rather than the one just picked, so the user got a different tag from the one they
described and nothing said so.
Nothing announced a tag change. No
AppEventsanywhere in the file, so a tag created in onewindow did not reach another until relaunch.
Two Macs traded the whole library.
saveTagsmarks every tag dirty and the push uploads everydirty tag, and the remote apply wrote a record without asking whether it differed from the one
already stored. One changed tag re-uploaded all of them, the other Mac wrote them and re-uploaded
them back.
Alongside those, the import loop read
existingTagsonce for the whole envelope, so two tagssharing a name in one file both passed the check taken before either was added.
What changed
loadTagsdecodes element by element, so one unreadable entry costs that entry. A payload itcannot read at all leaves the store untouched and refuses the write instead of overwriting it.
addTagthrowsTagStorageError. The create sheet keeps itself open and says the name is taken.saveTagsreturnsBool, matchingConnectionStorage's documented convention.addTaganddeleteTagannounceconnectionUpdatedafter a successful write.saveTagsstayssilent so the sync pull keeps its single coalesced event.
applyRemoteTagon the store, skipping a record identical to the one already held, replacing thecopy of that logic in
SyncCoordinator.GroupStorage, whichis what makes any of this testable.
Verification
verify.sh generate,verify.sh build: PASSverify.sh test TagStorageTests GroupStorageTests StringCatalogIntegrityTests: PASS, 37 casesswiftlint --stricton every changed file: cleanscripts/localization.py verify: both catalogs still round-trip byte for byteTagStorageTestsis new: each thrown error, an event per mutation and none from a remote apply, anunchanged remote record leaving nothing dirty, a preset refusing deletion, an unreadable store left
untouched, and an unreadable entry not taking the library down.
One thing the tests taught me about the store:
initseeds the presets throughloadTags, so aninstance built before a test writes its payload has a warm cache and never reads it. The two
recovery tests write the store first and build the instance after, which is also what actually
happens: the app starts, and the file is already there.
https://claude.ai/code/session_01L81TaoPWxkLd15CGw2riPq