Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(host-core): align schema v22 checks

vastsad7c03cf11355
diff --git a/crates/host-core/src/db/migrations.rs b/crates/host-core/src/db/migrations.rs
index cf064fa87..95a004fa2 100644
--- a/crates/host-core/src/db/migrations.rs
+++ b/crates/host-core/src/db/migrations.rs
@@ -966,7 +966,7 @@ pub(crate) fn migrate_v20_to_v21(conn: &Connection, path: &Path) -> Result<()> {
pub(crate) fn migrate_v21_to_v22_tx(tx: &rusqlite::Transaction<'_>) -> Result<()> {
tx.execute_batch(
"DROP INDEX IF EXISTS idx_sessions_updated;
- CREATE INDEX IF NOT EXISTS idx_sessions_updated_id ON sessions(updated_at DESC, id DESC);"
+ CREATE INDEX IF NOT EXISTS idx_sessions_updated_id ON sessions(updated_at DESC, id DESC);",
)?;
tx.pragma_update(None, "user_version", 22i64)?;
Ok(())
diff --git a/crates/host-core/src/db/tests.rs b/crates/host-core/src/db/tests.rs
index 90ef57848..ae8ffd8f3 100644
--- a/crates/host-core/src/db/tests.rs
+++ b/crates/host-core/src/db/tests.rs
@@ -1669,31 +1669,39 @@ fn migrates_v21_to_v22_replaces_session_index() {
{
// Open a fresh database which creates the latest schema
let db = Database::open(&db_path).unwrap();
- db.conn().execute_batch(
- "
+ db.conn()
+ .execute_batch(
+ "
DROP INDEX IF EXISTS idx_sessions_updated_id;
CREATE INDEX idx_sessions_updated ON sessions(updated_at DESC);
PRAGMA user_version = 21;
- "
- ).unwrap();
+ ",
+ )
+ .unwrap();
}
-
+
let db = Database::open(&db_path).unwrap();
-
- let version: i64 = db.conn().query_row("PRAGMA user_version", [], |r| r.get(0)).unwrap();
+
+ let version: i64 = db
+ .conn()
+ .query_row("PRAGMA user_version", [], |r| r.get(0))
+ .unwrap();
assert_eq!(version, crate::db::SCHEMA_VERSION);
-
+
let old_index_exists: bool = db.conn().query_row(
"SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='index' AND name='idx_sessions_updated')",
[],
|r| r.get(0)
).unwrap();
assert!(!old_index_exists, "idx_sessions_updated should be dropped");
-
+
let new_index_exists: bool = db.conn().query_row(
"SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='index' AND name='idx_sessions_updated_id')",
[],
|r| r.get(0)
).unwrap();
- assert!(new_index_exists, "idx_sessions_updated_id should be created");
+ assert!(
+ new_index_exists,
+ "idx_sessions_updated_id should be created"
+ );
}
diff --git a/crates/host-core/src/plugins/providers/tests.rs b/crates/host-core/src/plugins/providers/tests.rs
index 629cd29a6..7472c8174 100644
--- a/crates/host-core/src/plugins/providers/tests.rs
+++ b/crates/host-core/src/plugins/providers/tests.rs
@@ -91,9 +91,11 @@ fn declaration_manifest(providers: Value, permissions: Value) -> Value {
#[test]
fn a_new_database_carries_the_owner_column_at_the_current_schema_version() {
let (_dir, db, _secrets) = test_context();
- // v17 added the owner column, v18 the turn-queue priority column, v19 session omit, and v21 the session Todo checklist; a fresh
- // database is stamped with the newest, so the column set is the current one.
- assert_eq!(SCHEMA_VERSION, 21);
+ // v17 added the owner column, v18 the turn-queue priority column,
+ // v19 session omit, v21 the session Todo checklist, and v22 the
+ // session-list index. A fresh database is stamped with the newest version,
+ // so the column set is the current one.
+ assert_eq!(SCHEMA_VERSION, 22);
let version: i64 = db
.conn()
.query_row("PRAGMA user_version", [], |row| row.get(0))
diff --git a/crates/host-core/src/turn_queue.rs b/crates/host-core/src/turn_queue.rs
index afd84919a..b34cb9e77 100644
--- a/crates/host-core/src/turn_queue.rs
+++ b/crates/host-core/src/turn_queue.rs
@@ -532,7 +532,7 @@ mod tests {
assert_eq!(entries[0].content, "existing");
assert!(entries[0].user_message_id.is_none());
assert!(entries[0].voice_origin.is_none());
- assert_eq!(crate::db::SCHEMA_VERSION, 21);
+ assert_eq!(crate::db::SCHEMA_VERSION, 22);
}
#[test]
diff --git a/docs/spec/03-runtime/04-data-storage.md b/docs/spec/03-runtime/04-data-storage.md
index 7411cafb3..113bce6ef 100644
--- a/docs/spec/03-runtime/04-data-storage.md
+++ b/docs/spec/03-runtime/04-data-storage.md
@@ -1436,7 +1436,7 @@ truncating at a guessed position.
cross the host/Electron/renderer boundary
- full transcript consumers → one sequential read of
`sessions/<id>.jsonl` (no DB), retained for sidecar context and mutations
- - session list → `idx_sessions_updated`
+ - session list → `idx_sessions_updated_id(updated_at DESC, id DESC)`
- group-by-project → `idx_sessions_project`
- badges/cost rollup → `idx_turns_session` (latest turn per session)
- global token history → `idx_turns_ended_at` (completed turns by end time)
@@ -1520,6 +1520,9 @@ truncating at a guessed position.
and `turn_queue.voice_origin_json`; existing queue rows remain valid and
unset. The migration keeps a v19 backup, and queue entries remain held until
the existing Agent Host controller attaches.
+- **Schema v22 is additive.** It replaces `idx_sessions_updated` with
+ `idx_sessions_updated_id(updated_at DESC, id DESC)` for session-list ordering.
+ It changes no rows or persisted fields; a v21 backup precedes the migration.
- **Schema v14 is additive.** It adds nullable `sessions.deleted_at`, the
partial deletion index, and `session_import_origins`. Existing sessions stay
active and have no origin rows. The migration runs in the same guarded