Skip to content

Model store - #5

Merged
colemancda merged 18 commits into
masterfrom
feature/model-store
Nov 17, 2026
Merged

colemancda merged 18 commits into
masterfrom
feature/model-store

Conversation

@colemancda

@colemancda colemancda commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

The model store on Linux: the guest's CoreModel, through AppRuntime's ModelStore contracts, to HostModelStore, over CoreModel's own SQLite backend.

LinuxCoreModel

  • LinuxModelStore, the host module. Stores go in <container>/Stores (a PortMaster port's conf/Stores), or $XDG_DATA_HOME/<id>/Stores: beside the app's Documents, out of reach of its Files. Answers go to the main loop.
  • SQLiteModelStorageProvider: one CoreModelSQLite.SQLiteDatabase per store.
    • The model is kept inside the database, in a table of its own.
    • A model canMigrate(from:to:) allows is migrated by copying into a new database that replaces the old one. Any other model fails with migrationRequired, or empties the store with .reset.
    • The app's indexes are made, plus one on each to-one relationship's column; indexes the app stops declaring are dropped.
  • SQLiteModelStorage, an AtomicModelStorage.
    • A batch is one transaction.
    • A predicate SQL can't express is evaluated with CoreModel's evaluator.
    • SQLite's errors map to the contract's: a full disk is outOfSpace, a file that isn't a database corrupted, one that can't be opened or read unavailable.
  • SQLite is compiled in (swift-sqlcipher), so a device needs no libsqlite3.

Upstream fixes, both merged. About 500 requests answered by SQLite and by CoreModel's in-memory evaluation disagreed on both sides:

Package.swift uses both packages' master until they're released; point it back at the tags then.

Tests (LinuxCoreModelTests, Swift Testing):

  • where stores are kept;
  • the requests compared with the in-memory store;
  • every attribute type there and back;
  • a batch applied whole or not at all;
  • a store kept between launches, migrated, refused or emptied;
  • indexes made and dropped;
  • a file that isn't a store, and no directory.

All 9 pass on macOS and on Debian 13 in Docker, as do the other suites.

A storage still open on a model that a later open migrated from, emptied or destroyed is closed, and fails with unavailable. Without that, SQLite failed it on macOS but went on reading the replaced file on Linux.

End to end: ExampleModel linked into linux-app-host on Debian 13 and launched twice on one container, with two to-dos written into its todos.sqlite between the launches. The second launch shows them under their lists, and it doesn't add the lists again:

ExampleModel on Linux

@colemancda
colemancda merged commit a0cae56 into master Nov 17, 2026
2 checks passed
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