fix(storage): propagate connection persistence failure (data-loss prevention)#1140
Merged
Merged
Conversation
|
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.
Summary
Fixes B1 from the 2026-05-09 full-app audit (
docs/refactor/full-app-audit-2026-05-09/02-bugs-behavior.md). Severity: CRITICAL — data loss.ConnectionStorage.saveConnections(_:)swallowed every persistence failure with a void return +Logger.error. Callers continued as if the write had succeeded, mutating dependent state (sync tracker, keychain, app settings) for a record that was never persisted.Worst-case scenario before this PR
deleteConnection.saveConnectionsthrows (disk full, sandbox denied, encoding error).Void.syncTracker.markDeleted(.connection, id:)queues the connection for cloud removal.deletePassword(for:)removes the keychain entry.A symmetric path existed in
SyncRecordMapper.applyRemoteConnection(saved to disk; if it failed, the function reported success and the sync token advanced, dropping the remote update on the floor).What changes
saveConnectionsnow returns@discardableResult Bool. Every caller that mutates dependent state checks the result and aborts the downstream side effects on failure.ConnectionStorage.swiftaddConnectionmarkDirty, no password writeConnectionStorage.swiftupdateConnectionmarkDirty, no password writeConnectionStorage.swiftdeleteConnectionmarkDeleted, no password / SSH / TOTP / plugin-field removalsConnectionStorage.swiftdeleteConnectionsmarkDeletedfor any of the batchConnectionStorage.swiftduplicateConnectionmarkDirty, no password copyConnectionStorage.swiftmigratePluginSecureFieldsIfNeededCore/Sync/SyncCoordinator.swiftapplyRemoteChanges(deletions)Core/Sync/SyncCoordinator.swiftapplyRemoteConnectionfalseso the sync token does not advance past this recordConnectionFormCoordinator.swiftsave(new + edit)saveError, keep the form open, do not dismiss, do not fireconnectionUpdatedViewModels/WelcomeViewModel.swiftmoveConnections,removeFromGroup, drag-reorder, group-reordermarkDirtyCore/Storage/GroupStorage.swiftgroupIdDiff stats
CLAUDE.md("persist first, then notify") is now enforced by the early-return guard, not by hope.Test plan
Critical reproducers (the audit's worst case + the symmetric paths):
chflags uchgthe connections file (or fill~/Library/Containers/.../Documentswithdd), trigger a delete from the welcome screen. Connection should remain in the list, password should remain in keychain, no CloudKit tombstone should be queued. Console log should showAborted deleteConnection: persistence failed.saveErrorshows the localized message; the user can correct disk space and retry.markDirtyshould queue.applyRemoteConnectionreturns false). Re-unlock and re-pull → the record applies cleanly.Non-regression: