Skip to content

fix(extension): scope reusable-tab selection to owned group members#1816

Open
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:fix/extension-1760-scope-reusable-to-owned-group
Open

fix(extension): scope reusable-tab selection to owned group members#1816
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:fix/extension-1760-scope-reusable-to-owned-group

Conversation

@Benjamin-eecs
Copy link
Copy Markdown
Contributor

Description

Re-attempt of #1762 against the post-#1794 model, following the direction left in the close comment:

The real remaining risk from #1760 should be handled against the new model by scoping reusable-tab selection to owned/group tabs (or another explicit ownership signal), not by refusing to adopt the canonical group because the same Chrome window also contains normal user tabs.

findReusableOwnedContainerTab(windowId) in extension/src/background.ts queries every debuggable tab in the candidate window. Under the v1.0.17 convergence model the canonical OpenCLI Adapter / Browser group can land in the user's main Chrome window, where ungrouped http(s) tabs are user content. resolveTab then happily reuses one of those, overwriting the user's open page (#1760).

Add an ownedGroupId parameter to findReusableOwnedContainerTab and three of its four callers that already have the group id. The filter accepts tabs that are in our group, plus about:blank / data: / empty-URL tabs (safe-to-overwrite container blanks), and rejects http(s) tabs that live outside the group. The fourth caller (just-created window, group not yet assigned) keeps the unscoped behavior because that path is reached only with a freshly minted window whose tabs are extension-created.

Related issue: fixes #1760. The previous attempt #1762 was the wrong abstraction and is preserved as the educational close.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Screenshots / Output

New unit test does not reuse a user http tab outside the canonical group when the group has converged into a user window reproduces the #1760 scenario: a window with one ungrouped https://example.com/user-page tab and one in-group about:blank tab, an OpenCLI Adapter group registered against the in-group tab. The test asserts that resolveTabId does not return the user tab id, does not touch the user tab's url or groupId, and that the chosen tab is in the canonical group.

The pre-existing discovers and reuses an existing OpenCLI Adapter group after service worker restart test mocked the post-restart state with the adapter tab outside the canonical group (tabs[0].groupId = -1). Under the v1.0.17 invariant that Chrome group state is source of truth, the realistic state is the tab inside the group, so the test setup is updated to tabs[0].groupId = 99 and the now-redundant expect(chrome.tabs.group).toHaveBeenCalledWith({ groupId: 99, tabIds: [1] }) assertion is dropped. Every other test in the file continues to pass unchanged. Full suite: 80/80.

Live verified on Chrome for Testing 149 with the patched extension loaded. A CDP probe set up the bug state in a single window (one ungrouped https://example.com/users-real-tab, one in-group about:blank named OpenCLI Adapter) and compared the two filter implementations against chrome.tabs.query:

Logic Picked tab
Pre-patch (any debuggable tab) https://example.com/users-real-tab (groupId -1, the user tab)
Patched (group-scoped) about:blank (groupId of the canonical group, the in-group tab)

Stops resolveTab from overwriting a user http(s) tab when the canonical group has converged into a user window.

Fixes jackwener#1760
@Benjamin-eecs Benjamin-eecs marked this pull request as ready for review June 1, 2026 08:55
Copilot AI review requested due to automatic review settings June 1, 2026 08:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR tightens the logic for reusing “owned container” tabs to avoid accidentally reusing user HTTP(S) tabs when an owned tab group converges into a user window.

Changes:

  • Extend findReusableOwnedContainerTab to accept an optional owned group id and filter out HTTP(S) tabs that are not in that group.
  • Update callers to pass the owned group id when looking for a reusable tab.
  • Add a regression test to ensure a user HTTP tab outside the canonical group is not reused in a converged user window scenario.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
extension/src/background.ts Adds owned-group-aware filtering to reusable tab selection and updates call sites.
extension/src/background.test.ts Adds test coverage for not reusing user HTTP tabs outside the canonical group; adjusts an existing test setup.
extension/dist/background.js Compiled output reflecting the source changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +859 to 872
// When a canonical owned group lives in a user window (cross-window
// convergence can land it there), an http(s) tab outside the group is
// user content and must not be reused. Group members and non-http tabs
// (about:blank / data: / fresh container) stay eligible.
const reusable = tabs.find(tab =>
tab.id !== undefined &&
initialTabIsAvailable(tab.id) &&
isDebuggableUrl(tab.url),
isDebuggableUrl(tab.url) &&
(
ownedGroupId === undefined ||
tab.groupId === ownedGroupId ||
!isSafeNavigationUrl(tab.url ?? '')
),
);
Comment on lines +866 to +871
isDebuggableUrl(tab.url) &&
(
ownedGroupId === undefined ||
tab.groupId === ownedGroupId ||
!isSafeNavigationUrl(tab.url ?? '')
),
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.

[Bug] Empty tab group residue causes resolveTab to reuse user's existing tabs instead of creating new automation window

2 participants