Repository navigation
fix(core): replace_library refuses a file that changed since it was read, and rebuild takes over unreadable files - #4617
Merged
Merged
Conversation
…ost checked it, and drops nothing
… and a rebuild sets aside a file it may not read
…the digest of each write
…es out, and iOS keeps its flags on a refused write
…e order the store holds them
This was referenced Nov 26, 2026
Merged
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 the library digest surface #4608 landed (the first K4c follow-up commit, before its reviews).
Core storage
replace_library_blocking(over, build):overis the digest of the file the host last read (None: no file). Under the write lock, a file whose bytes differ is refused withstorage.library_changedand nothing is written. That includes a file swapped for one that does not decode.buildmakes the write from that same locked read, so what a write keeps from stored entries comes from the checked bytes, not from an earlier unlocked read.storage.repeated_idfor a repeated favourite or a tag named twice on a connection.storage.connection_not_foundfor a favourite of no connection the file keeps.rebuild_library_blocking(write, now) -> Rebuilt { digest, set_aside }:FFI
replace_library(library, over) -> LibraryWritten { digest, set_aside }.rebuild_libraryreturns where it put an unreadable file.replace_libraryrefuses a blank hop id and alast_opened_msout of range instead of dropping them.LibraryWriteRecord.removing: entries this build cannot read that the write takes out, with their secrets, under the same digest check; an id the write also keeps is refused withstorage.repeated_idbefore any secret goes.iOS
CoreLibraryStorekeepsfileDigest, the digest of the core's file as it last read or wrote it, and passes it asoverto everyreplaceLibrary.removingrather than separate deletes, so the removal is checked with the write. The digest follows each write; a re-read is taken in only when it is the file the write left, and the device flags stay as they were when a write is refused.Windows
Test plan
a_library_write_over_a_file_that_changed_since_is_refused,a_library_write_over_a_file_swapped_for_one_that_does_not_read_is_refused_as_changed,a_library_write_refuses_what_the_store_would_dropa_rebuild_sets_aside_a_file_this_build_cannot_read,a_rebuild_sets_aside_a_file_the_system_will_not_let_it_reada_rebuild_keeps_only_what_it_names_and_starts_a_new_generationnow expects no deletion in the journal.a_library_write_over_a_file_changed_since_it_was_read_is_refused,a_library_write_refuses_a_blank_hop_id_and_a_time_out_of_range,a_rebuild_sets_aside_a_file_this_build_cannot_read.writeAfterDroppingAHeldConnectionLands,writeOverAChangedCoreFileIsRefused;coreOnlyValuesSurviveAnEditpasses the digest it read.over.a_library_write_takes_out_an_entry_this_build_cannot_read_that_it_names, anda_library_write_refuses_what_the_store_would_dropcovers a connection both kept and removed.verify.sh --platform linux --jobs 2: lint and build pass. Every Meson suite ran 9322 cases and one failed:each_history_db_write_names_the_records_it_wrote_and_deleted(from feat(core): store parity for the Mac library (ids, icons, SSH/TLS fields, batch API) #4590), which read deleted subfolders in no set order. ce7cf9a orders them by rowid, andtablepro-storagethen passed, 445 of 445.verify.sh --platform windows --jobs 4: coretablepro-ffi396 passed, build passed, test 2507 passed, bindings match the library.verify.sh --jobs 4 package TableProFFIpassed, 9 of 9.xcodebuild build-for-testingof TableProMobile for the iOS Simulator succeeded, so the app andTableProMobileTestscompile against the new call sites. The test run,verify.sh ios CoreLibraryStoreTests LibraryRecordMappingTests AppStateLibraryTests SyncedWriteFailureTests AppStateSyncWiringTests, waits for the MacBook, the build host with the simulator runtimes, which is offline.removing.removing: two medium (a connection both kept and removed, flags kept on a refused write), fixed.verify.sh --platform windows bindingspassed twice with no rewrite.tablepro-ffipassed 400 of 400, andtablepro-storagepassed 445 of 445 lib, 3 isolation and 8 stored-format tests.--adminbefore the CI queue, on Dat's rule of 2026-11-26 for this work (main's CI runs after the merge; red is fixed forward).