Skip to content

fix(extension): gate tab capture on receiver pairing - #2986

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/receiver-required-posts
Jul 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/receiver-required-posts

Conversation

@Sinity

@Sinity Sinity commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Prevents a stale content script in an existing provider tab from posting a capture to the local receiver after the extension has been reset or is unpaired.

Problem

Live daemon telemetry continued to record unauthenticated browser-capture requests after automatic capture was disabled and the current service worker reported no receiver pairing. The direct polylogue.capture message path bypassed the earlier automatic-provider gate, so content scripts surviving a reload could still reach postJson.

Ref polylogue-yyvg.6.1.

Solution

The shared tab-originated capture handler now requires a paired, trusted receiver before it submits /v1/browser-captures. This covers ordinary content scripts and stale injected scripts without changing non-tab receiver diagnostics or explicit configuration flows. An unpaired capture records its held state but makes no receiver fetch and creates no retry entry.

Verification

  • npm test -- --run tests/background.test.js — 81 passed.
  • npm run lint — passed.
  • npm run validate — manifest valid.
  • npm test — 320 passed; one known pre-existing failure remains in tests/build.test.js::...packaged service worker fixture without foreground tab activation, reproduced unchanged.
  • devtools verify --quick — passed.

Summary by CodeRabbit

  • Bug Fixes
    • Content captures are now blocked when the browser extension is not paired with a trusted receiver.
    • Prevents stale content scripts from sending capture requests without valid receiver pairing information.
    • Improved capture retry and receiver diagnostic handling for more reliable capture behavior.

Problem: content scripts that survived an extension reload could still submit an unauthenticated capture even after automatic capture was paused and receiver pairing was reset.

What changed: tab-originated capture messages now require a paired, trusted receiver before the receiver POST. The focused regression verifies the unpaired path makes no fetch or retry-queue entry.

Ref polylogue-yyvg.6.1.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1b999bd9-1bd7-407f-abf8-0af69d41ad6d

📥 Commits

Reviewing files that changed from the base of the PR and between 807fbf3 and b5b22ac.

📒 Files selected for processing (2)
  • browser-extension/src/background.js
  • browser-extension/tests/background.test.js

📝 Walkthrough

Walkthrough

Content-script captures now require a paired trusted receiver before receiver requests proceed. Background tests update pairing and status mocks, add unpaired-capture assertions, and track capture retry attempts separately from status checks.

Changes

Receiver pairing capture flow

Layer / File(s) Summary
Enforce paired receiver for content captures
browser-extension/src/background.js
Tab-originated polylogue.capture messages now require a paired trusted receiver before posting capture data.
Update pairing and retry coverage
browser-extension/tests/background.test.js
Tests initialize receiver pairing, separate /v1/status responses from capture requests, verify unpaired rejection and ledger state, and assert retry attempts through captureCalls.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/receiver-required-posts

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.js

ast-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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 26c6a3e into master Jul 17, 2026
1 of 2 checks passed
@Sinity
Sinity deleted the feature/fix/receiver-required-posts branch July 17, 2026 08:24
Sinity added a commit that referenced this pull request Jul 17, 2026
Problem: ~15 P0/P1 beads carried in_progress claims from sessions closed
on 2026-07-17, making bd ready misreport availability; some had
substantial merged work that the claim state hid.

What changed: per-bead verification against master commits since
2026-07-14. Six no-work claims reset to open (1xc.14.1.2, 1xc.14.1.3,
2qx.2, 2qx.1.1, h6r, 41ow). Eight partials reset to open with commit
receipts and residue notes (1xc.14.1, 1xc.14.1.1, b054.1.1, yeq.3,
9e5.31, 3v1, ptx, yyvg.7). Three flagged for adjudication without status
change: yyvg.6.1 (verify-for-close vs #2981-#2986), cuxz.2 (overlap with
#3033), 1xc.13 (awaiting two operator live receipts only). Lane-owned
claims (z9gh cluster, hjpx/yla8/lkrc, 866e, t8t, hjpx.2, t46.8.1) and
fifth-lane beads (yyvg.6, 1vpm.6.1) left untouched.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ
Sinity added a commit that referenced this pull request Jul 18, 2026
…3098)

