Skip to content

Retain table-crops for document view, surface table-quality warnings, add aspect-ratio support and formatting-audit script#1129

Closed
BigSimmo wants to merge 23 commits into
mainfrom
codex/identify-formatting-issues-in-tables-and-images
Closed

Retain table-crops for document view, surface table-quality warnings, add aspect-ratio support and formatting-audit script#1129
BigSimmo wants to merge 23 commits into
mainfrom
codex/identify-formatting-issues-in-tables-and-images

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Retain uncaptioned table/diagram/page-region crops for document viewing with extraction-quality warnings, intrinsic aspect-ratio rendering, and an offline formatting-fixture audit.
  • Keeps view-only retained crops non-searchable so they do not feed retrieval/indexing.

RAG impact: no retrieval behaviour change — ingestion retention and document-viewer presentation only; no ranking/retrieval comparator, selection, or search-order edits.

Verification

  • npm run format:check (after Prettier fix on scripts/enrich-documents.ts)
  • Focused Vitest for formatting audit + signed-image + accessible-table + retention/filtering DOM/unit tests
  • Python extractor unit test for crop completeness scoring
  • UI verification not run: Production UI already green on prior head; this CI fix is Prettier + PR policy body only beyond prior UI-validated tip

Risk and rollout

  • Risk: medium — worker retention/searchable flags and document-viewer quality signals affect clinical source presentation; retrieval inputs must stay non-searchable for view-only crops.
  • Rollback: revert the PR commit(s); no schema/migration changes.
  • Provider or production effects: None (offline/local verification only; no live reindex or provider calls in this fix)

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

  • CI failure root cause addressed: Prettier on scripts/enrich-documents.ts and missing Clinical Governance Preflight section in the PR body.
  • Remove this PR_POLICY_BODY.md after merge so Sync PR policy body does not leave a stale template on main.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@cursor[bot], you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 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: CHILL

Plan: Pro Plus

Run ID: 65a6bc3c-e61d-48f9-bf99-b8af3460ef38

📥 Commits

Reviewing files that changed from the base of the PR and between 3ddf97b and b572217.

📒 Files selected for processing (14)
  • PR_POLICY_BODY.md
  • package.json
  • scripts/audit-formatting-fixtures.ts
  • scripts/enrich-documents.ts
  • src/components/clinical-dashboard/signed-image.tsx
  • src/lib/document-detail.ts
  • src/lib/image-filtering.ts
  • tests/document-detail-performance.test.ts
  • tests/enrich-documents-retention.test.ts
  • tests/formatting-fixture-audit.test.ts
  • tests/image-filtering.test.ts
  • tests/signed-image.dom.test.tsx
  • worker/python/extract_pdf_assets.py
  • worker/python/test_extract_pdf_assets_budget.py
📝 Walkthrough

Walkthrough

The change adds crop-quality metadata, preserves selected uncaptured images for document viewing, exposes quality fields through document-detail contracts, and updates the viewer with warnings, aspect-ratio rendering, and low-confidence table fallbacks. A formatting-fixture audit command and related tests are also added.

Changes

Formatting quality handling

Layer / File(s) Summary
Crop quality metadata
worker/python/extract_pdf_assets.py, worker/python/test_extract_pdf_assets_budget.py
Crop completeness and page-edge clipping metadata are recorded, table crops receive larger expansion padding, and the completeness scoring is tested.
Document-view image retention
worker/main.ts
Selected uncaptured image kinds receive fallback classifications and are persisted with document-view retention state without reopening indexing.
Image metadata contracts and mapping
src/components/document-viewer/types.ts, src/lib/document-detail-contract.ts, src/lib/document-detail.ts, tests/document-detail-performance.test.ts
Image/table dimensions, crop quality, OCR density, extraction confidence, truncation, and retention metadata are typed, mapped, and projected by the document-detail loader.
Viewer quality warnings and fallbacks
src/components/clinical-dashboard/signed-image.tsx, src/components/document-viewer/source-panels.tsx, tests/accessible-table.dom.test.tsx, tests/signed-image.dom.test.tsx
The viewer derives quality warnings, selects source images for low-quality tables, supports low-confidence table fallbacks, and renders supplied image aspect ratios.
Formatting fixture audit
scripts/audit-formatting-fixtures.ts, package.json, tests/formatting-fixture-audit.test.ts
A CLI script audits extractor JSON formatting risks, reports warnings and failures, exits non-zero for failures, and is covered by a subprocess test.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PDFExtractor
  participant CaptionWorker
  participant DocumentDetailLoader
  participant DocumentImage
  PDFExtractor->>CaptionWorker: crop metadata and image classification
  CaptionWorker->>DocumentDetailLoader: retained image and quality fields
  DocumentDetailLoader->>DocumentImage: mapped image metadata
  DocumentImage->>DocumentImage: calculate warnings and display order
  DocumentImage->>DocumentImage: render source image or accessible table fallback
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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 clearly summarizes the main changes: retained crops, quality warnings, aspect-ratio support, and the audit script.
Description check ✅ Passed The description covers the required sections and includes summary, verification, risk/rollback, and clinical governance content.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/identify-formatting-issues-in-tables-and-images

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.

