Skip to content

fix(browser): preserve backfill receiver and recovery contracts - #2819

Merged
Sinity merged 6 commits into
masterfrom
feature/fix/browser-backfill-resilience
Jul 13, 2026
Merged

Sinity merged 6 commits into
masterfrom
feature/fix/browser-backfill-resilience

Conversation

@Sinity

@Sinity Sinity commented Jul 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Makes browser backfill reject incompatible durable acknowledgements, preserve recovery evidence across worker or profile loss, and serialize operator controls safely.

Problem

A receiver could accept a capture without proving the durable acknowledgement contract, while profile replacement could erase the IndexedDB ledger. A slow resume preflight could also race a later operator cancel.

Solution

  • Preflight declared receiver capabilities on start, resume, and every new service-worker lifetime.
  • Require a receiver-returned X-Request-ID plus the exact content hash before treating a capture as acknowledged.
  • Persist a credential-free recovery checkpoint; expose checkpoint-write failure without aborting durable IndexedDB work.
  • Restore profile-loss evidence as an explicit paused recovery state and serialize per-job controls so cancel wins over a delayed resume.
  • Render receiver-contract, profile-recovery, and checkpoint-copy failures distinctly in the popup.

Acceptance matrix

Bead Status Evidence
polylogue-jlme.3 AC1 satisfied Missing durable fields or a receiver-returned request ID pause once while retaining the stored envelope.
polylogue-jlme.3 AC2 satisfied Popup renders receiver-upgrade guidance rather than a receiver-down retry.
polylogue-jlme.3 AC3 satisfied Explicit compatible resume drains the saved envelope without a provider refetch.
polylogue-jlme.3 AC4 satisfied Packaged worker fixture covers preflight, stale ACK pause, resume, and no foreground activation.
polylogue-jlme.4 AC1 satisfied Real fake-IndexedDB restart coverage preserves job, cursor, queue/revisions, ACK, and exactly-once work.
polylogue-jlme.4 AC2 satisfied Credential-free checkpoint restoration is explicit; companion Sinnix PR #1 is merged and preserves extension local settings on ordinary restart/reseed.
polylogue-jlme.4 AC3 satisfied Checkpoint tests exclude provider options, raw envelopes, receipts, cookies, and account identifiers.
polylogue-jlme.4 AC4 satisfied Packaged recovery fixture plus private-profile stale-lock/reseed smoke cover the browser and control-plane paths.

Verification

  • npm test — 204 passed.
  • npm test -- --run tests/backfill.test.js — 36 passed.
  • npm run lint and npm run validate — clean; manifest valid.
  • devtools test tests/unit/browser_capture/test_receiver.py — 34 passed.
  • devtools verify --quick — 15/15 steps passed (20260713T014640Z-quick-2575750-c65b5b95).
  • Sinnix companion: shell syntax, temporary stale-lock smoke, and NixOS toplevel evaluation passed; PR Gemini AI Studio exports need one reproducible archive path #1 merged as 3e9b54e.

GitHub Actions checks dispatched as immediate runner failures with empty step lists and no retrievable failed logs; the affected local gates above are green.

Ref polylogue-jlme.3, polylogue-jlme.4, polylogue-jlme.4.1.

Adversarial review notes

Two independent cold passes found and then verified fixes for checkpoint isolation, receiver preflight/ACK races, restored recovery state, stale Chrome locks, and concurrent resume/cancel ordering. Final pass: clear.

Problem: a stale receiver could accept a capture while omitting the\ndurable acknowledgement hash, which looked like a transient outage and\ncaused reposts. Browser profile replacement could also leave a backfill\nappearing empty.\n\nWhat changed: preflight and recheck the receiver contract per worker\nlifetime; turn missing ACK fields into a distinct paused state while\nkeeping the exact envelope for explicit resume; mirror a credential-free\nrecovery checkpoint and surface profile-loss evidence.\n\nCompatibility: receivers must expose the browser-capture capability\ncontract before a new backfill can run.\n\nRef polylogue-jlme.3, polylogue-jlme.4.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Backfill now preflights receiver acknowledgment capabilities, validates durable receipt fields, pauses incompatible jobs, and persists sanitized recovery checkpoints. IndexedDB and memory stores restore recoverable state, while the background worker and popup handle contract and browser-profile recovery states.

Changes

Backfill receiver compatibility and recovery

