Skip to content

fix(ui): ensure session deletion properly clears backend and cache#12043

Open
keval718 wants to merge 7 commits intorelease-1.8.0from
fix/deleted-messages-remain-in-llm-context
Open

fix(ui): ensure session deletion properly clears backend and cache#12043
keval718 wants to merge 7 commits intorelease-1.8.0from
fix/deleted-messages-remain-in-llm-context

Conversation

@keval718
Copy link
Collaborator

@keval718 keval718 commented Mar 4, 2026

Problem

In release-1.8.0, the session deletion logic was failing to properly purge data from both the UI and backend, manifesting in two critical ways:

Context Persistence: Deleting the "Default Session" cleared the chat UI, but the LLM retained memory of previous messages
Data Leakage/Reuse: Deleting a numbered session (e.g., "New Session 0") and creating a new one caused the system to reuse the old session's data, with messages from the deleted session immediately reappearing

Root Cause
The system was performing "shallow deletions" that only affected the sidebar UI. The backend deletion API was never called for numbered sessions due to a conditional check that required the session to be in the dbSessions list first.

Testing
✅ Verified numbered sessions now call backend API on deletion
✅ Confirmed Message Logs shows empty state after deletion
✅ Tested session recreation doesn't reuse old data
✅ Verified no context persistence after deletion

@keval718 keval718 requested a review from viktoravelino March 4, 2026 19:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66082dc0-92ce-42dc-b872-70afbe4bae52

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/deleted-messages-remain-in-llm-context

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Mar 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 23%
23.27% (8148/35009) 15.97% (4390/27476) 16.12% (1188/7367)

Unit Test Results

Tests Skipped Failures Errors Time
2653 0 💤 0 ❌ 0 🔥 46.105s ⏱️

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 0% with 39 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-1.8.0@73aad93). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ollers/API/queries/messages/use-delete-sessions.ts 0.00% 21 Missing ⚠️
.../chat-view/chat-messages/hooks/use-chat-history.ts 0.00% 9 Missing ⚠️
...ygroundComponent/chat-view/utils/session-filter.ts 0.00% 6 Missing ⚠️
...at-view/chat-header/hooks/use-edit-session-info.ts 0.00% 2 Missing ⚠️
...end/src/modals/IOModal/components/session-view.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##             release-1.8.0   #12043   +/-   ##
================================================
  Coverage                 ?   37.16%           
================================================
  Files                    ?     1592           
  Lines                    ?    78102           
  Branches                 ?    11842           
================================================
  Hits                     ?    29023           
  Misses                   ?    47425           
  Partials                 ?     1654           
Flag Coverage Δ
backend 57.28% <ø> (?)
frontend 20.83% <0.00%> (?)
lfx 41.50% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...hat-view/chat-header/hooks/use-get-add-sessions.ts 0.00% <ø> (ø)
...end/src/modals/IOModal/components/session-view.tsx 0.00% <0.00%> (ø)
...at-view/chat-header/hooks/use-edit-session-info.ts 0.00% <0.00%> (ø)
...ygroundComponent/chat-view/utils/session-filter.ts 0.00% <0.00%> (ø)
.../chat-view/chat-messages/hooks/use-chat-history.ts 0.00% <0.00%> (ø)
...ollers/API/queries/messages/use-delete-sessions.ts 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@keval718 keval718 self-assigned this Mar 4, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Mar 4, 2026
Copy link
Member

@Cristhianzl Cristhianzl left a comment

Choose a reason for hiding this comment

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

🟠 NEEDS CHANGES

Must fix (blockers):

  1. DRY violation — Extract session filtering logic into a shared isMessageForSession(msg, flowId, session) helper used by both the useEffect initializer and the useMemo display filter
  2. any types — Replace 6+ any usages in use-delete-sessions.ts with proper types. The original code used useMutationFunctionType — either keep using it or define DeleteSessionResponse and Error types
  3. Unnecessary cast — Remove as unknown as DeleteSessionParamsvariables is already typed correctly

Should fix:
4. Tests — Add regression tests for the data leakage fix, at minimum covering: (a) delete removes cache, (b) new session after delete starts clean, (c) session filtering correctness
5. sessionStorage double-write — Either remove the explicit sessionStorage cleanup in removeLocalSession (since the useEffect on line 67-77 already handles it), or add a comment explaining why both are needed (race condition?)

Nice to have:
6. Simplify ExtendedMessageProperties — the base Message type has [key: string]: unknown so the extension adds no type safety
7. Change comments from WHAT to WHY
8. Consider centralizing query key factories to avoid tight coupling in predicate-based cache removal

@keval718
Copy link
Collaborator Author

keval718 commented Mar 4, 2026

🟠 NEEDS CHANGES

Must fix (blockers):

  1. DRY violation — Extract session filtering logic into a shared isMessageForSession(msg, flowId, session) helper used by both the useEffect initializer and the useMemo display filter
  2. any types — Replace 6+ any usages in use-delete-sessions.ts with proper types. The original code used useMutationFunctionType — either keep using it or define DeleteSessionResponse and Error types
  3. Unnecessary cast — Remove as unknown as DeleteSessionParamsvariables is already typed correctly

Should fix: 4. Tests — Add regression tests for the data leakage fix, at minimum covering: (a) delete removes cache, (b) new session after delete starts clean, (c) session filtering correctness 5. sessionStorage double-write — Either remove the explicit sessionStorage cleanup in removeLocalSession (since the useEffect on line 67-77 already handles it), or add a comment explaining why both are needed (race condition?)

Nice to have: 6. Simplify ExtendedMessageProperties — the base Message type has [key: string]: unknown so the extension adds no type safety 7. Change comments from WHAT to WHY 8. Consider centralizing query key factories to avoid tight coupling in predicate-based cache removal

Fixed. Thanks

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Mar 4, 2026
@keval718 keval718 force-pushed the fix/deleted-messages-remain-in-llm-context branch from 3cb08a6 to 617d634 Compare March 4, 2026 21:30
@keval718 keval718 requested a review from Cristhianzl March 4, 2026 21:31
@github-actions github-actions bot removed the bug Something isn't working label Mar 4, 2026
@github-actions github-actions bot added the bug Something isn't working label Mar 4, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants