Repository navigation
fix(extension): avoid automatic provider transport tabs - #2974
Conversation
Problem: passive backfill and freshness requests created empty ChatGPT\nroot tabs whenever no provider page was open. This disturbed the operator\nbrowser and caused a recurring tab loop.\n\nWhat changed: passive page-context operations now use only an existing\nsupported provider surface and fail with a typed no-surface condition\notherwise. Creating an extension-owned background transport remains limited\nto explicit queued browser actions that mutate provider UI.\n\nCompatibility: passive backfill defers until the next normal provider visit\ninstead of opening a tab itself.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughChangesProvider transport routing
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant BrowserAction
participant background.js
participant chrome.tabs
participant ProviderPage
BrowserAction->>background.js: request ChatGPT transport with allowCreate=true
background.js->>chrome.tabs: find or create provider tab
chrome.tabs-->>background.js: return provider tab
background.js->>ProviderPage: execute transport bridge
ProviderPage-->>background.js: provide transport surface
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.44.1)browser-extension/tests/background.test.jsast-grep timed out on this file 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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9ca9e06d3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
## Summary `tests/build.test.js`'s packaged-service-worker fixture test was failing on master because two of its mocks were stale relative to intentional, already-shipped, already-tested production behavior. This PR fixes only the fixture — no production code changed. ## Problem Ref polylogue-uegw. `tests/build.test.js`'s "executes the packaged service worker fixture without foreground tab activation" test failed: `vi.waitFor` at line 274 timed out because `polylogue.backfill.start` never issued a page request. ## Root-cause evidence Bisected two independent, unrelated fixture defects: 1. **Dead `chrome.tabs.query` mock.** It was `vi.fn(async () => [])`, never reflecting the fixture's own `ownedTabs` array, so `observedProviderTab()` could never find a provider tab. Passive/ automatic backfill is intentionally observe-only by design (`fix(extension): avoid automatic provider transport tabs`, #2974: "Only explicit queued UI actions may create an extension-owned inactive transport"), and is heavily pinned by `background.test.js` ("never creates a transport tab when passive backfill has no provider page", "defers backfill when no supported provider surface is open", "shares an existing provider surface across concurrent backfill jobs"). The fixture's `tabs.create` assertion (expecting the extension to create its own tab) directly contradicted that tested contract. 2. **No seeded receiver pairing.** `stored` never set `polylogueReceiverPairing`, and the fetch mock had no `/v1/status` handler, so `requirePairedTrustedReceiver()` (`fix(extension): require pairing before provider capture`, #2983) always threw `receiver_unpaired` for the exact-capture path. `background.test.js`'s successful-capture fixtures all seed this pairing; `build.test.js` never did. Both gaps were pre-existing, and were already known: PR #2986's own verification note from 2026-07-17 says "one pre-existing packaged-worker fixture failure reproduced unchanged" — this test broke around the same time #2974/#2983 tightened the passive-capture and pairing contracts, and was never updated. **Anti-vacuity check (confirms this is a fixture bug, not a production bug):** I first attempted a production-code fix, threading `allowCreate`/`requirePairing` options through `providerPageFetch`, `providerAccountHandle`, and `captureProviderConversation` in `src/background.js` so backfill could create/use its own tab and skip pairing. That DID make `build.test.js` pass, but it broke 4 `background.test.js` tests that explicitly pin the opposite behavior ("never creates a transport tab when passive backfill has no provider page", "defers backfill when no supported provider surface is open", "shares an existing provider surface across concurrent backfill jobs"). That change was reverted (`git checkout -- src/background.js`); this PR only touches the test. ## Solution In `browser-extension/tests/build.test.js`: - Seed one already-open, operator-owned ChatGPT tab (id 42, matching `background.test.js`'s convention) instead of an empty tab list, and make `chrome.tabs.query` return it dynamically. - Seed `polylogueReceiverPairing` in `stored` and add a `/v1/status` fetch handler, matching how `background.test.js`'s successful-capture fixtures already model a paired receiver. - Replace the incorrect `tabs.create` assertion with `expect(tabs.create).not.toHaveBeenCalled()` — consistent with the test's own name ("without foreground tab activation" is about not materializing/activating a tab at all, not merely not making it foreground) and with the adjacent `tabs.update` assertion. - Update the `tabs.sendMessage` assertion's tab id from the stale fixture-only id 77 to the pre-seeded tab id 42. No production capture behavior changed. Shipped artifacts were never affected by the fixture bug itself, but the two gates the fixture was failing to model (observe-only passive/automatic transport, pairing-gated exact capture) are real, already-shipped invariants this fixture now correctly exercises instead of accidentally bypassing. ## Verification - `npx vitest run tests/build.test.js` — 6/6 passed. - `npx vitest run` (full extension suite) — 378/378 passed, run twice. `tests/background.test.js`'s one known-flaky timing test ("falls back to the adapter's full-fidelity normalization...") failed once on a full-suite run and passed clean when re-run in isolation — pre-existing flake, unrelated to this change, matches the operator's advance note. - `node scripts/validate-manifest.mjs` — manifest ok. - pre-push `devtools verify --quick` — passed (18 steps, 68.7s). Ref polylogue-uegw. Co-authored-by: Claude <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Prevent passive ChatGPT/Claude capture work from opening an empty provider root tab. Passive inventory, recovery, and freshness now observe an already-open supported surface or defer; explicit queued browser actions retain the intentional inactive transport path.
Problem
The periodic freshness sweep and ordinary backfill used the same provider-tab helper as UI-mutating browser actions. When no ChatGPT tab was open, that helper created the ChatGPT root page, so closing all ChatGPT tabs caused another empty tab to materialize on the next automatic pass.
Solution
Ref polylogue-yyvg.6.
Verification
Summary by CodeRabbit
Bug Fixes
Improvements