Layer / File(s) Summary
Receiver contract validation
browser-extension/src/backfill/models.js, browser-extension/src/backfill/coordinator.js, browser-extension/src/background.js
Defines required durable acknowledgment fields, validates receiver capabilities and receipts, and gates scheduling and execution on receiver compatibility.
Recovery checkpoint persistence
browser-extension/src/backfill/storage.js, browser-extension/src/backfill/coordinator.js, browser-extension/src/background.js
Exports and restores sanitized backfill state, converts affected queue items to recovery-required state, and persists checkpoints through browser storage.
Receiver submission handling
browser-extension/src/backfill/coordinator.js, browser-extension/tests/backfill.test.js
Requeues incompatible acknowledgments, pauses jobs with contract-specific cooldowns, and tests restart, preflight, retry, and recovery behavior.
Operator-facing recovery states
browser-extension/src/popup.js, browser-extension/tests/popup.test.js, browser-extension/tests/background.test.js, browser-extension/tests/build.test.js
Displays actionable contract and browser-profile recovery messages and updates integration mocks for the preflight and resume lifecycle.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BackgroundWorker
  participant BackfillCoordinator
  participant Receiver
  participant BackfillStore
  BackgroundWorker->>Receiver: fetch durable acknowledgment capabilities
  Receiver-->>BackgroundWorker: durable_ack_fields
  BackgroundWorker->>BackfillCoordinator: construct with receiverPreflight
  BackfillCoordinator->>Receiver: submit captured envelope
  Receiver-->>BackfillCoordinator: acknowledgment receipt
  BackfillCoordinator->>BackfillStore: pause and requeue incompatible item
  BackfillCoordinator-->>BackgroundWorker: recovery status
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: preserving backfill receiver and recovery contracts.
Description check ✅ Passed The core template sections are covered with solid detail; Changelog and Risks/Follow-ups are omitted but the description is otherwise complete.
✨ 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/browser-backfill-resilience

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfc20b26cf

ℹ️ 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".

