Skip to content

fix(browser-capture): deduplicate concurrent extension posts - #2785

Merged
Sinity merged 7 commits into
masterfrom
feature/fanout/capture-hardening
Jul 12, 2026
Merged

Sinity merged 7 commits into
masterfrom
feature/fanout/capture-hardening

Conversation

@Sinity

@Sinity Sinity commented Jul 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Harden the browser-capture path for concurrent extension instances and make replaced receiver snapshots materialize through typed membership authority.

Problem

Concurrent extensions could submit the same provider snapshot without durable attribution or semantic duplicate suppression. Backfill jobs added observer-only job, queue, and extension identifiers to provider metadata, making otherwise-identical posts evade that suppression. Separately, a replaced browser-capture JSON snapshot is not a byte-prefix successor, so generic raw-revision authority quarantined it instead of materializing newer acquired attachment bytes.

Solution

  • Stamp direct and retry capture envelopes with one persistent MV3 service-worker instance id, coalescing concurrent cold-start reads and mints.
  • Deduplicate observer-equivalent snapshots while retaining request-byte acknowledgement hashes, excluding backfill observer attribution from the semantic fingerprint only.
  • Serialize spool replacement with an advisory OS lock and atomic writes.
  • Route single-session artifacts from the browser-capture watch source through existing membership revision authority from their first observation. Strict message/event/attachment growth governs content changes; metadata-equivalent snapshots retain the existing timestamp-aware membership rule; every raw blob remains retained.

Acceptance matrix

Bead Status Evidence
polylogue-3v1.1 Satisfied Two concurrent cold-start extension capture messages share one persisted instance id. Receiver writes converge to one artifact and the production live-batch route materializes exactly one archived session; distinct backfill jobs also yield one deduplicated receipt.
polylogue-57rp Partial: typed-authority regression satisfied; exact/live criteria deferred The real-route fixture retains raw snapshots, advances the accepted membership head to the acquired replacement, stores its inline attachment as an acquired content-addressed blob, and retains the head for both reverse and divergent stale replacements. It uses synthetic attachment bytes, so the bead's exact 848,460-byte/SHA proof, daemon replay-debt accounting, and live re-capture query remain deferred under the archive-safety boundary.
polylogue-5k5l.1 Already merged PR #2712 (8c23ba218) supplied authenticated interpreter/sandbox acquisition and typed outcomes.
polylogue-5k5l Partial: existing acquisition implementation retained; parent ACs not newly closed Existing adapter tests cover sandbox and file-service acquisition; parser/archive tests prove acquired envelope assets reach attachment blobs. The controlled file-service live acquisition and idempotent live re-capture evidence remain with the parent bead.

Verification

  • nix develop --command devtools test tests/unit/daemon -k 'receiver or capture' — 38 passed.
  • POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/daemon/test_browser_capture_instance_attribution.py — 1 passed.
  • POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/sources/test_live_batch_support.py -k browser_capture_replacement_advances_membership_head_and_acquires_attachment — 1 passed.
  • npm test -- --run tests/background.test.js — 23 passed.
  • npm test -- --run tests/content/chatgpt.test.js tests/content/chatgpt_bridge.test.js — 34 passed.
  • nix develop --command devtools test tests/unit/sources/test_browser_capture.py -k 'embedded_attachments_are_acquired_in_archive or native_payload_delegation_keeps_envelope_acquired_assets' — 2 passed.
  • Pre-push devtools verify --quick — all 15 gates passed (20260712T225848Z-quick-1752486-5ad29130).

Adversarial review notes

  • Iteration 1: fixed a real cold-start instance-id race in 436e9c012; added a divergent stale-snapshot route proof and corrected the membership wording. A further direct review finding that the spool test did not prove archive materialization landed in 6deab55d7. The exact/live 57rp and parent 5k5l criteria remain explicitly deferred above.

Anti-vacuity: the 57rp fixture calls LiveBatchProcessor.ingest_files against the production archive writer, then reads source/index database state. Removing the browser-capture membership route restores the old quarantined byte-revision behavior; removing ambiguity handling lets a divergent stale snapshot overwrite the accepted head. The concurrent-writer test invokes write_capture_envelope with a synchronization barrier and distinct backfill job/queue/instance metadata, then runs the real live-batch processor; removing semantic deduplication, its attribution normalization, or the archival route breaks its receipt/artifact/session assertions. The background test drives two real runtime messages concurrently; removing the single-flight promise permits distinct cold-start identifiers and fails its one-id assertion.

Ref polylogue-3v1.1
Ref polylogue-57rp
Ref polylogue-5k5l

