Repository navigation
feat(capture): extension trust surface — automatic UX, spool health, pairing (polylogue-yyvg.7 + 3v1 + gnie) - #3260
Conversation
…etry
Problem: polylogue-gnie's remaining defect was token adoption -- a fresh
extension install had to view/copy/paste the receiver's long-lived bearer
token. polylogue-3v1's capture-gap/error telemetry design ask ("extension
failures land nowhere the daemon can report") was also unimplemented.
What changed:
- polylogue/browser_capture/pairing.py: a short-lived (default 180s),
single-use, rate-limited (5 wrong guesses) pairing code, minted via
`polylogued browser-capture pairing start` and exchanged for the current
bearer token via `POST /v1/pairing/redeem`. Only the code's SHA-256 hash
is ever persisted; the plaintext code and the token are never both in the
same place except the in-flight loopback response.
- polylogue/browser_capture/server.py: `/v1/pairing/redeem` is
origin-checked but deliberately unauthenticated (its purpose is
bootstrapping the token an unpaired caller does not have yet).
`/v1/capture-health` (POST report, GET list) is bearer-gated like every
other route and stores events in the existing ops.db `daemon_events`
ledger under kind `browser_capture_health`, reusing
`polylogue.daemon.events.emit_daemon_event`/`query_daemon_events` rather
than adding a new table.
- polylogue/daemon/browser_capture.py: `pairing start` and `capture-health`
CLI commands.
- polylogue/browser_capture/route_contracts.py: contract entries for the
three new routes, including a new `unauthenticated_pairing_exchange` auth
policy value.
Not attempted (see PR body AC matrix): the design's *recommended*
installer-managed native-messaging bootstrap (needs an OS-level host
manifest and stable extension identity this repo cannot install or test
headlessly) and automatic token-rotation recovery, which the design
associates with that native-messaging path specifically.
Verification: `devtools test tests/unit/browser_capture/` (146 passed,
including 18 new pairing/capture-health tests exercising real HTTP against
the threaded receiver server); `mypy` clean on touched files; `ruff check`/
`format` clean; `devtools render all --check` exit 0 (new pairing.py module
required a topology-projection regen).
Problem: the popup's only pairing path was a manual "Bearer token" field -- the operator had to run `token show` and paste the receiver's long-lived secret. The receiver's new `POST /v1/pairing/redeem` route (this branch, prior commit) exists specifically so a fresh install never needs that. What changed: - background.js: `redeemPairingCode(baseUrl, code)` posts to `/v1/pairing/redeem` with no Authorization header (mirrors `probeReceiverStatus`'s debug-log/timeout/abort pattern, but cannot reuse `postJson` -- that requires an already-trusted receiver, circular for an unpaired install). `pairWithCode(code)` saves the returned token via the existing `saveReceiverSettings` path and confirms health without canonical-endpoint auto-recovery (same posture as an explicit settings save). New `polylogue.pairWithCode` runtime message. - popup.html/popup.js: a "Pairing code" field + Pair button inside the existing collapsed `<details id="diagnostics">` receiver-settings section, next to the manual bearer-token field it complements (does not replace manual entry, which remains the break-glass path). Lives inside diagnostics, so the yyvg.7 always-visible DOM/action budget test is unaffected. Verification: `npx vitest run` (347 passed; the 1 failing build.test.js service-worker-fixture-timing test is pre-existing -- reproduced identically on the pre-change tree via `git stash`); `npm run lint`/`validate` clean.
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (15)
✨ Finishing Touches🧪 Generate unit tests (beta)
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: 74b74ebe98
ℹ️ 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".
| try: | ||
| token = redeem_pairing_code(request.code) |
There was a problem hiding this comment.
Return the receiver's configured token during redemption
When the receiver is started with an explicit token through --auth-token or daemon.browser_capture.auth_token, this call loads or mints the archive token file instead of returning self.server.config.auth_token. Redemption therefore reports success but gives the extension a token the running receiver will reject on every authenticated request, breaking pairing for a documented configuration.
Useful? React with 👍 / 👎.
| const health = await checkReceiverHealth({ allowCanonicalRecovery: false }); | ||
| return { ok: true, health, pairing: health.pairing || (await storedReceiverPairing()) }; |
There was a problem hiding this comment.
Adopt the redeemed receiver identity when re-pairing
When an extension with an existing pairing uses a code after the receiver identity changes, such as after an archive/profile reseed, checkReceiverHealth compares the new identity with the retained old one and returns pairing_mismatch. This code nevertheless returns ok: true, so the popup says “Paired,” clears the now-consumed code, and never adopts result.receiverId; an explicit code redemption should authorize replacing the old identity and should not report success while health remains mismatched or unauthorized.
Useful? React with 👍 / 👎.
| self._send_json( | ||
| HTTPStatus.ACCEPTED, | ||
| BrowserCaptureHealthEventAcceptedPayload(event_id=get_latest_event_id()).model_dump(mode="json"), |
There was a problem hiding this comment.
Return the inserted capture-health event ID
Under concurrent reports handled by ThreadingHTTPServer, another request can insert an event after this request commits but before get_latest_event_id() runs. The response will then identify the other request's row, and multiple callers can receive the same event_id; the insert operation should return its own SQLite lastrowid rather than querying the global maximum afterward.
Useful? React with 👍 / 👎.
Problem: - tests/unit/daemon/test_daemon_http_security.py::TestNoTokenLogging::test_no_token_in_log_or_print_calls: the AST-based token-output scanner flagged two legitimate call sites its name-based taint tracking can't distinguish from real secret leaks: `_handle_query_units` (polylogue/daemon/http.py) echoes decoded query results, not the client-supplied `continuation_token` pagination cursor itself, back via `_send_json`; `_pairing_redeem` (polylogue/browser_capture/server.py, #3260) deliberately returns a freshly-issued `auth_token` to the client that just redeemed its one-time pairing code -- that disclosure IS the endpoint's whole purpose. - tests/unit/daemon/test_route_contracts.py::test_rebuild_index_handler_forwards_resumable_pass_options_through_writer_bridge: the handler (polylogue/daemon/http.py:_handle_rebuild_index, polylogue-ogn1) calls `write_bridge.run_sync_with_timeout(...)` (a longer-timeout variant sized for a bounded rebuild pass) instead of the bridge's default-timeout `run_sync`; the test still mocked/asserted on `run_sync`, so `call_args` was `None` and unpacking it raised `AttributeError` before the test's own assertions ran. - tests/unit/daemon/test_health_contract.py::TestTierInventoryContract::test_medium_tier_inventory_pinned: #3362 ("add provider format-drift sentinel over live ingest") added a new MEDIUM-tier health check (`_check_schema_drift_medium`, polylogue/daemon/health.py) that was never added to this test's pinned `EXPECTED_MEDIUM_CHECKS` inventory. What changed: - test_daemon_http_security.py: added both call sites to `intentional_secret_outputs` with rationale comments. - test_route_contracts.py: updated the mock/assertion to `run_sync_with_timeout` (actor, timeout, function, request) instead of `run_sync` (actor, function, request). - test_health_contract.py: added `"schema_drift"` to `EXPECTED_MEDIUM_CHECKS`. Verification: - devtools test tests/unit/daemon/test_daemon_http_security.py tests/unit/daemon/test_route_contracts.py tests/unit/daemon/test_health_contract.py -> 679 passed. Ref polylogue-c66i Co-Authored-By: Claude <[email protected]>
Summary
Delivers the browser-capture receiver+extension pairing-bootstrap and
capture-health-telemetry slice of the extension trust-surface cluster
(Ref polylogue-yyvg.7, Ref polylogue-3v1, Ref polylogue-gnie). Two commits:
receiver/CLI infrastructure (Python), then the extension-side pairing UI
that consumes it (JS).
Problem
receiver's auto-minted bearer token except the operator running
polylogued browser-capture token showand pasting the 43-charactersecret into the popup. The bead's own notes call this out explicitly as
the still-open defect after the underlying auth machinery (PR fix(browser-capture): stable receiver identity survives token rotation #3245,
jlme.5) shipped: "the prior close treated CLI copy/paste as equivalent to
automatic token adoption. It is not."
telemetry ("extension errors post to the receiver as capture-health
events -> ops.db -> daemon /metrics + status ... the extension becomes an
observable component") so that capture gaps/errors are queryable archive
history rather than only visible transiently in the popup. This did not
exist.
through 2026-07-19), the popup/badge/attention-model redesign is already
substantially shipped across five prior merged PRs (feat(browser): expose autonomous conversation transport (#2928) #2928, close AC gaps on yyvg.6.1/ptx + add popup attention surface (yyvg.7) #3098, feat(yyvg.7): compact active-card, DOM/action budget, and mockup visual convergence #3126,
fix(browser-capture): scope receiver token + spool root under archive_root #3137, fix(yyvg.7): stop a stale mission snapshot overriding a fresher ledger read #3139). What remains open per the bead's own AC-by-AC record is
either blocked on a data model that does not exist yet (explicit-
approval/destructive-conflict attention categories) or requires live
installed-browser proof the bead's notes say was already attempted and
partially completed by a prior session.
Solution
polylogue-gnie — one-time pairing code (compatibility fallback per the
bead's own design text): the bead's recommended primary design is an
installer-managed native-messaging host; this repo cannot install an OS-level
native-messaging manifest or exercise a real, stable
chrome-extension://identity headlessly, so that path is genuinely out of scope for an
unattended session. The design text names an explicit fallback instead —
"a user-presence one-time pairing approval/code that transfers the secret
without copy/paste" — and that is what this PR implements:
polylogue/browser_capture/pairing.py(new): mints an 8-character,40-bit-entropy, single-use, 180s-default-TTL code; only its SHA-256 hash
is ever persisted (
browser-capture-pairingfile under the archiveroot, same 0600-atomic-write pattern as the bearer token). 5 wrong
guesses burn the pending code even before its TTL expires.
POST /v1/pairing/redeem(new route,polylogue/browser_capture/server.py):deliberately unauthenticated — bootstrapping the token is its job — but
still origin-checked (
_reject_origin), so an arbitrary webpage cannotforge the extension's
chrome-extension://origin to redeem a code itsomehow observed.
polylogued browser-capture pairing start [--ttl-seconds]CLI prints thecode; the extension's new popup "Pairing code" field (inside the existing
collapsed diagnostics section, next to the manual bearer-token field it
complements rather than replaces) exchanges it automatically via
background.js's newpairWithCode/redeemPairingCode.design explicitly ties that behavior to the native-messaging host path,
which is out of scope here. Manual re-pairing (paste the token, or run
pairing startagain) remains the break-glass/recovery route.polylogue-3v1 — capture-health telemetry, producer side deferred:
POST /v1/capture-health(bearer-gated like every other route) andGET /v1/capture-health(new routes): events are stored in the existingops.db
daemon_eventsledger underkind="browser_capture_health",reusing
polylogue.daemon.events.emit_daemon_event/query_daemon_eventsrather than adding a new table (
ops.dbis a freeform-additivedisposable tier — see
fts_drift_samplesprecedent).polylogued browser-capture capture-health [--limit]CLI lists recentevents without an HTTP round trip.
mismatch (page-visible vs. archived message count) and call this new
endpoint automatically. The receiver-side ledger, query surface, and CLI
are real and tested; the producer that would make gaps self-report is a
distinct, still-open chunk of work (the extension has no existing
visible-vs-captured comparison to hook — a genuine follow-up, not a
trivial wire-up). Gemini bridge coverage (
gemini.google.comhostpermission + content-script bridge) is likewise not attempted — a full
new provider bridge is out of scope for this slice.
polylogue-yyvg.7 — no additional code in this PR. Verified the bead's
own AC-by-AC record against current
main(popup.js/operator_status.js/popup.html) and confirmed the prior sessions' claims hold: compact
always-visible surface, single-attention-item model, shared status module,
DOM/action budget test, and the F1/F6 visual convergence are all present
in the current tree. What the bead's notes list as still open — explicit-
approval/destructive-conflict attention categories (blocked on a data
model ptx does not yet expose) and literal live-installed offline-recovery
proof — are unchanged by this PR; both require capability or environment
this session does not have (a real backing data model for the former, a
disposable second receiver + real browser for the latter).
Verification
devtools test tests/unit/browser_capture/— 146 passed(18 new:
tests/unit/browser_capture/test_pairing.py, real HTTP againstthe threaded
BrowserCaptureHTTPServer, plus CLI round-trips viaCliRunner).mypyclean on touched files.devtools verify --quickexit 0 (
.cache/verify/runs/20260721T234119Z-quick-765869-deca05d8).devtools render all --checkexit 0 (newpairing.pymodule required atopology-projection regen, included).
npx vitest run— 347 passed / 1 failed. The 1 failure(
build.test.jsservice-worker-fixture timing) is pre-existing andunrelated — reproduced identically with this branch's diff stashed out
(
git stash && npx vitest run tests/build.test.jsfails the same way).npm run lintandnpm run validate(manifest) both clean.test_pairing_redeem_route_pairs_without_a_preexisting_tokenexercises the real
write_capture_envelope-adjacent HTTP stack end toend — mutating
redeem_pairing_codeto skip the origin check, orremoving the
_reject_origin()call ahead of the pairing route inserver.py, makestest_pairing_redeem_route_rejects_disallowed_originfail; mutating the single-use clear-on-success behavior makes
test_pairing_redeem_route_is_single_use_over_httpfail. On the JS side,deleting the
polylogue.pairWithCodehandler or theContent-Typeheader in
redeemPairingCodefailsbackground.test.js's "exchanges a valid pairing code" test (asserts noAuthorizationheader is sent and the body round-trips exactly).What only manual/live browser testing can prove
reachable/styled correctly in a real installed Chrome/Firefox profile
(jsdom-based
popup.test.jsproves the click → message → storage wiring,not visual layout).
polylogueddaemon + realchrome-extension://<id>origin (the test fixtures use a syntheticchrome-extension://polylogue-testorigin, which is the same patternevery other receiver-route test in this repo already uses).
explicitly out of scope for this PR (see Solution above).
Per-bead AC matrix
polylogue-gnie ("Automate secure browser-to-receiver pairing"):
partially satisfied: the one-time-code fallback delivers this; the
design's primary recommendation (native messaging) is not attempted.
the token via pairing — satisfied for the origin axis (tested); the
short-lived/single-use/rate-limited code is the stated defense against a
same-host process without native-messaging-grade isolation.
mismatch, logs no secret — satisfied: the response includes
receiver_id; rejections log only the exception type, never the code ortoken (verified by reading the log call sites).
deferred: this AC clause is explicitly tied to the native-messaging
path in the bead's design text; manual re-pairing remains the recovery
route with this fallback.
authenticated reads, rotation recovery, profile reseed, hostile-origin
rejection, receiver-offline recovery — partially satisfied: first
pairing and hostile-origin rejection are proven over real HTTP; rotation
recovery, profile reseed, and receiver-offline recovery are not (need a
live browser or are explicitly deferred per AC refactor: split CLI into command modules and add HTML preview output #4).
polylogue-3v1 ("Capture extension reliability + status UX"):
(already substantially shipped per the bead's prior-session notes;
independently verified present in the current tree).
(prior sessions' notes claim this is already implemented; not re-verified
here — out of this slice's scope).
gemini.google.comcapture end-to-end — not attempted (full newprovider bridge, out of scope for this slice; named as residual above).
receiver/CLI side (
GET /v1/capture-health,polylogued browser-capture capture-health); not satisfied for theproducer side — the extension does not yet detect and report gaps
automatically (residual, needs a follow-up bead for the visible-vs-
captured comparison + wiring).
polylogue-yyvg.7 ("Make extension UX automatic and exception-driven"):
independently spot-checked against current
mainand found consistent.Still-open items per that record (explicit-approval/destructive-conflict
attention categories blocked on a missing data model; literal
live-installed offline-recovery proof) are unchanged residuals, not
addressed by this PR.
Residuals (named follow-ups, not silently dropped)
comparison →
POST /v1/capture-healthon detected gap/error/spool-backlog/provider-auth-broken) — the receiver/CLI/query side landed here,
the extension-side detection+call did not.
gemini.google.com) capture bridge — not attempted.path — not attempted (this repo cannot install/test it headlessly).
blocked on a ptx-side data model that does not exist yet (per the
bead's own notes, unchanged by this PR).