Conversation
…dex and non-destructive migration - Remove signature field from StoredMessageRef/StoredMessageRecord; detect divergence by comparing storageKey/messageId/order instead - On save, only write message records from the first divergent index onward (or just the last record for streaming appends) rather than any record whose JSON signature changed - Replace the drop-all-stores upgrade path with migrateLegacySessionRecords, which reads existing session rows that still carry an inline messages array and rewrites them into the split sessions/session-messages/session-metadata layout without data loss - Update tests: add createTwoTurnSession helper, add divergence-suffix test, rename streaming-save test, rewrite migration test to assert data is preserved across the upgrade
🤖 Augment PR SummarySummary: Refactors extension session persistence to reduce IndexedDB writes and preserve data across schema upgrades. Changes:
Technical Notes: Migration runs during 🤖 Was this summary useful? React with 👍 or 👎 |
| return messageRecords.slice(divergenceIndex); | ||
| } | ||
|
|
||
| return [messageRecords[messageRecords.length - 1]]; |
There was a problem hiding this comment.
getMessageRecordsToPut returns only the last message when refs are unchanged, but serializeSessionAttachments() can change earlier messages (e.g., generating a new attachmentId when missing). That can leave older message rows pointing at attachment IDs that get deleted on later saves, effectively losing attachments or creating orphaned blobs.
Severity: high
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| const sessionStore = transaction.objectStore(SESSIONS_STORE); | ||
| const messageStore = transaction.objectStore(SESSION_MESSAGES_STORE); | ||
| const metadataStore = transaction.objectStore(METADATA_STORE); | ||
| const getAllSessionsRequest = sessionStore.getAll(); |
There was a problem hiding this comment.
migrateLegacySessionRecords only wires onsuccess for sessionStore.getAll(); if the request errors, the DB can upgrade to v4 without rewriting legacy rows, and later reads may fail due to missing messageRefs/message rows. Consider handling the error path so upgrades don’t silently produce a partially-migrated schema.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
… stable across saves Replace crypto.randomUUID() fallback with a deterministic ID derived from session ID, message ID, and part index. This ensures that file attachment references remain stable when re-saving a session where only a later message changed, preventing duplicate attachment writes. Add test 'keeps earlier attachment refs stable when only the latest message rewrites' to cover this behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
StoredMessageRefandStoredMessageRecordno longer carry asignaturefield. Change detection now comparesstorageKey/messageId/orderto find the first divergent index in the message list, writing only records from that point onward.oldVersion < DB_VERSION. The new path callsmigrateLegacySessionRecords, which reads session rows that still carry an inlinemessagesarray and rewrites them into the splitsessions/session-messages/session-metadatalayout, preserving all data.Tests
createTwoTurnSessionfixture helper.putcalls when the second turn is edited.Verification