Repository navigation
feat(browser): checkpoint mirror + per-message capture layer - #2871
Conversation
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]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 14 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 |
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]>
Fix round (reviewer pass)Addressed the reviewer's MAJOR finding on this PR (commit 000b4cc): Silent checkpoint-validation data loss (fixed). Added 7 regression tests to 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:
|
Summary
Two coupled pieces of work from the browser-extension cluster:
chrome.storage.localcopy 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
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): aMutationObserver-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-destructiveposition:relativefallback when a container has no positioning context). States:captured/pending/failed/unknown/not-seen. Save re-triggers the existing whole-sessioncapture()(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 tounknownrather than asserting a status it can't verify. Wired intochatgpt.js/claude.jsand all three places the extension injects content scripts (manifest.json,background.js,popup.js).06zm — new
POST/GET /v1/backfill-checkpointroutes on the existing local receiver (polylogue/browser_capture/{models,receiver,route_contracts,server}.py), one JSON file perextension_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.jsmirrors 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 localchrome.storage.localcopy are empty, falls back to GET-ing the receiver's mirrored checkpoint and restoring from it.Acceptance-criteria matrix
4c3eb375b) implements the full preflight/pause/resume contract described in the bead's AC. Verified the merge is onorigin/masterand the code (ensureReceiverContract,receiverAckContractError,receiver_contract_incompatiblepause) is present inbrowser-extension/src/backfill/coordinator.js. No new code needed; bead notes were simply stale relative to the merge (written before the PR landed).exportRecoveryCheckpoint/restoreRecoveryCheckpointinstorage.js,recoveryRequiredItem/recoveryCheckpointJobstate repair,browser_profile_recovery_requiredcontrol-path guard incoordinator.js.2141c848b("preserve private Chrome profiles on restart",#1), confirmed onorigin/masterof the sinnix repo — separate-repo scope, out of bounds for this PR, but the work exists and is merged.origin/master. Recommend the operator or a live-desktop session run the actual verification and record the four retry outcomes directly on the bead.chrome.storage.localcopy 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-existingrestoreRecoveryCheckpointempty-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 ownextension_instance_id(stored in the samechrome.storage.local) — that needs an operator-facing "adopt an orphaned checkpoint" flow, which is real, separate follow-up work, not silently claimed here.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
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]