Skip to content

fix(notebook): cascade-delete chat sessions on notebook deletion - #1175

Merged
lfnovo merged 3 commits into
mainfrom
fix/notebook-delete-cascade-chat-sessions
Jul 19, 2026
Merged

fix(notebook): cascade-delete chat sessions on notebook deletion#1175
lfnovo merged 3 commits into
mainfrom
fix/notebook-delete-cascade-chat-sessions

Conversation

@lfnovo

@lfnovo lfnovo commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Problem

DELETE /api/notebooks/{id} removed the notebook, its notes, and (optionally) its exclusive sources, but left chat_session records orphaned in the database.

Change

  • Extend Notebook.delete() to enumerate the notebook's chat sessions via the existing get_chat_sessions() method (the refers_to graph relation) and delete each one, matching the ordering and error handling of the existing notes/sources cascade. The returned counts dict gains deleted_chat_sessions.
  • Notebook.get_delete_preview() and the NotebookDeletePreview response now report chat_session_count, so the API no longer understates what a delete will remove.

Tests

  • Added test_notebook_delete_cascades_chat_sessions — asserts each chat session is deleted and the count is returned.
  • Added test_notebook_delete_preview_counts_chat_sessions — asserts the preview reports the chat session count.
  • Full suite: 557 passed. ruff check . and mypy clean.

Closes #1124

Review in cubic

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 because NotebookDeletePreview/dialog rendering omits the new field, so users can confirm deletion without informed consent and lose conversations unexpectedly. Extend NotebookDeletePreview plus 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

Comment thread open_notebook/domain/notebook.py Outdated
"note_count": note_count,
"exclusive_source_count": exclusive_count,
"shared_source_count": shared_count,
"chat_session_count": chat_session_count,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

lfnovo added 2 commits July 19, 2026 12:38
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.
@lfnovo
lfnovo merged commit 9807115 into main Jul 19, 2026
13 checks passed
@lfnovo
lfnovo deleted the fix/notebook-delete-cascade-chat-sessions branch September 2, 2026 22:03
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.

Deleting a notebook does not cascade-delete its chat sessions

1 participant