Sinity added 2 commits July 12, 2026 22:50
Problem: concurrent extension instances can submit an identical provider\nsnapshot to the same loopback spool without durable attribution or\nsemantic duplicate suppression.\n\nWhat changed: stamp capture posts with the service worker's persistent\ninstance id; ignore observer-only provenance in the dedup fingerprint;\nserialize spool writes with an OS file lock; and return attribution/dedup\nreceipts to the extension.\n\nCompatibility: existing capture envelopes remain valid; new response fields\nare additive.\n\nRef polylogue-3v1.1\n\nCo-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 12, 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: 3 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: fe0ec350-a7cc-4e14-9dd4-a4a26fe73077

📥 Commits

Reviewing files that changed from the base of the PR and between 901825e and 694f8bd.

📒 Files selected for processing (10)
  • browser-extension/src/background.js
  • browser-extension/tests/background.test.js
  • polylogue/browser_capture/models.py
  • polylogue/browser_capture/receiver.py
  • polylogue/browser_capture/server.py
  • polylogue/sources/live/batch.py
  • tests/unit/browser_capture/test_receiver.py
  • tests/unit/browser_capture/test_receiver_token.py
  • tests/unit/daemon/test_browser_capture_instance_attribution.py
  • tests/unit/sources/test_live_batch_support.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fanout/capture-hardening

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: dfff3e8092

ℹ️ 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 polylogue/browser_capture/receiver.py Resolved
Sinity and others added 4 commits July 12, 2026 23:23
Problem: mutable browser-capture snapshot JSON is not a byte-prefix\nstream, so its first raw entered quarantined byte-revision governance and\na later acquired replacement could never materialize.\n\nWhat changed: route single-session artifacts from the browser-capture\nwatch source into existing membership revision authority from their first\nobservation. The authority accepts only strict parsed-content growth while\nretaining every prior raw blob and its membership receipt.\n\nRef polylogue-57rp\nRef polylogue-5k5l\n\nCo-Authored-By: Claude <[email protected]>
Problem: concurrent backfill jobs carry observer-only identifiers in both
top-level and session provider metadata. Including those values in the spool
deduplication hash made identical provider snapshots overwrite the same
artifact instead of taking the duplicate path.

What changed: remove the job, queue, and extension-instance attribution
fields from provider metadata only for the semantic deduplication fingerprint.
Preserve any other backfill metadata and raw payload content.

Ref polylogue-3v1.1

Co-Authored-By: Claude <[email protected]>
Problem: simultaneous capture messages during a cold MV3 service-worker\nstart could independently mint and post different instance identifiers.\n\nWhat changed: share the in-flight storage read/mint operation, retrying only\nafter that operation fails. Extend the browser-capture membership route proof\nwith a divergent stale replacement and remove a timestamp-tie-sensitive\nassertion.\n\nRef polylogue-3v1.1\nRef polylogue-57rp\n\nCo-Authored-By: Claude <[email protected]>
Exercise concurrent receiver delivery through the real live-batch processor and
assert it materializes exactly one archived provider session.

Ref polylogue-3v1.1

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

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review — iteration 1

Findings and fixes:

  • Real: a cold MV3 service worker could mint two attribution ids for concurrent capture messages. 436e9c012 memoizes the in-flight storage read/mint; the runtime-message regression uses Promise.all and proves both POSTs share the persisted id.
  • Borderline, fixed: the browser-capture replacement fixture proved literal reverse arrival but not a divergent stale branch. It now sends a non-prefix divergent replacement through LiveBatchProcessor, requires the current head to remain accepted, and requires the new membership decision to be ambiguous.
  • Borderline, fixed: the PR previously described every accepted advancement as strict content growth. The body now distinguishes strict message/event/attachment growth from the pre-existing timestamp-aware metadata-equivalence rule.
  • Additional closure proof: 6deab55d7 carries the concurrent receiver artifact through the production live-batch route and asserts one archived session, rather than inferring ingestion from one spool file.

What survived scrutiny:

  • Backfill observer attribution is excluded only from the dedup fingerprint; raw payloads and non-observer provider metadata remain retained.
  • Exact live 57rp replay/debt/blob proof and the parent 5k5l live file-service/idempotent re-capture criteria remain deferred to their open Beads, not claimed here.

Verification: focused background test 23 passed; focused concurrent receiver-to-archive test 1 passed; focused browser-capture replacement test 1 passed; lint/type checks passed; pre-push devtools verify --quick passed all 15 gates (20260712T225848Z-quick-1752486-5ad29130).