## Summary
Four commits closing AC gaps on the three P0 extension beads flagged by
the 2026-07-17 warroom It.17 sweep, all scoped to `browser-extension/` +
receiver code:

1. `polylogue-yyvg.6.1` AC1: a deterministic fixture proving no ChatGPT
conversation/attachment request occurs for a terminal conversation
across a receiver outage *combined with* a simulated service-worker
restart.
2. `polylogue-ptx` AC6: a static/contract test rejecting reintroduction
of the retired `BrowserPostCommand`/`BrowserLaunchJob` campaign
machinery or campaign-identity vocabulary.
3. `polylogue-ptx` AC7: receiver-side coverage of all six typed
pre-submit failure outcomes (the extension side already had it; the
receiver's identical state-machine branch did not).
4. `polylogue-yyvg.7`: a real (partial) slice of the exception-driven
popup redesign — a single-item `computeAttention()` surface plus a
pending-browser-action count, and progressive-disclosure diagnostics for
the previously always-visible machinery (receiver pairing/reset, work
queue, backfill panel, raw logs, receiver settings).

## Problem
All three beads had their core behavior land already (`yyvg.6.1` via
#2977/#2979/#2981/#2983/#2986; `ptx` via #2928; `yyvg.7`'s first UX
slice via #2928/#2929) but were left open pending explicit AC-by-AC
checks, and several AC clauses specifically wanted *fixtures*, *guards*,
or *UI surfaces* that didn't exist yet — see full AC-by-AC verdicts
recorded in each bead's notes (`polylogue-yyvg.6.1`, `polylogue-ptx`,
`polylogue-yyvg.7`).

## Solution
- `browser-extension/tests/background.test.js`: new fixture combining a
receiver outage with a simulated service-worker restart against a
terminal conversation.
- `tests/unit/architecture/test_browser_action_conduit_vocabulary.py`:
static scan over `polylogue/browser_capture/`,
`polylogue/daemon/browser_capture.py`, and `browser-extension/src/`.
- `tests/unit/browser_capture/test_actions.py`: parametrized
`test_typed_provider_failures_block_and_release_the_lease` over all six
receiver failure outcomes.
- `browser-extension/src/operator_status.js`: new `computeAttention()`
(strict single-item typed priority list: auth/pairing mismatch → action
`outcome_unknown` → capability mismatch → archive failure → null) and
`pendingBrowserActionCount()`, added to the existing shared status
module already used by ambient/message-layer/popup.
- `browser-extension/src/popup.html` + `popup.js`: a "Pending browser
actions" count and hidden-by-default "Attention" section under the
header; receiver pairing/reset, work queue, backfill panel, recent
capture log, debug log, and receiver settings now live inside one
collapsed `<details id="diagnostics">`. Clicking an attention item's
action opens diagnostics and drives the real underlying control (no
second authority copy).

**Honesty on scope**: commit 4 is explicitly a partial yyvg.7 slice, not
full closure — pixel-level mockup convergence, a compact bounded "Now"
summary, the "explicit submit/destructive approval" and "destructive
conflict" attention categories (no backing data model yet), a DOM/height
budget check, and the live installed proof all remain open. Recorded
honestly in the bead notes rather than claimed done.

## Verification
- `npx vitest run` (in `browser-extension/`) → 335 passed, 1
pre-existing unrelated failure (packaged service-worker backfill fixture
in `tests/build.test.js`; reproduced unchanged on a clean tree with this
branch's changes stashed out)
- `npm run lint` / `npm run validate` (in `browser-extension/`) → clean
/ manifest ok
- `devtools test
tests/unit/architecture/test_browser_action_conduit_vocabulary.py` → 1
passed
- `devtools test tests/unit/browser_capture/test_actions.py` → 18 passed
- `devtools verify --quick` (pre-push hook, all four pushes) → exit 0

Ref polylogue-yyvg.6.1, polylogue-ptx, polylogue-yyvg.7

---------

Co-authored-by: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 31, 2026
## 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]>
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.

1 participant