fix(notebook): cascade-delete chat sessions on notebook deletion - #1175
Conversation
Deleting a notebook removed its notes and exclusive sources but left chat_session records orphaned. Extend Notebook.delete() to enumerate the notebook's chat sessions via the existing refers_to relation and delete each one, and report chat_session_count in the delete preview. Closes #1124
There was a problem hiding this comment.
1 issue found across 5 files
Confidence score: 3/5
- In
open_notebook/domain/notebook.py, the delete flow still does not surface that associated chat sessions will also be removed becauseNotebookDeletePreview/dialog rendering omits the new field, so users can confirm deletion without informed consent and lose conversations unexpectedly. ExtendNotebookDeletePreviewplus the delete dialog and related i18n copy to explicitly show this warning before merging.
You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="open_notebook/domain/notebook.py">
<violation number="1" location="open_notebook/domain/notebook.py:210">
P2: Notebook deletion still gives no UI warning that chat sessions will be removed: the dialog's typed preview omits and never renders this new field. Extend `NotebookDeletePreview` and the delete dialog/i18n copy to display `chat_session_count`, so users can see this additional destructive effect before confirming.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| "note_count": note_count, | ||
| "exclusive_source_count": exclusive_count, | ||
| "shared_source_count": shared_count, | ||
| "chat_session_count": chat_session_count, |
There was a problem hiding this comment.
P2: Notebook deletion still gives no UI warning that chat sessions will be removed: the dialog's typed preview omits and never renders this new field. Extend NotebookDeletePreview and the delete dialog/i18n copy to display chat_session_count, so users can see this additional destructive effect before confirming.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At open_notebook/domain/notebook.py, line 210:
<comment>Notebook deletion still gives no UI warning that chat sessions will be removed: the dialog's typed preview omits and never renders this new field. Extend `NotebookDeletePreview` and the delete dialog/i18n copy to display `chat_session_count`, so users can see this additional destructive effect before confirming.</comment>
<file context>
@@ -202,6 +207,7 @@ async def get_delete_preview(self) -> Dict[str, Any]:
"note_count": note_count,
"exclusive_source_count": exclusive_count,
"shared_source_count": shared_count,
+ "chat_session_count": chat_session_count,
}
except Exception as e:
</file context>
The delete-preview API advertised chat_session_count but the frontend dialog and locales never render it, creating a UI inconsistency. Trim the preview back to notes and sources; the deletion cascade and its post-delete deleted_chat_sessions count are unchanged.
Problem
DELETE /api/notebooks/{id}removed the notebook, its notes, and (optionally) its exclusive sources, but leftchat_sessionrecords orphaned in the database.Change
Notebook.delete()to enumerate the notebook's chat sessions via the existingget_chat_sessions()method (therefers_tograph relation) and delete each one, matching the ordering and error handling of the existing notes/sources cascade. The returned counts dict gainsdeleted_chat_sessions.Notebook.get_delete_preview()and theNotebookDeletePreviewresponse now reportchat_session_count, so the API no longer understates what a delete will remove.Tests
test_notebook_delete_cascades_chat_sessions— asserts each chat session is deleted and the count is returned.test_notebook_delete_preview_counts_chat_sessions— asserts the preview reports the chat session count.ruff check .andmypyclean.Closes #1124