Guard untyped bbox jsonb with shared normalizeImageBbox helper - #173
Merged
Conversation
document_images.bbox is untyped jsonb, but bboxLooksLikeHeaderOrFooter array-destructured it after only a truthiness check, so an object-shaped bbox row crashed the whole enrichment run with a TypeError. The enrich script and rag.ts also cast the raw jsonb straight to a tuple type. Add normalizeImageBbox to image-filtering.ts (validates a 4-element array of finite numbers, else null), use it inside bboxLooksLikeHeaderOrFooter, and replace the unsafe casts at both jsonb read sites. Matches the chunkImageBbox semantics from the pr131 branch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
BigSimmo
enabled auto-merge
July 2, 2026 10:54
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:9ca7f8018e
ℹ️ 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".
Uh oh!
There was an error while loading. Please reload this page.
auto-merge was automatically disabled
July 2, 2026 11:28
Merge commits are not allowed on this repository
Uh oh!
There was an error while loading. Please reload this page.
BigSimmo added a commit
that referenced
this pull request
Jul 2, 2026
Drops the branch-local chunkImageBbox in favour of the shared helper that landed on main with the same semantics. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
document_images.bboxis untyped jsonb, butbboxLooksLikeHeaderOrFooter(src/lib/image-filtering.ts) array-destructured it after only a truthiness check — an object-shaped bbox row threw aTypeErrorand crashed the whole enrichment run.normalizeImageBbox(value: unknown)tosrc/lib/image-filtering.ts: returns the[x0, y0, x1, y1]tuple only for a 4-element array whose entries all coerce to finite numbers, elsenull.bboxLooksLikeHeaderOrFooternow normalizes before destructuring, so malformed jsonb means "not a header/footer" instead of a crash.as [number, number, number, number] | nullcasts at both jsonb read sites with the shared helper:scripts/enrich-documents.tsandsrc/lib/rag.ts(attachPageVisualEvidence).cheapImageSkipReasonreturns null instead of throwing, plus directnormalizeImageBboxcoverage (valid tuple, numeric-string coercion, object, wrong-length array, non-numeric entry, NaN, string, null).Note: the helper matches the semantics of the uncommitted
chunkImageBboxfix on theclaude/pr131-review-fixesworktree; if that branch lands later it will hit a trivial one-line conflict at the same rag.ts line, resolved by keeping the shared helper.Verification
npm run verify:cheap— passed (runtime check, lint, typecheck, 823 tests passed / 2 skipped across 99 files)npm run verify:ui— not run: no UI, routing, styling, or browser behavior changednpm run verify:release— not run: not a release/handoff claimnpm run format:check— changed files clean; 2 pre-existing warnings in untouched files (src/components/document-viewer-lazy.tsx,src/lib/supabase/database.types.ts) also present onmainnpm run check:production-readiness— not run: no clinical workflow, privacy, env, Supabase config, source governance, or deployment behavior changed; this is a pure defensive type-safety fix at existing read sitesnpm run check:deployment-readiness— not run: no deployment behavior changedClinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy) — no env or project changesnull(image simply not treated as header/footer or positioned evidence) rather than crashing ingestionNotes
npm run typecheckandnpx vitest run tests/image-filtering.test.ts(15/15).🤖 Generated with Claude Code