You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support deleting chat messages (turn-level cascade delete) #778
Add the ability to delete a chat message. Since branching/regenerate is not yet supported, delete operates at turn granularity: a turn is one user message + its following assistant response.
Deleting a user message
Soft-deletes the user message and cascades to soft-delete its immediately following assistant response (same turn).
Rationale: a user message and its AI response are one logical turn. Leaving an orphaned AI response with no visible originating prompt is confusing and semantically meaningless.
Deleting an AI response directly
Not allowed. No delete action is exposed on assistant messages in the UI.
Rationale: an assistant message without its paired user message is a dangling answer with no question — it breaks conversation readability and context. Regeneration (replacing a response) is a separate concern already handled by isOutdated, not by delete.
Storage approach
Use soft delete: add deletedAt: Instant? = null to ChatMessage.
All read paths (message list, export, context-window building for the LLM) must filter WHERE deletedAt IS NULL.
In-memory LLM context sync
Deleting a turn must also invalidate/rebuild the session's TokenAwareSummarizingMemory (ChatSessionService) so the next LLM call doesn't include deleted messages. Simplest approach: evict the cached session context on delete so it's rehydrated from (filtered) DB messages on next use.
Out of scope
Branching / multiple assistant responses per user message (not supported yet)
Session-level token-usage accounting impact (tracked in a separate issue)
Hi @haiphucnguyen, I'd like to work on this one if it's still open.
I read through the current code first. A few things I'd plan around:
LLM memory: I don't think evicting the cached context is enough on its own. Eviction from memoryCache triggers triggerAsyncSummarization(), and the summary is persisted through SessionMemoryRepository, so the deleted turn could survive inside the summary. I'd reuse the pattern from ChatSessionService.markMessagesAsOutdatedAfter: sessionMemoryRepository.deleteBySessionId, reload the recent non-deleted messages, then loadFromFilteredMemory.
Read paths: a deleted_at column via a new migration (65.sqm), and the filter added next to every is_outdated = 0 in ChatMessages.sq, plus the search, bookmark and export queries that don't filter today.
Turn pairing: the "following assistant response" would be the next ASSISTANT message by created_at in the same session, skipping outdated ones. Tests for: normal turn, user message with a failed/no response, and a bookmarked message.
Two questions before I start:
Sync: selectUnsynced / updateMessageFromServer don't know about deletion. Should a delete be synced to the server (so deleted_at goes out like any other change), or stay local for now?
If the deleted message is bookmarked, should the bookmark be removed, or just hidden with it?
LLM memory: I don't think evicting the cached context is enough on its own. Eviction from memoryCache triggers triggerAsyncSummarization(), and the summary is persisted through SessionMemoryRepository, so the deleted turn could survive inside the summary. I'd reuse the pattern from ChatSessionService.markMessagesAsOutdatedAfter: sessionMemoryRepository.deleteBySessionId, reload the recent non-deleted messages, then loadFromFilteredMemory.
Exactly like what you said, this is the right pattern.
Read paths: a deleted_at column via a new migration (65.sqm), and the filter added next to every is_outdated = 0 in ChatMessages.sq, plus the search, bookmark and export queries that don't filter today.
Yes, it is. I am having the open branch, and I may merge my change with the 65.sqm, but you get the point of database migration script
Two questions before I start:
Sync: selectUnsynced / updateMessageFromServer don't know about deletion. Should a delete be synced to the server (so deleted_at goes out like any other change), or stay local for now?
You can ignore the sync now, the community does not have feature releate to sync. Let it stay local
If the deleted message is bookmarked, should the bookmark be removed, or just hidden with it?
We should only hide the deleted bookmark message
In the chatview, we should hide the delete user message and the next ai response message. It is different than outdated message we still display in ChatView, the deleted message is hidden.
Thanks for the assignment and the clear answers! I'll keep delete local-only, hide (not remove) bookmarks of deleted messages, and hide the deleted turn completely in ChatView, unlike outdated messages. I'll start with 65.sqm and renumber if your branch lands first.
As mentioned, your 65.sqm landed first, so the migration is now 66.sqm with AfterVersion(66). I also tested the upgrade path from an existing database in the running app. Happy to adjust anything in review.
Activity
rcpeken commentedon Oct 24, 2026
Hi @haiphucnguyen, I'd like to work on this one if it's still open.
I read through the current code first. A few things I'd plan around:
LLM memory: I don't think evicting the cached context is enough on its own. Eviction from memoryCache triggers triggerAsyncSummarization(), and the summary is persisted through SessionMemoryRepository, so the deleted turn could survive inside the summary. I'd reuse the pattern from ChatSessionService.markMessagesAsOutdatedAfter: sessionMemoryRepository.deleteBySessionId, reload the recent non-deleted messages, then loadFromFilteredMemory.
Read paths: a deleted_at column via a new migration (65.sqm), and the filter added next to every is_outdated = 0 in ChatMessages.sq, plus the search, bookmark and export queries that don't filter today.
Turn pairing: the "following assistant response" would be the next ASSISTANT message by created_at in the same session, skipping outdated ones. Tests for: normal turn, user message with a failed/no response, and a bookmarked message.
Two questions before I start:
Sync: selectUnsynced / updateMessageFromServer don't know about deletion. Should a delete be synced to the server (so deleted_at goes out like any other change), or stay local for now?
If the deleted message is bookmarked, should the bookmark be removed, or just hidden with it?
haiphucnguyen commentedon Oct 25, 2026
Thank you @rcpeken for thoughtful analysis.
Exactly like what you said, this is the right pattern.
Yes, it is. I am having the open branch, and I may merge my change with the
65.sqm, but you get the point of database migration scriptYou can ignore the sync now, the community does not have feature releate to sync. Let it stay local
In the chatview, we should hide the delete user message and the next ai response message. It is different than outdated message we still display in ChatView, the deleted message is hidden.
rcpeken commentedon Oct 26, 2026
Thanks for the assignment and the clear answers! I'll keep delete local-only, hide (not remove) bookmarks of deleted messages, and hide the deleted turn completely in ChatView, unlike outdated messages. I'll start with 65.sqm and renumber if your branch lands first.
haiphucnguyen commentedon Oct 26, 2026
Awesome, thank you @rcpeken . I am looking forward to your PR!
rcpeken commentedon Oct 27, 2026
PR is up: #784
As mentioned, your
65.sqmlanded first, so the migration is now66.sqmwithAfterVersion(66). I also tested the upgrade path from an existing database in the running app. Happy to adjust anything in review.feat(chat): support deleting a chat turn (soft delete) (askimo-ai#784)