Delete AI chat sessions when a site is deleted - #4132
Conversation
|
@shaunandrews @youknowriad What do you think about deleting chat sessions when their site is deleted? For now I only implemented archiving, but I think there's a case to be made that a session for a site that no longer exists is not very useful. A middle ground could be tying it to the "Delete site files" checkbox: keep the transcripts unless the user also chose to delete the site's files. |
|
I feel like we should just delete the sessions when a site is deleted, the reason is that the folder where they live is hidden and there's no way to restore them, unlike the site files. |
📊 Performance Test ResultsComparing 7bc7bcc vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
…studio into archive-chats-on-site-delete
|
Makes sense to delete them. |
katinthehatsite
left a comment
There was a problem hiding this comment.
I tested this and it mostly works fine but I noticed that sometimes I hit the Session not found screen. For example, I click on Delete site for the site that has sessions and stay on the open session for that site and after a couple of seconds, I can see the message Session not found:
Screen.Recording.2026-07-13.at.3.13.55.PM.mov
I think we can switch to the next available site once the deletion completed or started to avoid hitting that screen. What do you think?
Done in bcd84ea |
Thanks for making the changes! I don't see the error related to the sessions not found anymore but I do see the brief flash of error when I remain on the chat session of the site that is being deleted: Screen.Recording.2026-07-14.at.9.31.31.AM.movIs that happening on your end as well? |
…e-delete # Conflicts: # apps/ui/src/components/site-list/index.test.tsx # apps/ui/src/components/site-list/index.tsx # apps/ui/src/ui-classic/components/session-view/style.module.css
It was! Nice catch! Should be fixed now, can you take another look please? |
…e-delete # Conflicts: # apps/ui/src/components/site-list/index.test.tsx # apps/ui/src/components/site-list/index.tsx
…e-delete # Conflicts: # apps/ui/src/data/core/connectors/ipc/index.ts # apps/ui/src/ui-classic/router/layout-root/index.tsx
| await deleteSharedSession( sessionId ); | ||
| await deleteAiSessionPlacement( sessionId ); |
There was a problem hiding this comment.
We could consider moving these isnide the try/catch to avoid an error to prevent running the rest of the loop.
…te (#4292) ## Related issues <!-- Link a related issue to this PR. If the PR does not immediately resolve the issue, for example, it requires a separate deployment to production, avoid using the "Fixes" keyword and use "Related to" instead. --> - Related to #4132 - Addresses @sejas's review suggestion from that PR ## How AI was used in this PR <!-- Help reviewers understand what to look for and verify that you've reviewed the code yourself. --> AI was used to implement the focused robustness change, add the regression test, and run validation. ## Proposed Changes <!-- Explain the intent of this PR: - What problem does it solve, or what need does it address? - How does it affect the user (new capability, fix, performance, accessibility, etc.)? - Note any user-visible behavior changes or trade-offs. Focus on the "why" and the user impact. Avoid listing modified files or describing implementation mechanics — the diff already shows that. --> - Ensure deleting a site continues removing its remaining AI chat sessions when one session's metadata cleanup fails. - Preserve best-effort metadata cleanup when a session file is already missing. ## Testing Instructions <!-- Add as many details as possible to help others reproduce the issue and test the fix. "Before / After" screenshots can also be very helpful when the change is visual. --> - Run `npx eslint --fix packages/common/ai/sessions/manage.ts packages/common/ai/sessions/tests/delete-sessions-for-site.test.ts`. - Run `npm run typecheck`. - Run `npm test -- packages/common/ai/sessions/tests/delete-sessions-for-site.test.ts` and confirm all three tests pass. ## Pre-merge Checklist <!-- Complete applicable items on this checklist **before** merging into trunk. Inapplicable items can be left unchecked. Both the PR author and reviewer are responsible for ensuring the checklist is completed. --> - [x] Have you checked for TypeScript, React or other console errors?
Related issues
How AI was used in this PR
Implemented with Claude Code: mapped the delete flows, wrote the helper, hook, and tests. Verified with lint, typecheck, unit tests, and a CLI smoke test (built CLI against a seeded fake
$HOME). Human-reviewed before opening.Proposed Changes
Testing Instructions
studio site delete --path <site>).~/Library/Application Support/Studio/sessionson macOS) and~/.studio/shared.json/app.jsonno longer reference those session ids.npm test -- packages/common/ai/sessions/tests/delete-sessions-for-site.test.ts apps/cli/commands/site/tests/delete.test.tsPre-merge Checklist
🤖 Generated with Claude Code