Comment thread browser-extension/src/background.js Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@browser-extension/src/backfill/coordinator.js`:
- Around line 433-435: Update persistCheckpoint() to catch and isolate rejected
checkpoint storage writes so they never propagate into start, control, or worker
backfill operations. Preserve the existing no-checkpoint early return and export
behavior, while recording the checkpoint failure through the coordinator’s
separate retry/observability status mechanism for later handling.
- Around line 423-424: Update the job persistence flow in control() to prevent
stale preflight results from overwriting a concurrently acquired or advanced
job. Use a CAS/versioned update when saving next, preserving the existing
owner-specific saveJob path only when its version or lease still matches;
otherwise re-read or discard the stale update. Alternatively, move preflight
before transitioning the job to running so alarms cannot act on the intermediate
state.

In `@browser-extension/src/backfill/storage.js`:
- Around line 347-365: Update restoreRecoveryCheckpoint so terminal checkpoint
jobs, including cancelled and complete, retain their original status during
restoration; only statuses that require recovery should be changed to paused.
Preserve the existing recovery metadata and cleanup of execution ownership
fields, and keep the createJob-compatible status behavior for running or paused
jobs.
- Around line 26-33: Update checkpoint restoration in recoveryRequiredItem() to
recognize items whose state is "leased" and reset them to the recoverable
waiting state, alongside the existing captured_waiting_receiver handling. Ensure
restored leased items can be reclaimed or re-acquired after checkpoint metadata
is removed by checkpointQueueItem().

In `@browser-extension/src/background.js`:
- Around line 710-716: Bound the request in backfillReceiverPreflight by
applying the same explicit timeout mechanism used for receiver submissions to
its getJson("/v1/browser-captures/capabilities") call. Ensure a non-responsive
receiver causes the existing pause/recovery handling to run instead of leaving
starts, resumes, or worker-epoch checks hanging.
- Around line 79-99: Update the backfillCoordinatorPromise initialization around
the async coordinator setup to clear backfillCoordinatorPromise when checkpoint
restore, IndexedDB, or storage initialization rejects, allowing later backfill
actions to retry. Mirror the existing rejection-reset behavior used by
extensionInstanceIdPromise while preserving successful BackfillCoordinator
creation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bf0a3dcb-3f99-459d-ae57-0e3a950a7f88

📥 Commits

Reviewing files that changed from the base of the PR and between f334a99 and bfc20b2.

📒 Files selected for processing (9)
  • browser-extension/src/backfill/coordinator.js
  • browser-extension/src/backfill/models.js
  • browser-extension/src/backfill/storage.js
  • browser-extension/src/background.js
  • browser-extension/src/popup.js
  • browser-extension/tests/backfill.test.js
  • browser-extension/tests/background.test.js
  • browser-extension/tests/build.test.js
  • browser-extension/tests/popup.test.js

Comment thread browser-extension/src/background.js Resolved
Comment thread browser-extension/src/background.js Resolved
Sinity added 5 commits July 13, 2026 03:30
Problem: the extension required a receiver capability declaration that the\nreceiver did not expose; recovery checkpoints could also resurrect terminal\njobs or strand in-flight leases.\n\nWhat changed: add the authenticated capability route, preserve terminal job\nstatus, normalize stripped leases during restore, and block resume while a\nprofile-loss queue requires operator recovery.\n\nRef polylogue-jlme.3, polylogue-jlme.4.
Problem: a failed backfill coordinator initialization stayed cached for the\nworker lifetime, and its receiver capability preflight was unbounded.\n\nWhat changed: clear rejected coordinator initialization promises and bound the\ncapability declaration request with the existing provider timeout.\n\nRef polylogue-jlme.3.
A reachable older receiver without the capabilities route is incompatible,\nnot transiently unavailable. Preserve that distinction for operator action.\n\nRef polylogue-jlme.3.
Problem: recovery checkpoint failures could abort durable work, a resume\npreflight could race an alarm, and a local request id could be accepted as\na receiver acknowledgement.\n\nWhat changed: make checkpoint writes observable best effort, preflight before\nresuming, require a receiver-returned acknowledgement id, and consistently\nexpose profile-recovery-required queue state.\n\nCo-Authored-By: Claude <[email protected]>
Problem: a delayed resume preflight could overwrite a later cancel.\n\nWhat changed: serialize operator actions per backfill job and cover a concurrent\nresume/cancel sequence so the terminal cancel wins.\n\nCo-Authored-By: Claude <[email protected]>
@Sinity
Sinity merged commit 4c3eb37 into master Jul 13, 2026
4 of 17 checks passed
@Sinity
Sinity deleted the feature/fix/browser-backfill-resilience branch July 13, 2026 01:49
Sinity added a commit that referenced this pull request Jul 14, 2026
Ref polylogue-jlme.3, polylogue-jlme.4, polylogue-jlme.4.1, polylogue-06zm, polylogue-s8gb, polylogue-ys30, polylogue-4g3n, polylogue-yyvg.

Summary: receiver-owned backfill-checkpoint mirror (POST/GET
/v1/backfill-checkpoint) plus extension-side mirror-on-persist + GET-fallback
restore when both IndexedDB and the local chrome.storage.local copy are
empty; new Shadow-DOM per-message capture-status dot + save action
(message_layer.js) wired into all 3 injection paths. jlme.3/jlme.4/jlme.4.1
verified already-satisfied by prior merged PRs (#2819, sinnix #1). bj5h/wvji
deliberately deferred (per-cluster triage: concentrate on the two beads with
a real code gap rather than four shallow implementations).

Verification: 15 dedicated JSDOM tests for message_layer.js covering all 5
ACs; receiver-side checkpoint tests at Python HTTP-route + JS mock level;
devtools verify --quick 15/15.
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 52.F001 / P1: fixed-already at the checked revision: polylogue/browser_capture/server.py:380 handles GET /v1/browser-captures/capabilities and returns BrowserCaptureCapabilitiesPayload with HTTP 200. The backfill preflight endpoint is implemented at the pin.

Only the rows listed above are dispositioned. Held findings remain open.

@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 51.F110 / P2: fixed-already at the checked revision: Checkpoint export converts leased items to their resume state, and recoveryRequiredItem independently performs the same conversion when restoring a checkpoint (browser-extension/src/backfill/storage.js:32,41). prepareRecoveryCheckpoint applies that normalizer to every queue row, preventing a lease stripped of its expiry from remaining permanently leased.
  • 51.F111 / P2: fixed-already at the checked revision: Checkpoint job normalization changes status only for running jobs or paused jobs with recovery-required queue entries (browser-extension/src/backfill/storage.js:55-59). Complete and cancelled jobs retain their original terminal status rather than being resurrected as paused jobs.

Only the rows listed above are dispositioned. Held findings remain open.

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