Skip to content

Android/Duckai/Contextual: Add new menu for chats#8885

Merged
karlenDimla merged 10 commits into
developfrom
feature/karl/duckaicontextual/addmenu
Jun 17, 2026
Merged

Android/Duckai/Contextual: Add new menu for chats#8885
karlenDimla merged 10 commits into
developfrom
feature/karl/duckaicontextual/addmenu

Conversation

@karlenDimla

@karlenDimla karlenDimla commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671677432066/task/1215444384395010?focus=true
Tech Design URL (if applicable):

Description

See https://app.asana.com/1/137249556945/project/1208671677432066/task/1215444384395010?focus=true

Steps to test this PR

contextualSheetImprovements OFF

  • Open a new tab and open an article in cnn.com
  • Select contextual menu icon
  • Verify for the initial state only has the full screen and x icons.
  • Select Summarize This Page and press send
  • Verify new chat icon is shown
  • Select new chat icon
  • Verify contextual sheet is reset

contextualSheetImprovements ON, user with NO recent chats

  • Open a new tab and open an NEW article in cnn.com
  • Select contextual menu icon
  • Verify chats icon is visible next to full screen icon
  • Click on chats icon
  • Verify chat history page is opened
  • Repeat first and second step
  • Select ask about page
  • Select summarize page
  • Verify chats icon is still visible next to full screen icon
  • Click on chats icon
  • Verify chat history page is opened

contextualSheetImprovements ON, user with recent chats

  • Start at least 2 more duck ai session
  • Open a new tab and open an NEW article in cnn.com
  • Select contextual menu icon
  • Verify chats icon is visible next to full screen icon
  • Click on chats icon
  • Verify menu opens
  • Verify menu shows ALL recent chats (max 5 only)
  • Click on a chat
  • Verify it opens on a new tab
  • Re-open contextual sheet again
  • Select ask about page
  • Select summarize page
  • Verify chats icon is still visible next to full screen icon
  • Click on chats icon
  • Verify menu opens
  • Select “View All Chats"
  • Verify chat history page opens
  • Start more duck ai sessions (more than 5)
  • Open contextual sheet again and press chats icon
  • Verify only 5 most recent chats are shown

UI changes

Before:
https://github.com/user-attachments/assets/3d54c3b2-8c4b-4027-8ca2-c632ef83360b

After:
https://github.com/user-attachments/assets/357b595c-60ce-4812-827a-5cb8acb64251
https://github.com/user-attachments/assets/95a5bed9-de65-4654-9270-8903b1cbb7a7
https://github.com/user-attachments/assets/3ee83bab-b340-4f42-8f5c-760ebc4df279


Note

Medium Risk
Changes contextual sheet UX and tab/navigation flows behind a flag, with non-trivial chat-deletion sync logic; mitigated by broad unit tests and unchanged behavior when the flag is off.

Overview
With contextualSheetImprovements, the contextual Duck.ai sheet swaps the legacy new-chat control for a chats icon (visible in input mode too) and wires it to ChatHistoryRepository.

Tapping chats keeps legacy behavior when the flag is off (still starts a new chat). When the flag is on, no recent history opens full chat history; with recents shows a new popup_contextual_chats_menu (optional New Chat in WEBVIEW, up to five other chats excluding the current one, View All). Selections open a chat in a new browser tab or launch chat history, and the sheet closes first.

The ViewModel adds observeRecentChats, popup/open/history commands, and observeCurrentChatDeletion so if the loaded chat disappears from history after it was seen, the sheet resets to input without changing bottom-sheet visibility (renderNewChatState(sheetState = null)). DuckChatContextualViewModelTest covers menu flows, caps/sorting, and deletion edge cases.

Reviewed by Cursor Bugbot for commit d778585. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

karlenDimla and others added 9 commits June 16, 2026 16:57
…extualSheetImprovements

