fix save indicator timing and auto-save history loss on resume

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 21:27:31 +00:00
co-authored by Claude Opus 4.6
parent 0e0be3327e
commit 60230ccfec
4 changed files with 92 additions and 70 deletions
@@ -93,20 +93,30 @@ savedSessionsRouter.put('/:id', async (ctx) => {
const homeDir = getHomeDirForRole(user.email, user.role);
// Load existing saved session to get previous messages
const existing = await getSavedSession(id, user.id);
if (!existing) {
return ctx.json({ error: 'Not found' }, 404);
}
let meta;
let messages: Message[];
let newMessages: Message[];
try {
const loaded = await storage.loadSession(homeDir, sessionId);
meta = loaded.meta;
messages = loaded.messages;
newMessages = loaded.messages;
} catch {
return ctx.json({ error: 'Session not found on disk' }, 404);
}
// Merge: old DB messages (from before resume) + new disk messages (from this session)
const oldMessages = (existing.rawMessages ?? []) as Message[];
const mergedMessages = [...oldMessages, ...newMessages];
const updated = await updateSavedSessionMessages(
id,
user.id,
messages,
mergedMessages,
meta.cost as unknown as Record<string, unknown>,
);