fix(ui): flush session persistence on close to prevent data loss
This commit is contained in:
@@ -45,6 +45,7 @@ import {
|
||||
clearActiveParentSession,
|
||||
createSession,
|
||||
fetchSessions,
|
||||
flushSessionPersistence,
|
||||
updateSessionAgent,
|
||||
updateSessionModel,
|
||||
} from "./stores/sessions"
|
||||
@@ -245,6 +246,12 @@ const App: Component = () => {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await flushSessionPersistence(instanceId)
|
||||
} catch (error) {
|
||||
log.error("Failed to flush session persistence before closing", error)
|
||||
}
|
||||
|
||||
clearActiveParentSession(instanceId)
|
||||
|
||||
try {
|
||||
|
||||
@@ -171,6 +171,15 @@ function schedulePersist(instanceId: string) {
|
||||
persistTimers.set(instanceId, timer)
|
||||
}
|
||||
|
||||
async function flushSessionPersistence(instanceId: string) {
|
||||
const existing = persistTimers.get(instanceId)
|
||||
if (existing) {
|
||||
clearTimeout(existing)
|
||||
persistTimers.delete(instanceId)
|
||||
}
|
||||
await persistSessionTasks(instanceId)
|
||||
}
|
||||
|
||||
async function persistSessionTasks(instanceId: string) {
|
||||
try {
|
||||
const instanceSessions = sessions().get(instanceId)
|
||||
@@ -439,6 +448,7 @@ export {
|
||||
pruneDraftPrompts,
|
||||
withSession,
|
||||
persistSessionTasks,
|
||||
flushSessionPersistence,
|
||||
setSessionCompactionState,
|
||||
setSessionPendingPermission,
|
||||
setActiveSession,
|
||||
|
||||
Reference in New Issue
Block a user