assistant2: Persist threads using serde_json instead of bincode (#25938)

This PR changes how we persist threads in Assistant2 to use `serde_json`
instead of `bincode` for the representation.

This makes the format more flexible to work with (and will allow for
using things like `#[serde(default)]`) if the schema changes over time.

Note: We have to bump the LMDB database version for this, so any threads
created before now will be gone.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-03-03 12:47:10 -05:00 committed by GitHub
parent 669082dbe0
commit 81ff6f7a3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,7 +12,7 @@ use futures::FutureExt as _;
use gpui::{ use gpui::{
prelude::*, App, BackgroundExecutor, Context, Entity, Global, ReadGlobal, SharedString, Task, prelude::*, App, BackgroundExecutor, Context, Entity, Global, ReadGlobal, SharedString, Task,
}; };
use heed::types::SerdeBincode; use heed::types::{SerdeBincode, SerdeJson};
use heed::Database; use heed::Database;
use language_model::Role; use language_model::Role;
use project::Project; use project::Project;
@ -255,7 +255,7 @@ impl Global for GlobalThreadsDatabase {}
pub(crate) struct ThreadsDatabase { pub(crate) struct ThreadsDatabase {
executor: BackgroundExecutor, executor: BackgroundExecutor,
env: heed::Env, env: heed::Env,
threads: Database<SerdeBincode<ThreadId>, SerdeBincode<SavedThread>>, threads: Database<SerdeBincode<ThreadId>, SerdeJson<SavedThread>>,
} }
impl ThreadsDatabase { impl ThreadsDatabase {
@ -270,7 +270,7 @@ impl ThreadsDatabase {
let database_future = executor let database_future = executor
.spawn({ .spawn({
let executor = executor.clone(); let executor = executor.clone();
let database_path = paths::support_dir().join("threads/threads-db.0.mdb"); let database_path = paths::support_dir().join("threads/threads-db.1.mdb");
async move { ThreadsDatabase::new(database_path, executor) } async move { ThreadsDatabase::new(database_path, executor) }
}) })
.then(|result| future::ready(result.map(Arc::new).map_err(Arc::new))) .then(|result| future::ready(result.map(Arc::new).map_err(Arc::new)))