Problem: the receiver accepted capture posts without an extension instance id,
leaving a concurrent capture unauditable. Its cross-process flock contract was
also unproven.

What changed: reject unattributed POSTs while retaining offline artifact
parse compatibility, and add independent-process spool coverage.

Ref polylogue-3v1.1

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

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review — iteration 2

Findings and fixes:

  • Real: the earlier concurrency test was thread-only, so it could not prove the fcntl.flock protection across receiver processes. 694f8bdac adds two spawned Python writers released at a shared barrier; it requires exactly one parseable artifact, one deduplicated result, and no orphan temporary file.
  • Real: the HTTP receiver accepted a valid capture with no extension_instance_id. The receiver now returns 400 missing_extension_instance_id before writing. The envelope model remains permissive only for parsing historical on-disk artifacts; current POST ingress is strict. Existing receiver/token fixtures now supply an instance id, and the negative HTTP regression proves omission is rejected.

What survived scrutiny:

  • Direct/retry extension capture paths single-flight the first persisted id; current POST receipts always carry it.
  • The full receiver-to-live-batch test still proves one artifact becomes one archived session.
  • Exact live 57rp replay/debt/blob evidence and parent 5k5l live file-service/idempotent recapture remain deferred to their open Beads.

Verification: 2-process daemon regression 2 passed; receiver contract 33 passed; token contract 7 passed; lint/type checks passed; pre-push devtools verify --quick passed all 15 gates (20260712T230854Z-quick-1962095-94df975c).

@Sinity

Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner Author

Final acceptance matrix after adversarial fixpoint (iteration 3: no legitimate gaps found)

Bead / AC Status Evidence or disposition
polylogue-3v1.1 — concurrent same-session delivery yields one archived session Satisfied Concurrent writer regression requires one deduplicated receipt and one spool artifact; the same artifact is ingested through LiveBatchProcessor and yields exactly one indexed session.
polylogue-3v1.1 — every current capture POST has an attributable instance id Satisfied MV3 direct/retry paths single-flight their persisted id; receiver rejects a missing id with 400 missing_extension_instance_id. Historical artifacts remain parse-compatible but cannot enter through current POST ingress without attribution.
polylogue-3v1.1 — concurrent spool writes do not corrupt/interleave Satisfied Thread and two-spawned-process regressions exercise atomic replacement and fcntl.flock, requiring a single parseable artifact and no temporary residue.
polylogue-57rp AC1 — replacement enters typed membership authority Satisfied Real LiveBatchProcessor browser-capture fixture retains raw evidence and advances the accepted membership head.
polylogue-57rp AC2 — exact 848,460-byte/SHA acquisition Deferred to polylogue-57rp Current fixture proves generic acquired attachment materialization only; the prescribed exact artifact evidence is archive/live scoped.
polylogue-57rp AC3 — reverse and divergent stale replacement cannot regress head Satisfied Fixture covers literal reverse and non-prefix divergent branches, retaining the prior head and recording ambiguity.
polylogue-57rp AC4 — replay-debt termination/counts Deferred to polylogue-57rp Not implemented or claimed by this PR.
polylogue-57rp AC5 — preserved live receiver artifact converges with source/index/blob evidence Deferred to polylogue-57rp Not run under the archive-safety boundary.
polylogue-5k5l AC1–AC5 Deferred to polylogue-5k5l This PR retains and exercises the existing parser/CAS path but does not claim the parent bead's controlled live sandbox/file-service acquisition, idempotent re-capture, or size-cap closure. The authenticated interpreter child is already merged as PR #2712 (8c23ba218).

No Bead state was changed and this PR is not merged.

@Sinity
Sinity merged commit 041b8a2 into master Jul 12, 2026
4 of 16 checks passed
@Sinity
Sinity deleted the feature/fanout/capture-hardening branch July 12, 2026 23:46
Sinity added a commit that referenced this pull request Jul 13, 2026
…800,2781

2ilz (origin-interop, PR #2794), 3v1.1 (capture-hardening, PR #2785), and
qqyg (hooks-capture, PR #2781) fully satisfied — closed. 9e5.16 (api-parity,
PR #2782), 57rp/5k5l (capture-hardening, PR #2785), and 7fj (beads-ingest,
PR #2800) partially satisfied — noted with disposition, left open.

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

Sinity commented Oct 1, 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.

  • 59.F117 / P2: fixed-already at the checked revision: polylogue/browser_capture/capture_stream.py:570-571 skips job_id, queue_id and instance_id from semantic backfill metadata. Both session and envelope metadata use semantic=True at lines 632 and 662, so observer-only differences no longer alter the capture dedup hash.

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