Repository navigation
fix(browser): preserve backfill receiver and recovery contracts - #2819
Conversation
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.
📝 WalkthroughWalkthroughBackfill 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. ChangesBackfill receiver compatibility and recovery
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 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".
There was a problem hiding this comment.
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
📒 Files selected for processing (9)
browser-extension/src/backfill/coordinator.jsbrowser-extension/src/backfill/models.jsbrowser-extension/src/backfill/storage.jsbrowser-extension/src/background.jsbrowser-extension/src/popup.jsbrowser-extension/tests/backfill.test.jsbrowser-extension/tests/background.test.jsbrowser-extension/tests/build.test.jsbrowser-extension/tests/popup.test.js
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]>
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.
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
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
X-Request-IDplus the exact content hash before treating a capture as acknowledged.Acceptance matrix
Verification
npm test— 204 passed.npm test -- --run tests/backfill.test.js— 36 passed.npm run lintandnpm 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).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.