Skip to content

Comments

bettter persistence#51

Merged
ForestMars merged 4 commits intomainfrom
better-persitence
Nov 21, 2025
Merged

bettter persistence#51
ForestMars merged 4 commits intomainfrom
better-persitence

Conversation

@ForestMars
Copy link
Owner

@ForestMars ForestMars commented Nov 20, 2025

Context

Following on the recently added a "Private" checkbox (allowing users to mark individual messages as ephemeral/session-only) which is implemented by ChatInterface.tsx skiping calling conversation State.addMessage() for private messages, preventing them from being saved.
However, relying solely on UI-layer filtering is fragile : bugs, refactoring, or edge cases could cause private messages to leak into the persistence layer.

Problem

Private messages (marked with isPrivate: true) must NEVER be persisted to IndexedDB or synced to the server. They should only exist in app state during the current session and disappear on refresh.

Solution

Implement defense-in-depth filtering at the persistence layer to guarantee private messages are never saved, regardless of what happens upstream.

Changes Made

src/services/indexedDbStorage.ts

  1. Filter private messages before saving (prepareChatForStorage())
  • Added filteredMessages array that strips out any message where isPrivate === true
  • Applied to all persistence operations (local IndexedDB + server sync)
  1. Auto-cleanup empty conversations (saveConversation())
    If filtering results in zero messages (all were private), delete the conversation from:
  • Local IndexedDB (this.db.chats.delete())
  • Remote server (DELETE /deleteChat/:id)

Prevents empty conversations from cluttering the sidebar 🚀!!!

Expected Behavior

  • Private messages: Never saved to IndexedDB, never synced to server, disappear on page refresh
  • Conversations with only private messages: Automatically deleted from sidebar
  • Mixed conversations: Private messages filtered out, non-private messages persist normally

Architecture

Two-layer defense:

  • UI Layer (ChatInterface.tsx): Skips addMessage() for private messages
  • Persistence Layer (this PR): Filters private messages as safety net

NB: PR addresses multiple issues

  • updates CI/CD from npm to bun
  • This PR also adds 102 lines of unit tests for MCP service (unrelated to private messages)
    src/__tests__/services/mcpService.test.ts

@ForestMars
Copy link
Owner Author

Let's merge this in to reduce the diff on #52

@ForestMars ForestMars merged commit e71e922 into main Nov 21, 2025
12 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant