Skip to content

feat(browser): checkpoint mirror + per-message capture layer - #2871

Merged
Sinity merged 4 commits into
masterfrom
feature/browser-ext/checkpoint-mirror-and-message-layer
Jul 14, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/browser-ext/checkpoint-mirror-and-message-layer

Conversation

@Sinity

@Sinity Sinity commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Two coupled pieces of work from the browser-extension cluster:

  1. polylogue-ys30 (in-page Layer 1): a Shadow-DOM capture-status dot + save action blended into each detected ChatGPT/Claude.ai message.
  2. polylogue-06zm (partial): the local receiver now mirrors the extension's sanitized backfill-ledger checkpoint, giving a second recovery path beyond IndexedDB + the existing chrome.storage.local copy from jlme.4.

Everything else in the assigned cluster (jlme.3, jlme.4, jlme.4.1, s8gb, bj5h, wvji, 4g3n, yyvg) was investigated and is reported below — most turned out to be already delivered by merged PRs earlier in this session (#2819, #2823, #2824, and sinnix #1), which the beads' notes hadn't caught up to yet.

Problem

  • ys30: the yyvg "ambient two-way surface" redesign's foundational per-message layer had no implementation at all — ChatGPT/Claude.ai messages had no visible per-message capture affordance.
  • 06zm: the existing recovery-checkpoint design (PR fix(browser): preserve backfill receiver and recovery contracts #2819) stores its fallback copy in chrome.storage.local — the same browser profile IndexedDB lives in. A profile that is fully destroyed/reinstalled (not merely restarted) loses both copies together, with no recovery path.

Solution

ys30 — browser-extension/src/content/message_layer.js (new): a MutationObserver-driven module that appends an isolated Shadow DOM badge (dot + button) next to each message container, never touching native DOM/classes/listeners (only a non-destructive position:relative fallback when a container has no positioning context). States: captured / pending / failed / unknown / not-seen. Save re-triggers the existing whole-session capture() (there is no per-message receiver endpoint — the archive's capture unit is the session) and every badge reflects the outcome; when the captured turn count and the mounted DOM node count disagree (branching, streaming, redesign) every badge falls back to unknown rather than asserting a status it can't verify. Wired into chatgpt.js/claude.js and all three places the extension injects content scripts (manifest.json, background.js, popup.js).

06zm — new POST/GET /v1/backfill-checkpoint routes on the existing local receiver (polylogue/browser_capture/{models,receiver,route_contracts,server}.py), one JSON file per extension_instance_id, last-write-wins, same write-lock/quota pattern as the capture spool and post-command queue. The receiver treats the checkpoint body as opaque JSON (same trust boundary as the capture-envelope route). Extension side: background.js mirrors every checkpoint persist to the receiver (fire-and-forget, decoupled from the local write so a receiver outage never surfaces as a checkpoint error), and on coordinator construction, if both IndexedDB and the local chrome.storage.local copy are empty, falls back to GET-ing the receiver's mirrored checkpoint and restoring from it.

Acceptance-criteria matrix

Bead Status Evidence
polylogue-jlme.3 (stale receiver contract) already_done Merged PR #2819 (4c3eb375b) implements the full preflight/pause/resume contract described in the bead's AC. Verified the merge is on origin/master and the code (ensureReceiverContract, receiverAckContractError, receiver_contract_incompatible pause) is present in browser-extension/src/backfill/coordinator.js. No new code needed; bead notes were simply stale relative to the merge (written before the PR landed).
polylogue-jlme.4 (ledger preservation across recovery) already_done Same PR #2819: exportRecoveryCheckpoint/restoreRecoveryCheckpoint in storage.js, recoveryRequiredItem/recoveryCheckpointJob state repair, browser_profile_recovery_required control-path guard in coordinator.js.
polylogue-jlme.4.1 (Sinnix restart-vs-reseed) already_done Sinnix commit 2141c848b ("preserve private Chrome profiles on restart", #1), confirmed on origin/master of the sinnix repo — separate-repo scope, out of bounds for this PR, but the work exists and is merged.
polylogue-s8gb (verify 4 paused oversized captures recover) misframed for this delivery model The bead's own description says "this Bead does not itself reload the extension, resume the live job, mutate browser profiles, or alter daemon services" — it's an operational live-verification task requiring an authenticated real browser session, not a code change. Its code prerequisites (PR #2823 "bound oversized backfill conversations", PR #2824 "recover bounded backfill captures safely") are confirmed merged on origin/master. Recommend the operator or a live-desktop session run the actual verification and record the four retry outcomes directly on the bead.
polylogue-06zm (receiver-owned durable ledger) partial AC1 (checkpoint visible via receiver) and AC2/AC3 (a profile loss that also destroys the local chrome.storage.local copy can still recover, demonstrating IndexedDB+local-copy are not the only durable source) are satisfied by this PR. AC4 (idempotent duplicate reconnects) is satisfied by the pre-existing restoreRecoveryCheckpoint empty-IndexedDB guard. AC5 (integration fixture) is satisfied at the Python HTTP-route level (real server, real POST+GET) and the JS level (background.test.js exercises the full mirror/restore flow against a mocked fetch); a true extension-to-daemon E2E fixture is not attempted (no live browser in this environment). Explicitly NOT done: correlating an orphaned checkpoint after a wipe that also destroys the extension's own extension_instance_id (stored in the same chrome.storage.local) — that needs an operator-facing "adopt an orphaned checkpoint" flow, which is real, separate follow-up work, not silently claimed here.
polylogue-ys30 (Layer 1 blended capture dot) satisfied Full implementation + 15 dedicated tests (real-file JSDOM eval, not duplicated logic) covering mounting/dedup, native-content non-destruction, click/keyboard activation, all 5 states incl. the fail-closed mismatch path, MutationObserver churn, invalid-selector fail-closed, teardown, non-destructive positioning. Known, stated limitation: "zero measured layout shift" and live ChatGPT/Claude.ai selector accuracy are asserted structurally in jsdom, not visually verified against a real browser (none available in this environment).
polylogue-bj5h (selection→assertion authoring) deferred Not attempted. Per the operator's explicit guidance for this cluster ("fine to land ys30 solidly... say explicitly which of the four you completed vs deferred"), scope was concentrated on ys30 + 06zm rather than four shallow implementations.
polylogue-wvji (Layer 2 corner chip/slide-over) deferred Not attempted, same reasoning as bj5h. This is explicitly the other layer from ys30 (cross-conversation intelligence vs. per-message state) and was called out as the layer to defer.
polylogue-4g3n ("What Polylogue did here" timeline) already_done (for this lane's scope) Bead notes already record PR #2780 merged, satisfying the local persisted reverse-chron timeline AC. The daemon-queryable mirror is explicitly, correctly deferred in the bead's own notes to the substrate-owned portion ("this browser-extension lane does not modify polylogue/") — confirmed still true, no action needed here.
polylogue-yyvg (epic) not closed Epic tracks 12 children, only 5 of which (yyvg itself + bj5h/wvji/ys30/4g3n) were in this cluster; the others (bkff, r2kb, r4no closed; l40k, yqof, yyvg.1-3 open) are out of scope. Not touched.

Verification

  • npx vitest run tests/content/message_layer.test.js — 15/15 passed.
  • npx vitest run (browser-extension full suite) — 236/236 passed.
  • npm run lint / npm run validate — clean; manifest v0.1.0 valid.
  • devtools test tests/unit/browser_capture/test_backfill_checkpoint.py — 12/12 passed.
  • devtools test tests/unit/browser_capture/ — 101/101 passed (no regression in existing capture/post-command routes).
  • devtools verify --quick — 15/15 steps passed (20260714T002517Z-quick-821673-6e4aee84): ruff format/check, mypy --strict, render all (grepped for "out of sync": none), topology, layering, closure-matrix, schema roundtrip, manifests, ci-workflows, doc-commands, test-infra-currency, test-clock-hygiene, pytest-timeout-overrides, degrade-loudly.

Per repo policy, GitHub Actions CI is disabled (billing-locked) — the above are the full local verification gates.

Follow-ups

  • polylogue-06zm remains open (partial): the orphaned-checkpoint-after-full-wipe correlation/adopt flow is real, separate work.
  • polylogue-s8gb remains open: needs a live operator/desktop session to actually reload the extension and record the four retry outcomes.
  • polylogue-bj5h, polylogue-wvji: untouched, ready for a dedicated pass.

Ref polylogue-ys30, polylogue-06zm, polylogue-jlme.3, polylogue-jlme.4, polylogue-jlme.4.1, polylogue-s8gb, polylogue-bj5h, polylogue-wvji, polylogue-4g3n, polylogue-yyvg.

Co-Authored-By: Claude [email protected]

Sinity and others added 3 commits July 14, 2026 02:10
Problem: polylogue-ys30 (in-page Layer 1 of the yyvg extension redesign)
had no implementation — ChatGPT/Claude.ai messages carried no visible,
per-message capture-status affordance, only a whole-page popup action.

What changed: new src/content/message_layer.js mounts an isolated
Shadow DOM badge (capture-status dot + save button) next to each
detected message container via a MutationObserver, without touching
any native DOM/classes/listeners (only a non-destructive
`position:relative` fallback on unpositioned containers so the badge
can be placed). States are captured/pending/failed/unknown/not-seen,
normalized and colored consistently. Save re-triggers the existing
whole-session capture() (the archive's actual capture unit — there is
no per-message receiver endpoint) and every mounted badge reflects the
outcome; when the captured turn count and the mounted DOM node count
disagree (branching, streaming, host redesign) every badge falls back
to "unknown" rather than asserting a per-message status it cannot
verify. Wired into both chatgpt.js and claude.js (mount + capture()
reportOutcome calls) and into all three places the extension injects
content scripts (manifest.json, background.js injectionPlanForUrl,
popup.js contentScriptFiles).

Verification:
- npx vitest run tests/content/message_layer.test.js -- 15/15 passed
  (evaluates the real production file in a JSDOM window per the
  grok.test.js/chatgpt_bridge.test.js convention, not a duplicated
  copy): badge mounting/dedup, native-content non-destruction, click
  and Enter/Space activation, pending->captured/failed/unknown state
  transitions incl. the turn/node-count-mismatch fail-closed path,
  MutationObserver churn (node added/removed), invalid-selector fail
  closed, stop() teardown, non-destructive positioning.
- npx vitest run -- 232/232 passed (full suite, incl. updated
  background.test.js/popup.test.js injection-file-list assertions).
- npm run lint -- clean.
- npm run validate -- manifest v0.1.0 valid.

Known limitation (documented, not silently claimed): "zero measured
layout shift" and live selector accuracy against the real ChatGPT/
Claude.ai DOM are asserted structurally in jsdom (absolute positioning,
fixed badge size, additive-only DOM diff) but not visually verified —
this environment has no live browser. bj5h (selection->assertion
authoring) and wvji (Layer 2 corner chip/slide-over) are deliberately
deferred, not attempted here; see PR body for the explicit AC matrix.

Ref polylogue-ys30.

Co-Authored-By: Claude <[email protected]>
…iver

Problem: polylogue-06zm asks for a receiver-owned durable copy of the
extension's backfill job ledger so IndexedDB (fast primary) and a local
chrome.storage.local copy (jlme.4's existing profile-restart fallback)
are not the only places a checkpoint can survive — a browser profile
that is fully destroyed/reinstalled, not merely restarted, currently
has no recovery path at all.

What changed: new POST/GET /v1/backfill-checkpoint routes on the
existing local receiver (polylogue/browser_capture/{models,receiver,
route_contracts,server}.py). The receiver treats the checkpoint body
as opaque JSON (same trust boundary the capture-envelope route already
uses: "receiver does not reinterpret payload structure") and persists
one file per extension_instance_id, overwritten on every write
(last-write-wins — the service worker is single-threaded and only ever
checkpoints its own ledger, so there is exactly one legitimate writer
per instance id). Quota-guarded with the same write-lock/TOCTOU-safe
pattern as the capture spool and post-command queue.

Scope note (partial, not full 06zm): this lands the receiver-side
storage/route half only. The extension-side POST-on-checkpoint and a
GET-based restore fallback (for when both IndexedDB and the local
chrome.storage.local copy are gone) are a separate, tightly-coupled
follow-up commit on this branch. AC5's "profile-reseed integration
fixture exercises the real extension-to-loopback route" is covered
Python-side here (real HTTP server, real POST+GET round trip) but not
yet from the actual browser-extension test suite until that follow-up
lands.

Verification:
- devtools test tests/unit/browser_capture/test_backfill_checkpoint.py
  -- 12/12 passed (direct write/read round-trip incl. opaque-payload
  fidelity, last-write-wins overwrite, distinct-instance isolation,
  quota enforcement before a NEW instance is written vs. an existing
  instance's overwrite, plus the full HTTP route: POST 202 store, GET
  200 read, GET 404 missing, GET 400 missing query param, POST 400
  invalid payload, POST 429 quota exceeded).
- devtools test tests/unit/browser_capture/ -- 101/101 passed (no
  regression in the existing capture/post-command route suite).
- devtools verify --quick -- 15/15 steps passed
  (20260714T001753Z-quick-806547-8cd09901): ruff format/check, mypy
  --strict, render all (grepped for "out of sync": none), topology,
  layering, closure-matrix, schema roundtrip, manifests, ci-workflows,
  doc-commands, test-infra-currency, test-clock-hygiene,
  pytest-timeout-overrides, degrade-loudly.

Ref polylogue-06zm.

Co-Authored-By: Claude <[email protected]>
Problem: the previous commit added the receiver-side backfill-checkpoint
mirror storage/routes but nothing in the extension used them yet, so
polylogue-06zm's actual failure mode (a browser profile that is fully
destroyed/reinstalled, wiping IndexedDB AND the local
chrome.storage.local checkpoint copy together) still had no recovery
path.

What changed: background.js now (1) POSTs a best-effort mirror of every
checkpoint the coordinator persists to /v1/backfill-checkpoint,
decoupled from the local chrome.storage.local write so a receiver
outage can never surface as a checkpoint error (BackfillCoordinator.
persistCheckpoint only awaits the checkpoint() callback itself); and
(2) on coordinator construction, if both IndexedDB and the local
checkpoint copy are empty (restoreRecoveryCheckpoint's
"checkpoint_unavailable" reason -- it already refuses to touch a
non-empty IndexedDB), falls back to GET-ing the receiver's mirrored
checkpoint for this extension instance and restoring from that.

Scope note (still partial, not full 06zm): identity correlation is by
extension_instance_id, which itself lives in chrome.storage.local --
a truly catastrophic whole-profile wipe that also destroys that id
cannot self-correlate to its old mirrored checkpoint (there is no
operator-facing "adopt an orphaned checkpoint" flow here). That
remains open follow-up work, not silently claimed as covered.

Verification:
- npx vitest run tests/background.test.js -- 52/52 passed, including
  4 new cases: mirrors every checkpoint persist (asserts the POST body
  carries the real extension_instance_id and version:1 payload, and
  that the local chrome.storage.local write still lands regardless);
  a receiver mirror failure never surfaces on job.recovery_checkpoint_
  error; restores a remote-only checkpoint into a paused
  browser_profile_recovery_required job when local state is empty; and
  does NOT query the receiver when a local checkpoint already restored
  jobs (the local-first invariant). Two pre-existing tests
  ("routes backfill inventory...", "bounds receiver capability
  preflight...") were updated from brittle exact fetch-call-count/index
  assertions to targeted lookups, since the new mirror/restore traffic
  is legitimate additional service-worker fetch activity.
- npx vitest run tests/build.test.js -- 6/6 passed after teaching the
  packaged-service-worker fixture's receiverPosts counter to treat
  /v1/backfill-checkpoint traffic as out-of-band (it was previously
  double-counted as a capture-envelope POST, corrupting an assertion
  about reaching a receiver-contract failure exactly once).
- npx vitest run -- 236/236 passed (full suite).
- npm run lint / npm run validate -- clean; manifest v0.1.0 valid.

Ref polylogue-06zm.

Co-Authored-By: Claude <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 14 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 45f859d8-7d85-4b71-ba01-5fcea2e6ded5

📥 Commits

Reviewing files that changed from the base of the PR and between 031d8d1 and 000b4cc.

📒 Files selected for processing (15)
  • browser-extension/manifest.json
  • browser-extension/src/background.js
  • browser-extension/src/content/chatgpt.js
  • browser-extension/src/content/claude.js
  • browser-extension/src/content/message_layer.js
  • browser-extension/src/popup.js
  • browser-extension/tests/background.test.js
  • browser-extension/tests/build.test.js
  • browser-extension/tests/content/message_layer.test.js
  • browser-extension/tests/popup.test.js
  • polylogue/browser_capture/models.py
  • polylogue/browser_capture/receiver.py
  • polylogue/browser_capture/route_contracts.py
  • polylogue/browser_capture/server.py
  • tests/unit/browser_capture/test_backfill_checkpoint.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/browser-ext/checkpoint-mirror-and-message-layer

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.

Problem: BrowserBackfillCheckpointRequest/Record's checkpoint field
validator called json_document(value), which silently coerced any
non-dict payload (string, null, list, number) to {} instead of
rejecting it. A malformed POST to /v1/backfill-checkpoint therefore
returned HTTP 202 success while overwriting a previously-good stored
checkpoint on disk with an empty one -- exactly the failure mode the
receiver-mirrored backfill ledger (polylogue-06zm) exists to prevent,
since it is meant to be a durable disaster-recovery copy.

What changed: renamed both coerce_checkpoint validators to
require_checkpoint_document and made them raise ValueError for any
non-dict value (surfaced by the server's existing
`except ValidationError` handler as HTTP 400 invalid_backfill_checkpoint,
not a false 202). Fixed the read-path twin on
BrowserBackfillCheckpointRecord too, so a corrupted on-disk checkpoint
file now reads back as "no checkpoint found" instead of a fabricated
empty-but-"valid" one. Added regression coverage in
test_backfill_checkpoint.py: non-dict rejection on both models
(parametrized over string/None/int/list), corrupted-file-on-disk reads
as None, a prior-good checkpoint survives a malformed follow-up write,
and the exact HTTP-level repro (POST checkpoint="garbage-not-a-dict").

Verification:
- devtools test tests/unit/browser_capture/test_backfill_checkpoint.py -> 23 passed
- devtools test tests/unit/browser_capture/ -> 112 passed (no regression)
- devtools verify --quick -> 15/15 steps green

Ref polylogue-06zm.

Co-Authored-By: Claude <[email protected]>
@Sinity

Sinity commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

Fix round (reviewer pass)

Addressed the reviewer's MAJOR finding on this PR (commit 000b4cc):

Silent checkpoint-validation data loss (fixed). BrowserBackfillCheckpointRequest.coerce_checkpoint (and the twin validator on BrowserBackfillCheckpointRecord) used json_document(value), which silently coerced any non-dict checkpoint payload (string/null/list/number) to {} instead of rejecting it. A malformed POST to /v1/backfill-checkpoint returned HTTP 202 success while overwriting a previously-good stored checkpoint on disk with an empty one -- directly undermining the durable-ledger contract polylogue-06zm exists to satisfy. Fixed by renaming both validators to require_checkpoint_document and raising ValueError for any non-dict value, which the server's existing except ValidationError handler now correctly surfaces as HTTP 400 invalid_backfill_checkpoint. Also fixed the read-path twin so a corrupted on-disk checkpoint file reads back as "no checkpoint found" rather than a fabricated empty-but-"valid" one.

Added 7 regression tests to tests/unit/browser_capture/test_backfill_checkpoint.py, including the exact HTTP-level repro from the review (POST checkpoint="garbage-not-a-dict" -> now 400, prior good checkpoint on disk unchanged).

Two minor/non-blocking findings deferred to polylogue-yky4 (quota not re-checked on same-instance overwrite growth; no GC for orphaned per-instance checkpoints after a profile reseed mints a new instance id) -- both need a real design decision, not a mechanical fix.

Verification:

  • devtools test tests/unit/browser_capture/test_backfill_checkpoint.py -> 23 passed
  • devtools test tests/unit/browser_capture/ -> 112 passed (no regression)
  • devtools verify --quick -> 15/15 steps green

@Sinity
Sinity merged commit fc0bedd into master Jul 14, 2026
2 checks passed
@Sinity
Sinity deleted the feature/browser-ext/checkpoint-mirror-and-message-layer branch July 14, 2026 08:06
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