Skip to content

feat(extension): default tab selector to the window's active tab - #4756

Merged
iscekic merged 5 commits into
mainfrom
feat/ext-default-active-tab
Jul 25, 2026
Merged

feat(extension): default tab selector to the window's active tab#4756
iscekic merged 5 commits into
mainfrom
feat/ext-default-active-tab

Conversation

@iscekic

@iscekic iscekic commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What

The side panel's target-tab selector now defaults to the browser window's active tab instead of the first-listed tab, whenever the active conversation has no valid stored selection (unset, or pointing at a tab that is no longer inspectable). Resolution priority: valid stored selection > active tab (when inspectable) > first inspectable tab.

New conversations no longer inherit the current conversation's selection. They are created synchronously with no selectedTabId (preserving the create-then-type-immediately contract), then patched with a fresh click-time sample of the active tab — but only if the selection is still unset at patch time, so a manual pick always wins.

Why

Previously the selector defaulted to the first tab returned by chrome.debugger.getTargets() (arbitrary order, never the tab the user is looking at), and new conversations copied the previous selection even when the user had switched context.

How

  • use-tab-debugger.ts: exported getActiveTabId() (never throws; degrades to undefined) and the existing tab-list query now atomically returns { tabs, activeTabId } so both inputs always settle together — the persist effect can never freeze a first-tab default before the active tab arrives.
  • agent-chat-panel.tsx: getSelectedInspectableTabId gains the active-tab priority and is passed at all four call sites. The persist effect gains empty-list and hydration guards (a momentarily empty list or a pre-hydration fallback can no longer wipe a valid stored selection) and is suppressed while a create-default patch is in flight.
  • createConversation(): synchronous store switch without selectedTabId; re-entrancy-guarded fire-and-forget patch that writes only when the selection is still unset.

No manifest or permission changes. Chrome and Firefox share the same code path.

Testing

  • Unit: full resolver priority chain + getActiveTabId edge cases (no active tab, non-numeric id, query rejection).
  • Chrome E2E: probe established locator.click() leaves the activated content tab active; create-path defaults to the activated tab across three-tab legs (activation target always differs from both frozen and first-listed labels); manual pick survives poll cycles; single-tab fallback; hydration-race + freeze reload; empty-list wipe guard; the inverted inheritance test rewritten for the new contract (all distinguishing labels read dynamically).
  • Firefox E2E: mirror scenario rewritten for non-inheritance. Probe confirmed Selenium's switchTo() re-activates the panel tab, so the active-default leg is harness-limited there; the scenario asserts the deterministic first-listed default instead (shared create/resolver code is E2E-covered on Chrome).
  • Full gate green: verify, build, build:firefox, e2e:chrome (57 passed / 10 env-gated skips), e2e:firefox (25/25).

Known harness blind spot (recorded in the approved plan): the production first-conversation active-default needs real side-panel geometry (the panel is not a tab); it is covered by the unit priority tests plus the create-path E2E, not reproducible in the panel-as-tab harness.

@iscekic iscekic self-assigned this Jul 24, 2026
Comment thread apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
@kilo-code-bot

kilo-code-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of the persist-effect rewrite in agent-chat-panel.tsx (re-verifying the target tab against the latest store snapshot inside the updater) found no new high-confidence issues; the fix correctly closes a stale-closure race without introducing new bugs, and the previously flagged createConversation re-entrancy comment remains resolved as working-as-designed.

Files Reviewed (1 file)
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
Previous Review Summaries (2 snapshots, latest commit e3482d8)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit e3482d8)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Full review of the active-tab default logic and its test coverage found no new high-confidence CRITICAL/WARNING issues; the previously flagged re-entrancy no-op on createConversation was resolved by the author as working-as-designed and the thread is resolved.

Files Reviewed (8 files)
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.test.ts
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
  • apps/extension/entrypoints/sidepanel/use-tab-debugger.test.ts
  • apps/extension/entrypoints/sidepanel/use-tab-debugger.ts
  • apps/extension/tests/e2e/conversation-rendering.test.ts
  • apps/extension/tests/e2e/firefox-selenium-e2e.ts
  • apps/extension/tests/e2e/tab-selection-default.test.ts
  • apps/extension/tests/e2e/tab-selection-e2e-helpers.ts

Previous review (commit c2b4808)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The re-entrancy guard on createConversation can silently drop a "New conversation" click while the previous conversation's active-tab patch is still resolving.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx 614 createConversation no-ops with no user feedback while a prior create's async active-tab patch is in flight
Files Reviewed (8 files)
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.test.ts
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx - 1 issue
  • apps/extension/entrypoints/sidepanel/use-tab-debugger.test.ts
  • apps/extension/entrypoints/sidepanel/use-tab-debugger.ts
  • apps/extension/tests/e2e/conversation-rendering.test.ts
  • apps/extension/tests/e2e/firefox-selenium-e2e.ts
  • apps/extension/tests/e2e/tab-selection-default.test.ts
  • apps/extension/tests/e2e/tab-selection-e2e-helpers.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 14 · Output: 3.7K · Cached: 246.8K

Review guidance: REVIEW.md from base branch main

iscekic added 3 commits July 24, 2026 18:58
Sample the side panel window's active tab in the shared tab-list query
and resolve selection as stored > active > first. Persist-effect gains
empty-list and hydration guards so a valid stored selection is never
wiped. New conversations no longer inherit the selection: they are
created synchronously without selectedTabId, then patched with a fresh
click-time active-tab sample when still unset.
Probe established that locator.click() on New conversation leaves the
activated content tab active, so tests use the UI-click recipe. Cover
the create-path active default with three-tab legs whose activation
target always differs from both the frozen and first-listed labels,
manual-pick persistence across poll cycles, single-tab fallback, the
hydration-race and empty-list wipe guards, and rewrite the inheritance
test for the R3 contract.
Rewrite the Firefox mirror of the inverted inheritance scenario under
R3 and rename it for Chrome parity. The A9 probe confirmed that
Selenium's switchTo() re-activates the panel tab, so the create-time
active-tab sample sees the non-inspectable panel: the scenario asserts
the deterministic first-listed default instead of the active-tab
default (harness-limited), with first-listed read dynamically.
@iscekic
iscekic force-pushed the feat/ext-default-active-tab branch from c2b4808 to e3482d8 Compare July 24, 2026 16:59
Prevent a stale fallback write from clobbering a manual target-tab pick
when the create path leaves selectedTabId unset (R3) and React batches
the effect update after the user pick. Found by CI e2e-chrome on the
merged head (conversation controls stay tied to the selected
conversation).
@iscekic
iscekic enabled auto-merge (squash) July 24, 2026 18:15
@iscekic
iscekic merged commit 466024f into main Jul 25, 2026
17 checks passed
@iscekic
iscekic deleted the feat/ext-default-active-tab branch July 25, 2026 08:40
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