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