dm / commit
feat: add save version — discard sessions with mismatched format
public/index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/index.html b/public/index.html index 44c3bf3..7f28f9f 100644 --- a/public/index.html +++ b/public/index.html @@ -1597,12 +1597,16 @@ function buildDebugInfo(userDesc) { } // ── SESSION PERSISTENCE ─────────────────────────────── +// Increment SAVE_VERSION on any breaking change to gameState shape or +// session format. tryResumeSession discards saves from older versions. +const SAVE_VERSION = 1; function saveSession() { if (!gameState) return; const { apiKey: _, ...stateToSave } = gameState; try { localStorage.setItem('dm_session', JSON.stringify({ + version: SAVE_VERSION, gameState: stateToSave, conversationHistory, messagesHTML: document.getElementById('messages').innerHTML, @@ -1622,6 +1626,12 @@ async function tryResumeSession() { let session; try { session = JSON.parse(sessionRaw); } catch { return false; } + if (session.version !== SAVE_VERSION) { + console.log(`Save version mismatch (saved ${session.version ?? 'none'}, current ${SAVE_VERSION}) — discarding old session.`); + localStorage.removeItem('dm_session'); + return false; + } + gameState = { ...session.gameState, apiKey: currentApiKey }; conversationHistory = session.conversationHistory || [];