Discard archived session checkpoints
This commit is contained in:
@@ -448,6 +448,7 @@ impl Database {
|
||||
) -> Result<Vec<StoredMessage>, String> {
|
||||
self.connection
|
||||
.transaction(|connection| {
|
||||
reactivate_archived_session(connection, session_id)?;
|
||||
touch_session(connection, session_id)?;
|
||||
let mut stored = Vec::with_capacity(system_messages.len() + 2);
|
||||
for content in system_messages {
|
||||
@@ -654,6 +655,7 @@ impl Database {
|
||||
.map_err(|_| "Context limit is too large to save".to_owned())?;
|
||||
self.connection
|
||||
.transaction(|connection| {
|
||||
reactivate_archived_session(connection, session_id)?;
|
||||
diesel::update(sessions::table.find(session_id))
|
||||
.set((
|
||||
sessions::compacted_summary.eq(Some(summary)),
|
||||
@@ -715,6 +717,20 @@ fn touch_session(
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
fn reactivate_archived_session(
|
||||
connection: &mut SqliteConnection,
|
||||
session_id: i32,
|
||||
) -> Result<(), diesel::result::Error> {
|
||||
diesel::update(
|
||||
sessions::table
|
||||
.find(session_id)
|
||||
.filter(sessions::state.eq(SessionState::Archived.as_id())),
|
||||
)
|
||||
.set(sessions::state.eq(SessionState::Normal.as_id()))
|
||||
.execute(connection)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -827,6 +843,44 @@ mod tests {
|
||||
fs::remove_file(path).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_work_reactivates_an_archived_session() {
|
||||
let id = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let path = std::env::temp_dir().join(format!("ds4-reactivate-{id}.sqlite3"));
|
||||
let mut database = Database::open(&path).unwrap();
|
||||
let project = database
|
||||
.create_project("DS4", "/tmp/ds4-reactivate")
|
||||
.unwrap();
|
||||
let session = database.create_session(project.id, "Archived").unwrap();
|
||||
database
|
||||
.set_session_state(session.id, SessionState::Archived)
|
||||
.unwrap();
|
||||
|
||||
database
|
||||
.start_chat_turn(session.id, "Resume", None, &[], false)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
database.load_projects().unwrap()[0].sessions[0].state(),
|
||||
SessionState::Normal
|
||||
);
|
||||
database
|
||||
.set_session_state(session.id, SessionState::Archived)
|
||||
.unwrap();
|
||||
database
|
||||
.record_compaction(session.id, "Summary", None, None, 100, 1_000)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
database.load_projects().unwrap()[0].sessions[0].state(),
|
||||
SessionState::Normal
|
||||
);
|
||||
drop(database);
|
||||
fs::remove_file(path).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a2ui_dismissal_persists_a_fresh_surface_boundary() {
|
||||
let id = SystemTime::now()
|
||||
|
||||
Reference in New Issue
Block a user