When the flag is on, the top-bar "+" icon becomes a chats icon shown in
both INPUT and WEBVIEW modes. Clicking opens a popup with up to 5 recent
chats and a "View all chats" footer (and a "New chat" header in WEBVIEW
mode); with no history it falls through to the legacy new-chat action.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…iew all footer

Each recent chat row now shows its per-type icon (matching chat
suggestions), and the View all chats footer uses ic_open_in_24.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sized labels

Adds a "Recent chats" section header above the chat rows, caps every
popup row's title at 3 lines, and ellipsizes with "…" when truncated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the 5 static PopupMenuItemView slots with an empty container
and inflates one row per chat at runtime, so the popup grows naturally
with the available history.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…with no recent chats

Previously fell through to a new-chat reset; now the user lands on the
chat history screen so they can see (or seed) their history.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@karlenDimla karlenDimla force-pushed the feature/karl/duckaicontextual/addmenu branch from 366dd80 to 04091d8 Compare June 16, 2026 15:01
}
if (state.recentChats.isEmpty()) {
onViewAllChatsClicked()
} else {

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.

WEBVIEW chats icon skips new chat

High Severity

With contextualSheetImprovements on, onChatsIconClicked sends users to chat history whenever recentChats is empty. In WEBVIEW mode that list is often empty because the active chat is filtered out, so tapping the toolbar control no longer starts a new chat and instead closes the sheet and opens history.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 04091d8. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is expected behavior. If the new icon is clicked and there are not any other recent chats, we should show the chat history instead.

…here

When the chat currently loaded in the contextual sheet's webview is
deleted from another part of the app (chat history, clear-all, fire
button), reset the sheet to its initial INPUT state instead of keeping
the now-deleted chat. Gated behind contextualSheetImprovements.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@karlenDimla karlenDimla force-pushed the feature/karl/duckaicontextual/addmenu branch from 6a63080 to d778585 Compare June 17, 2026 12:26

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d778585. Configure here.

}
.flowOn(dispatchers.io())
.onEach { recent -> _viewState.update { it.copy(recentChats = recent) } }
.launchIn(viewModelScope)

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.

Stale chat id after tab switch

High Severity

Opening the contextual sheet on a tab with no stored chat URL updates tabId and SheetMode.INPUT but leaves _chatId and lastSeenChatId from the previous tab’s session. The new recent-chats flow then hides that id from the menu, and observeCurrentChatDeletion can call handleLoadedChatDeleted when the user sends a prompt (WEBVIEW) if that stale chat no longer exists in history—resetting the sheet mid-flow.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d778585. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ve tested and I don’t think this should actually happen. There is no case where the contextual sheet can be opened from a tab with no url but has previously been used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is arguably not a real defect at all under the current architecture.
The report's entire severity case rests on one mechanism: state from "the previous tab's session" bleeding into a new tab. That requires a ViewModel shared across tabs. There isn't one — each tab gets its own DuckChatContextualFragment with a fixed tabId and its own FragmentScope ViewModel, and onSheetOpened runs once per fragment. So:

"leaves _chatId/lastSeenChatId from the previous tab" — can't happen; a new tab's VM starts with both null.
"recent-chats flow hides that id" — only hides whatever this VM's _chatId is, which is null on a fresh INPUT sheet. Nothing wrongly hidden.
"observeCurrentChatDeletion resets mid-flow when you send a prompt" — needs a stale non-null _chatId at prompt time. Within one tab, _chatId is coupled to the persisted URL (set/cleared together), so when the
no-stored-URL branch runs _chatId is already null, and the deletion observer's currentChatId != null guard short-circuits.

@YoussefKeyrouz YoussefKeyrouz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Works well. Tested different scenarios. Thanks for fixing the issue with burning the chat.

If you can just take a look at the bugbot comment as it was marked as high.

@karlenDimla karlenDimla merged commit 6644af0 into develop Jun 17, 2026
26 checks passed
@karlenDimla karlenDimla deleted the feature/karl/duckaicontextual/addmenu branch June 17, 2026 15:11
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.

2 participants