Skip to content

Conversation

@malmstein
Copy link
Contributor

@malmstein malmstein commented Jan 30, 2026

Task/Issue URL: https://app.asana.com/1/137249556945/project/1157893581871903/task/1213010969250403?focus=true

Description

This PR adds the changes agreed in the Ship Review for the context attachment feature

Steps to test this PR

Make sure you enable contextualMode and automaticContextAttachment FF
Turn Automatic Context Attachment in Settings / AI Features

New context UI

  • Open Contextual Mode
  • Verify “Attach Page Context” is visible
  • Tap on “Attach Page Context”
  • Verify context has been attached
  • Remove the context
  • Tap on “Summarise Page Content"
  • Verify that the context has been attached and the prompt has been added
  • Tap on Send
  • Verify Duck.ai opens with prompt and context

Automatic context attachment - Setting ON

  • Open Contextual Mode
  • Enter a prompt
  • Verify Duck.ai opens without context attached
  • Verify that the context has been added to the web input
  • Enter any prompt
  • Verify context is added

Automatic context attachment - Setting OFF

  • Turn Automatic Context Attachment iOFF n Settings / AI Features
  • Open Contextual Mode
  • Verify context is not attached
  • Enter a prompt
  • Verify Duck.ai opens without context attached
  • Verify that the context has not been added to the web input
  • Enter any prompt
  • Verify context is not added

Note

Medium Risk
Changes when and how page content is attached/sent to Duck.ai via the JS bridge and new feature-flag checks, which can affect privacy-sensitive context sharing and session persistence behavior.

Overview
Duck.ai contextual mode now has explicit, gated page-context attachment behavior. Automatic context attachment on init is only sent when both the new automaticContextAttachment remote toggle and the user setting are enabled (while userAction requests still return context), and the JS bridge now receives an explicit userEnabledContextAttachment flag.

Contextual sheet UX/behavior is updated. The UI adds a dedicated “Attach Page Content” affordance, a clear-text button, tweaks layout sizing/padding, and adjusts bottom-sheet state changes (less forced half/expanded transitions, more logging). URL persistence is tightened to only store chat URLs when in webview mode, with tests updated/added to cover the new gating and persistence rules.

Written by Cursor Bugbot for commit 325271b. This will update automatically on new commits. Configure here.

Copy link
Contributor Author

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

@malmstein malmstein force-pushed the feature/david/01-30-duck.ai_contextual_page_context_attachment branch from 88fbfc1 to 9f0e813 Compare February 2, 2026 21:32
@malmstein malmstein marked this pull request as ready for review February 2, 2026 22:26
Copy link

@cursor cursor bot left a comment

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 3 potential issues.

contextTitle = title,
contextUrl = url,
tabId = tabId,
showContext = _viewState.value.allowsAutomaticContextAttachment && _viewState.value.showContext,
Copy link

Choose a reason for hiding this comment

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

Automatic context attachment never auto-attaches due to AND logic

High Severity

The logic showContext = _viewState.value.allowsAutomaticContextAttachment && _viewState.value.showContext in onPageContextReceived prevents automatic context attachment from working. Since showContext initially starts as false, the AND operation always evaluates to false even when automatic attachment is enabled. This causes the "init" request from the web to never receive page context, as the JS helper checks userEnabledContextAttachment && isAutomaticContextAttachmentEnabled(). The operator likely needs to be || (OR) instead of && (AND) to auto-attach when the feature is enabled.

Fix in Cursor Fix in Web


private fun ensureBrowserIsCompatibleWithContextualSheetState() {
val bottomSheetBehavior = BottomSheetBehavior.from(binding.duckAiContextualFragmentContainer)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
Copy link

Choose a reason for hiding this comment

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

Sheet state command dropped due to channel overflow

Medium Severity

The removal of bottomSheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED from ensureBrowserIsCompatibleWithContextualSheetState() causes the sheet to potentially appear in an incorrect state. The commandChannel has capacity 1 with DROP_OLDEST overflow, and onSheetOpened sends ChangeSheetState followed immediately by LoadUrl. The first command is dropped when the second is sent, so the sheet state is never set. Previously, the direct state assignment provided a guaranteed initial state that is now missing.

Additional Locations (1)

Fix in Cursor Fix in Web

null
}
} else {
logcat { "Duck.ai Contextual: page context is empty, can't add it" }
Copy link

Choose a reason for hiding this comment

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

Duplicated function calls can be consolidated

Low Severity

getPageContextResponse(featureName, method, it, pageContext) is called identically in two separate branches (lines 163 and 165). These could be consolidated into a single call using a combined condition:

if (pageContext != null && (reason == REASON_USER_ACTION || (reason == REASON_INIT && shouldAddContext))) {
    getPageContextResponse(featureName, method, it, pageContext)
} else { ... }

Fix in Cursor Fix in Web

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