@supabase

supabase Bot commented Jul 24, 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 24, 2026 04:18
@BigSimmo
BigSimmo enabled auto-merge (squash) July 24, 2026 04:19

@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: 49fdf1da59

ℹ️ 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 worker/main.ts Outdated
@BigSimmo

Copy link
Copy Markdown
Owner Author

@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation.

@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: 49fdf1da59

ℹ️ 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 worker/main.ts Outdated
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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 #4650 (success).

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

cursoragent and others added 2 commits July 24, 2026 04:41
…ting-issues-in-tables-and-images

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Persist retainForDocumentView / audit table crops on document_images for
the viewer, but only push searchable rows into insertedImages so they do
not feed buildChunks, table-fact extraction, or embedding-field writes.

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

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/document-viewer/source-panels.tsx (1)

287-295: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not provide the fallback for every table.

AccessibleTable treats any lowConfidenceFallback as the replacement branch (as its new DOM test confirms), but this always passes imageBlock. Consequently, even high-confidence structured tables render no table; on the table-first path, the fallback image is also duplicated inside “Show original table image.”

Gate this prop on an explicit low-confidence condition and ensure exactly one layer owns the source-image fallback.

🤖 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/components/document-viewer/source-panels.tsx` around lines 287 - 295,
Update the AccessibleTable usage in the source-panels component so
lowConfidenceFallback is provided only when the image/table has an explicit
low-confidence status. Preserve structured table rendering for high-confidence
tables, and ensure the source-image fallback is owned by exactly one rendering
layer without duplication on the table-first path.
🤖 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 `@scripts/audit-formatting-fixtures.ts`:
- Around line 39-41: Update the table_crop validation around sourceKind and
meta.table_rows so supported image-only fallback records emit a warning rather
than a failing audit result; only fail when metadata indicates structured rows
were expected, using the existing expectation metadata or an explicit
extraction-status field. Add a passing fixture covering the intentional
image-only table_crop case.

In `@src/components/clinical-dashboard/signed-image.tsx`:
- Around line 128-136: The signed-image error branch around the failed request
return (Lines 97-104) still applies the fixed aspect-[4/3] fallback instead of
the validated aspectRatio. Reuse the same validated/clamped aspect-ratio style
and fallback-class condition used by the main frame, and update the DOM test to
verify the supplied ratio remains applied when the signed-image request fails.

In `@worker/main.ts`:
- Around line 1115-1123: Update the re-enrichment flow used by
scripts/enrich-documents.ts to persist and consume a canonical top-level
skip/retention state, preserving retained_for_document_view for diagram_crop and
page_region as well as audit tables. Ensure retained view-only images remain
non-searchable and excluded from insertedImages/enrichment indexing, and add a
regression test covering this behavior.

---

Outside diff comments:
In `@src/components/document-viewer/source-panels.tsx`:
- Around line 287-295: Update the AccessibleTable usage in the source-panels
component so lowConfidenceFallback is provided only when the image/table has an
explicit low-confidence status. Preserve structured table rendering for
high-confidence tables, and ensure the source-image fallback is owned by exactly
one rendering layer without duplication on the table-first path.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b30f7095-744f-4d03-ab0c-0f1004784b48

📥 Commits

Reviewing files that changed from the base of the PR and between 6ceaaff and 3ddf97b.

📒 Files selected for processing (14)
  • package.json
  • scripts/audit-formatting-fixtures.ts
  • src/components/clinical-dashboard/signed-image.tsx
  • src/components/document-viewer/source-panels.tsx
  • src/components/document-viewer/types.ts
  • src/lib/document-detail-contract.ts
  • src/lib/document-detail.ts
  • tests/accessible-table.dom.test.tsx
  • tests/document-detail-performance.test.ts
  • tests/formatting-fixture-audit.test.ts
  • tests/signed-image.dom.test.tsx
  • worker/main.ts
  • worker/python/extract_pdf_assets.py
  • worker/python/test_extract_pdf_assets_budget.py

Comment thread scripts/audit-formatting-fixtures.ts Outdated
Comment thread src/components/clinical-dashboard/signed-image.tsx
Comment thread worker/main.ts
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 5 file(s) based on 3 unresolved review comments.

Files modified:

  • scripts/audit-formatting-fixtures.ts
  • scripts/enrich-documents.ts
  • src/components/clinical-dashboard/signed-image.tsx
  • tests/formatting-fixture-audit.test.ts
  • tests/signed-image.dom.test.tsx

Commit: 12634d3e539d5c2ca09973100b5bfba627e5a989

The changes have been pushed to the codex/identify-formatting-issues-in-tables-and-images branch.

Time taken: 4m 46s

coderabbitai Bot and others added 2 commits July 24, 2026 05:08
Fixed 5 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>

@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: 59e9b7d340

ℹ️ 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 worker/python/extract_pdf_assets.py
Comment thread worker/main.ts
Comment thread scripts/enrich-documents.ts Outdated
@BigSimmo

Copy link
Copy Markdown
Owner Author

@cursoragent please fix failing CI testing

@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

CI on #1129 is green (PR required, Static, Unit, Build, Production UI, PR policy).

What was failing:

  • Prettier on scripts/enrich-documents.ts
  • PR policy missing Clinical Governance Preflight
  • Lint unused user in tests/signed-image.dom.test.tsx (--max-warnings 0)

What I fixed:

  • Formatted the retention condition in enrich-documents.ts
  • Added PR_POLICY_BODY.md so Sync PR policy body could apply the governance checklist (direct body edits weren’t available to this token)
  • Removed the unused userEvent.setup() in the SignedImage DOM test

Local checks: focused Vitest (formatting audit + signed-image) and ESLint on the touched files passed. Head is 10f6852e. Reminder: remove PR_POLICY_BODY.md after merge so it doesn’t linger on main.

Open in Web Open in Cursor 

cursoragent and others added 6 commits July 24, 2026 05:46
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
…-in-tables-and-images' into HEAD

Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Unblocks Static PR checks format:check on the retained-for-view re-enrichment gate.
…-in-tables-and-images' into codex/identify-formatting-issues-in-tables-and-images
Unblocks the PR policy gate for this clinical-risk PR; remove the template after merge.
The prior policy run evaluated the pre-sync description; body now includes checked Clinical Governance Preflight.

@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: 9a1b1f989f

ℹ️ 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 scripts/audit-formatting-fixtures.ts Outdated
Clears the @typescript-eslint/no-unused-vars warning that failed Static PR checks under --max-warnings 0.
cursoragent and others added 4 commits July 24, 2026 06:00
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo
BigSimmo disabled auto-merge July 24, 2026 06:50
cursoragent and others added 4 commits July 24, 2026 06:52
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo

Copy link
Copy Markdown
Owner Author

Closed as safely deferred, not discarded. The 19-file patch expands crop/image retention, geometry, storage and time behavior without a real current-main malformed-asset fixture. The required next step is now durably recorded as #76 in docs/outstanding-issues.md via #1165: reproduce one authorised fixture, identify the exact extraction stage, add a red regression, and only then make the smallest budget-preserving fix. Broad thresholds/padding/storage expansion and PR_POLICY_BODY.md are not recommended for incorporation. The branch remains recoverable in the verified/final reconciliation bundles.

@BigSimmo BigSimmo closed this Jul 24, 2026
cursor Bot pushed a commit that referenced this pull request Jul 24, 2026
* test(pdf): red repro for page-edge table crop truncation (#76)

Add a minimal authorised synthetic fixture and deliberately-red Python/Vitest
contracts that name the failing pymupdf_find_tables stage and expected clip
geometry before any retention/padding change from PR #1129.

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

* fix(pdf): retain on-page remnant for page-edge table crops (#76)

Extend find_tables candidates using contiguous cell drawings so straddling
final rows are cropped to the page edge, recover structured remnant text when
possible, and emit an incompleteness warning when content continues past the
page. Flip the #76 red contracts green and archive the ledger item.

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

* docs: record PR #1176 page-edge crop review in branch ledger

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

* docs: supersede #1176 review ledger row for merged tip

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

* fix(ci): format PDF crop follow-up

* docs: record PR 1176 maintenance

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
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