Skip to content

fix(core): replace_library refuses a file that changed since it was read, and rebuild takes over unreadable files - #4617

Merged
datlechin merged 8 commits into
mainfrom
fix/core-library-digest
Nov 26, 2026
Merged

datlechin merged 8 commits into
mainfrom
fix/core-library-digest

Conversation

@datlechin

@datlechin datlechin commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the library digest surface #4608 landed (the first K4c follow-up commit, before its reviews).

Core storage

  • replace_library_blocking(over, build):
    • over is the digest of the file the host last read (None: no file). Under the write lock, a file whose bytes differ is refused with storage.library_changed and nothing is written. That includes a file swapped for one that does not decode.
    • build makes 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.
    • A write that changes nothing checks the file again before it returns its digest.
  • A library write refuses what the store would otherwise drop:
    • storage.repeated_id for a repeated favourite or a tag named twice on a connection.
    • storage.connection_not_found for a favourite of no connection the file keeps.
  • rebuild_library_blocking(write, now) -> Rebuilt { digest, set_aside }:
    • A file it cannot read, for its contents or a system read error, is moved aside first instead of refusing the rebuild.
    • The journal is told the write against nothing, so no id from the untrusted file goes out as a deletion.
  • A read's digest is only for checking a host's tag; the doc and the record comments say so.

FFI

  • replace_library(library, over) -> LibraryWritten { digest, set_aside }.
  • rebuild_library returns where it put an unreadable file.
  • replace_library refuses a blank hop id and a last_opened_ms out 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 with storage.repeated_id before any secret goes.

iOS

  • CoreLibraryStore keeps fileDigest, the digest of the core's file as it last read or wrote it, and passes it as over to every replaceLibrary.
  • It takes out entries the core holds unread through removing rather 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

  • Bindings regenerated with uniffi-bindgen-cs 0.11.1+v0.31.0.

Test plan

  • Storage:
    • 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_drop
    • a_rebuild_sets_aside_a_file_this_build_cannot_read, a_rebuild_sets_aside_a_file_the_system_will_not_let_it_read
    • a_rebuild_keeps_only_what_it_names_and_starts_a_new_generation now expects no deletion in the journal.
  • FFI: 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.
  • iOS: writeAfterDroppingAHeldConnectionLands, writeOverAChangedCoreFileIsRefused; coreOnlyValuesSurviveAnEdit passes the digest it read.
  • Storage and FFI tests that wrote the library now pass the current digest as over.
  • Storage a_library_write_takes_out_an_entry_this_build_cannot_read_that_it_names, and a_library_write_refuses_what_the_store_would_drop covers a connection both kept and removed.
  • Linux dev container, 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, and tablepro-storage then passed, 445 of 445.
  • Windows steps from macOS, verify.sh --platform windows --jobs 4: core tablepro-ffi 396 passed, build passed, test 2507 passed, bindings match the library.
  • macOS: verify.sh --jobs 4 package TableProFFI passed, 9 of 9.
  • iOS: xcodebuild build-for-testing of TableProMobile for the iOS Simulator succeeded, so the app and TableProMobileTests compile 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.
  • Reviews:
    • Claude (fresh agent), a review and a security pass of the digest commit. Each found one high, the same write over a changed file, fixed here.
    • Codex, four rounds:
      • The Rust fixes: three medium, fixed (an undecodable swap reported as changed, the no-op re-check, a rebuild over a file it may not read).
      • The whole range with iOS: one high (an escaping closure read a main-actor property and did not compile) and three medium, fixed, plus one low (a read error taken as no file), fixed.
      • The iOS fixes: two medium (the separate deletes were not checked with the write), fixed by removing.
      • removing: two medium (a connection both kept and removed, flags kept on a refused write), fixed.
  • On the merge with main (cbe45ec, which brings feat(macos): saved queries and history on the core stores #4611's FFI host stores): verify.sh --platform windows bindings passed twice with no rewrite. tablepro-ffi passed 400 of 400, and tablepro-storage passed 445 of 445 lib, 3 isolation and 8 stored-format tests.
  • Merged by the coordinator with --admin before 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant