Skip to content

feat(macos): store slices 1b and 2 on the core store models - #4589

Merged
datlechin merged 30 commits into
integ/mac-enginefrom
feat/macos-core-library-slice-2
Nov 26, 2026
Merged

datlechin merged 30 commits into
integ/mac-enginefrom
feat/macos-core-library-slice-2

Conversation

@datlechin

@datlechin datlechin commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Mac stores chain, lane M2 (core ADR 0010 slices 1b and 2), on integ/mac-engine with main merged in (#4590, #4608, #4611, #4617).

  • The connection library moves into the core's ConnectionStore at Application Support/TablePro/Core/connections.json: every connection field, groups, each connection's group and place, tags, and the favourites with their order. CoreLibraryStore reads it once through library_contents and writes it whole through replace_library.
  • The library opens on CoreStoreHost.shared, the one core over TablePro/Core the sync engine and history.db use. Its secret store is CoreStoreSecrets: the account's items as KeychainHostSecrets keeps them, and each connection's secrets through ConnectionKeychainSecrets. The Local only ids sit behind a shared lock the library sets on every read and write.
  • ConnectionStorage, GroupStorage, TagStorage and ConnectionListPreferences.favoritesOrder keep their synchronous main-actor API over that one in-memory library. GroupStorage, TagStorage and ConnectionListPreferences take the ConnectionStorage they share instead of a defaults suite.
  • LibraryRecordMapping maps DatabaseConnection, ConnectionGroup and ConnectionTag to the core's records and back:
    • a value only the core names (teal, Strict TLS, an origin from a newer build) is written back as long as the Mac's value still reads as it;
    • queryTimeoutSeconds goes to query_timeout_secs;
    • an SSH tunnel is read from the legacy fields the way DatabaseConnection.init reads them.
  • Writes:
    • Each write passes the digest of the file as the store last read or wrote it. A file changed since is never written over: a group, tag, favourites or sync write fails and the store reads the file again, and a person's connection save rebuilds it.
    • rebuild_library rebuilds the file from what the Mac holds when a person saves over an untrusted store, when an untagged core file loses to the verified mirror, and when the core reports a damaged file (document_corrupt, document_missing_version, document_unreadable). A newer build's file is never moved or written over.
    • A connection the core holds unread is never written over; a deletion from another device takes it out through removing.
    • After each finished sync pass the library reads the file again when its digest moved, since the core's engine writes it without telling the Mac. What it reads is never tagged: nothing yet tells the engine's writes from one made outside TablePro.
    • Writes the app makes itself never vouch: the numbering of unranked groups, starring, and the saved database a rename or drop retargets.
  • Downgrade mirror (LegacyLibraryMirror):
    • After every core write it writes connections.json (with its tag and backup), com.TablePro.groups, com.TablePro.tags and the favourites order in the previous stable's formats.
    • It records a digest of each side, whether connections.json existed, and whether the core is ahead.
    • At launch: stores changed while the core's store was not are read back, since the previous stable ran; a core file without TablePro's tag loses to those stores when they verify; a mirror that fell behind is written again; a changed store that does not read stops every write.
  • Integrity:
    • The core's file has its own HMAC tag over the SHA-256 the core returns for the exact bytes it read or wrote.
    • Only a person's connection save vouches for a store again. Group, tag, favourites order and sync writes never vouch, and the mirror never tags connections.json beyond what the core's store is trusted for.
    • A readable file a rebuild replaces is kept as .untrusted-<time>, one an unverified edit of connections.json replaces as .replaced-<time>, a damaged one as the core's .corrupt-<seconds>. A save that moves secrets out removes them and the core's pre-upgrade copies.
    • A rebuild after a trusted read keeps the values that read held; any rebuild refuses a file a newer build wrote.
  • ConnectionKeychainSecrets is the HostSecrets over the Keychain items earlier builds read (database password, SSH password, key passphrase), device-only for Local only connections. It refuses every call until the library has read, since no scope is known before. A connection the core deletes for another device's deletion loses only its device-only items.
  • A write that names one id twice is refused. An import keeps the first copy of a repeated id, and of a repeated tag on one connection.
  • The mirror keeps connections.json's copies of connections the core holds unread, and their places in the favourites order.
  • Merging main into integ/mac-engine:
  • PublishedSSHRoute gains an init that keeps a stored basis. ConnectionStoreIntegrity.hasKey and IntegrityStampedFileStore.withdrawTrust are new.
  • .claude/rules/data-sync-storage.md: rows for the library, the mirror and its record, the kept copies and the core's tag.
  • apple/scripts/probes/check-library-downgrade.sh: T-DWN with this build and the previous stable's app in one sandbox.

Known limits:

  • SSH profiles and credential profiles stay in their Swift stores, and their sync kinds stay off, until a core change puts profiles in LibraryContents and LibraryWriteRecord.
  • A teal tag reads as no colour in 0.88. If 0.88 pushes that tag after a downgrade, it sends "None".
  • A file the engine writes will read as untrusted until a person's connection save, which rebuilds it. No engine adapter writes the library yet; one needs the core to say which writes it made.

Tests changed on purpose:

  • Every test library gets its own folder, since the core's store sits in Core/ beside the legacy file.
  • Write-failure tests refuse writes with LibraryWriteRefusal (the immutable flag). The core resets its folder's mode before each write, so a read-only mode no longer refuses it. Affected: ConnectionEditorStoreFixture.makeLibraryReadOnly, ConnectionStorageSyncDeleteTests.failedPersistenceRecordsNoTombstone, MacImportLibraryStoreTests.unwritableLibraryWritesNoKeychainItem and WelcomeViewModelTests.testDeleteKeepsTheConnectionAndReportsWhenPersistenceFails.
  • ConnectionEditorStoreTests.failedSaveForgetsLoadedSecrets changes the record too, because the core writes nothing for a save that leaves the record as it was.
  • CloudLibraryRecordsTests uses .silent for the six Safe Mode levels of the base surface.
  • ScopeRecordingKeychain lists its device-only keys.
  • SavedQueryCoreMirrorTests and FavoriteCoreMirrorTests (from feat(macos): saved queries and history on the core stores #4611) read the host journal instead of SyncChangeTracker, which integ removed. SavedQueryCoreMirrorTests.policyStopEndsTheApply and stopWhileTheWriteWaits go with the Swift pull apply they tested.
  • CoreLibraryStoreTests.onlyAConnectionSaveVouches reorders two favourites, so its favourites write writes.

Test plan

  • New tests:
    • CoreLibraryStoreTests: first launch, both stores written, the previous stable's edit and deletion taken in, a mirror cut short, an unreadable changed store, a damaged and a newer core file, held entries, trust and vouching, a forged mirror record, repeated ids, secrets moved out, a write over a changed file refused, a connection save over one rebuilding it and keeping a trusted read's values, a save over a newer build's file refused, an empty library trusted, another writer's change read in after a pass and left untrusted, a connection a pull leaves unreadable, an unread favourite after a relaunch.
    • LibraryRecordMappingTests: every stored property of ConnectionCoverageFixture through the core, every password source, the query timeout, a tunnel turned off, every Safe Mode level, AI policy and TLS mode, values only the core names, groups and tags.
    • ConnectionKeychainSecretsTests, with no secret call before the library reads.
    • SyncProviderCoordinatorTests.aFinishedPassReadsTheCoresWrites.
  • verify.sh build: PASS.
  • The 117 store, sync, editor, Welcome and core-mirror suites that build on these stores, run against the core: 1,139 tests passed.
  • swift test --package-path apple/Packages/TableProFFI: 9 passed.
  • T-DWN: check-library-downgrade.sh with this build's Debug app and TablePro 0.88.0 passed. It covers:
    • this build takes in 0.88's library;
    • this build's first write reaches connections.json with a tag 0.88 trusts;
    • 0.88 reads it without rewriting it;
    • 0.88's own write is taken in, untrusted, and stays in the core.
  • verify.sh lint on every changed Swift file and check-banned-words.sh: clean.
  • Reviews by Claude (fresh agent), with Codex at its limit: a review and a security pass on the whole diff, then a review of the fixes. Every finding is fixed except the known limits above and these core follow-ups:
    • rebuild_library moves aside a newer build's file and one it could not read for the system; the Mac checks before it rebuilds, outside the core's write lock.
    • A rebuild carries no options, unknown keys or profile sections from the file it replaces.
    • Tags have no freshness: an older file restored with its tag verifies.

@datlechin
datlechin changed the base branch from main to integ/mac-engine November 26, 2026 16:42
@datlechin
datlechin marked this pull request as ready for review November 26, 2026 18:31
@datlechin
datlechin merged commit 043a107 into integ/mac-engine Nov 26, 2026
28 of 35 checks passed
datlechin added a commit that referenced this pull request Nov 27, 2026
core/, linux/ and the generated C# are round 4's exactly: our only core commit missing from it, #4589's squash, is in it unsquashed (f02b24c, 372ad69). The Mac store files #4611 and #4589 both added keep #4589's versions, which descend from #4611 on main. SyncCoordinator.swift stays deleted (M4).
@datlechin
datlechin deleted the feat/macos-core-library-slice-2 branch November 27, 2026 16:36
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