Skip to content

fix(worker): preserve distinct image placements in cheap image de-duplication#881

Closed
BigSimmo wants to merge 4 commits into
mainfrom
codex/improve-ingestion-reliability-in-bigsimmo
Closed

fix(worker): preserve distinct image placements in cheap image de-duplication#881
BigSimmo wants to merge 4 commits into
mainfrom
codex/improve-ingestion-reliability-in-bigsimmo

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Preserve distinct image placements during cheap worker image de-duplication so identical bytes on different pages still reach classification and captioning.
  • Add placement-aware dedupe keys in src/lib/image-filtering.ts and switch worker tracking in worker/main.ts to skip only same-placement duplicates.

Verification

  • npm run test -- --run tests/image-filtering.test.ts tests/worker-visual-capture.test.ts
  • npm run verify:cheap (passed focused worker/image coverage; unrelated PDF extraction budget failures are pre-existing local env issues)
  • Verification not run: full npm run verify:pr-local not re-run in this metadata repair pass; CI Static/Unit/Build gates apply on this PR.

Risk and rollout

  • Risk: low — ingestion dedupe behavior only; no UI, auth, or clinical search contract changes.
  • Rollback: revert this PR squash commit on main.
  • Provider or production effects: None beyond more complete image caption coverage during ingestion.

Notes

  • Supersedes duplicate placement-loss behavior where same-byte table/diagram crops on different pages were skipped before classification.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0dc5ae2a-61a3-483f-a421-26b6710fe9e9

📥 Commits

Reviewing files that changed from the base of the PR and between 3bd634d and 4740462.

📒 Files selected for processing (1)
  • src/lib/image-filtering.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/image-filtering.ts

📝 Walkthrough

Walkthrough

Image filtering now deduplicates images by hash, source kind, page number, and normalized bounding-box placement. Worker and document-enrichment flows record placement keys, with tests covering distinct, invalid, and identical placements.

Changes

Image deduplication

Layer / File(s) Summary
Placement deduplication contract
src/lib/image-filtering.ts
Adds optional pageNumber support, generates normalized placement keys, and uses them for duplicate detection.
Pipeline placement tracking
worker/main.ts, scripts/enrich-documents.ts
Tracks placement keys during captioning and document enrichment, passing normalized image data to duplicate detection.
Placement deduplication coverage
tests/image-filtering.test.ts
Verifies page-specific behavior, invalid bounding-box handling, and rounding-equivalent identical placements.

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

Sequence Diagram(s)

sequenceDiagram
  participant uploadAndCaptionImages
  participant classifyExistingImages
  participant cheapImageSkipReason
  participant imagePlacementDedupeKey
  uploadAndCaptionImages->>cheapImageSkipReason: pass image and seenImagePlacements
  classifyExistingImages->>cheapImageSkipReason: pass filterImage and seenHashes
  cheapImageSkipReason->>imagePlacementDedupeKey: compute placement key
  imagePlacementDedupeKey-->>cheapImageSkipReason: return placement key or null
  uploadAndCaptionImages->>imagePlacementDedupeKey: record processed placement
  classifyExistingImages->>imagePlacementDedupeKey: record processed placement
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly captures the main change: preserving distinct image placements during cheap de-duplication.
Description check ✅ Passed The description is substantive and on-topic, covering motivation, implementation, and testing for the placement-aware dedupe change.
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.
✨ 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 codex/improve-ingestion-reliability-in-bigsimmo

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Jul 18, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@BigSimmo
BigSimmo marked this pull request as ready for review July 18, 2026 15:38
@BigSimmo
BigSimmo enabled auto-merge (squash) July 18, 2026 15:39

@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: 17bbb81f42

ℹ️ 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 src/lib/image-filtering.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/image-filtering.test.ts (1)

33-52: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover bbox and source-kind distinctions too.

This regression only changes pageNumber; it would still pass if bbox or sourceKind were accidentally removed from the dedupe key. Add same-page/different-bbox and same-page/different-source-kind cases to protect the full placement contract.

🤖 Prompt for 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.

In `@tests/image-filtering.test.ts` around lines 33 - 52, Extend the image
deduplication tests around imagePlacementDedupeKey and cheapImageSkipReason with
same-page cases that change only bbox and only sourceKind, asserting these
placements are not skipped. Keep the existing different-page case and verify the
full dedupe key distinguishes pageNumber, bbox, and sourceKind.
src/lib/image-filtering.ts (1)

12-12: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Make the new set contract explicit.

seenHashes now contains placement keys rather than raw image hashes. The worker and supplied tests were migrated, but any other caller can still compile while passing new Set([imageHash]), silently disabling duplicate detection. Rename this field to seenImagePlacements or introduce a distinct key type, and verify every caller was migrated.

Also applies to: 360-360

🤖 Prompt for 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.

In `@src/lib/image-filtering.ts` at line 12, Make the placement-key contract
explicit by renaming the relevant seenHashes field to seenImagePlacements in the
image-filtering API, then update every caller and test to pass placement keys
rather than raw image hashes. Verify no remaining references use the old name or
construct the set from imageHash values.
🤖 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 `@src/lib/image-filtering.ts`:
- Around line 323-326: Update stableBboxKey so missing or malformed bounding
boxes do not all return the shared "bbox:null" key. Preserve coordinate-based
keys for valid normalized bboxes, and return a unique stable discriminator or
otherwise bypass deduplication when reliable placement metadata is unavailable.

---

Nitpick comments:
In `@src/lib/image-filtering.ts`:
- Line 12: Make the placement-key contract explicit by renaming the relevant
seenHashes field to seenImagePlacements in the image-filtering API, then update
every caller and test to pass placement keys rather than raw image hashes.
Verify no remaining references use the old name or construct the set from
imageHash values.

In `@tests/image-filtering.test.ts`:
- Around line 33-52: Extend the image deduplication tests around
imagePlacementDedupeKey and cheapImageSkipReason with same-page cases that
change only bbox and only sourceKind, asserting these placements are not
skipped. Keep the existing different-page case and verify the full dedupe key
distinguishes pageNumber, bbox, and sourceKind.
🪄 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: CHILL

Plan: Pro Plus

Run ID: 47d5f741-ea7b-4924-8eb2-6a4cf67af0c5

📥 Commits

Reviewing files that changed from the base of the PR and between a8cb9fe and 17bbb81.

📒 Files selected for processing (3)
  • src/lib/image-filtering.ts
  • tests/image-filtering.test.ts
  • worker/main.ts

Comment thread src/lib/image-filtering.ts Outdated
Update enrich-documents to use imagePlacementDedupeKey with pageNumber,
and skip cheap placement de-dupe when bbox is missing or malformed so
distinct unknown placements are not collapsed into one shared key.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

CI triage

CI failed on this PR. Automated classification of the 2 failed job(s):

  • Static PR checksneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • PR requiredneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.

Compared with main CI run #3362 (cancelled).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo

Copy link
Copy Markdown
Owner Author

Closing as superseded: identical change already merged in #888 (same title and files: scripts/enrich-documents.ts, src/lib/image-filtering.ts, tests/image-filtering.test.ts, worker/main.ts).

@BigSimmo BigSimmo closed this Jul 18, 2026
auto-merge was automatically disabled July 18, 2026 16:20

Pull request was closed

@BigSimmo
BigSimmo deleted the codex/improve-ingestion-reliability-in-bigsimmo branch July 18, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants