fix: persist direct chat transcript before Goosed escalation

Prevent portal direct-chat history from being lost when snapshot cache
is invalidated on Goosed submit by writing non-empty messages to DB first,
and stop caching empty Goose placeholder messages in snapshots.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-05 11:16:55 +08:00
parent 614837e199
commit bdeab23b83
6 changed files with 311 additions and 5 deletions
+4 -3
View File
@@ -67,6 +67,8 @@ function resolveDisplayTitle(session, messages) {
return deriveTitleFromMessages(messages);
}
import { filterNonemptyUserVisibleMessages } from './conversation-transcript-persist.mjs';
async function syncConversationMemory({
memoryV2 = null,
conversationMemoryService = null,
@@ -279,9 +281,8 @@ export function createSessionSnapshotService(pool, options = {}) {
});
if (!res.ok) return;
const gooseSession = await res.json();
// Store raw userVisible messages — same as write-through path.
const messages = (gooseSession.conversation ?? [])
.filter((m) => m.metadata?.userVisible);
// Store userVisible messages with content — skip empty Goose placeholders.
const messages = filterNonemptyUserVisibleMessages(gooseSession.conversation ?? []);
await save(sessionId, userId, gooseSession, messages);
} catch (err) {
console.warn('[snapshot] refresh failed:', sessionId, err instanceof Error ? err.message : err);