Files
cobble/src/functions/backend/db/bot-sessions/clear-implicit-session-links-sql.ts
T
tbenandClaude Opus 5.5 56f219b322 Clear session links no carry-over made, at boot
Sessions from v0.2.8 and earlier were linked to the one before them by
every rollover and New session, so production threads offered "Show the
previous session" (and prompts read summaries) for sessions nothing was
carried from. A link is kept only when the session opens with a message
carried from that session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 06:21:51 +01:00

21 lines
884 B
TypeScript

/**
* Clears `previous_session_id` on every session that wasn't carried over:
* before v0.3.0 a rollover and New session linked each session to the
* one before it, so threads offered "Show the previous session" and
* prompts read summaries of sessions nothing was carried from. A carry
* over always opens its session with a message naming the one it came
* from (`carried_from_session_id`); a link without one is cleared.
*/
export default function clearImplicitSessionLinksSql() {
return {
sql: `UPDATE bot_sessions SET previous_session_id = NULL
WHERE previous_session_id IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM bot_messages m
WHERE m.session_id = bot_sessions.id
AND m.carried_from_session_id = bot_sessions.previous_session_id
)`,
values: [] as number[],
};
}