Skip to content

Guard untyped bbox jsonb with shared normalizeImageBbox helper - #173

Merged
BigSimmo merged 2 commits into
mainfrom
claude/bbox-jsonb-guard
Jul 2, 2026
Merged

Guard untyped bbox jsonb with shared normalizeImageBbox helper#173
BigSimmo merged 2 commits into
mainfrom
claude/bbox-jsonb-guard

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

  • document_images.bbox is untyped jsonb, but bboxLooksLikeHeaderOrFooter (src/lib/image-filtering.ts) array-destructured it after only a truthiness check — an object-shaped bbox row threw a TypeError and crashed the whole enrichment run.
  • Added exported normalizeImageBbox(value: unknown) to src/lib/image-filtering.ts: returns the [x0, y0, x1, y1] tuple only for a 4-element array whose entries all coerce to finite numbers, else null. bboxLooksLikeHeaderOrFooter now normalizes before destructuring, so malformed jsonb means "not a header/footer" instead of a crash.
  • Replaced the unsafe as [number, number, number, number] | null casts at both jsonb read sites with the shared helper: scripts/enrich-documents.ts and src/lib/rag.ts (attachPageVisualEvidence).
  • Added tests: object-shaped bbox through cheapImageSkipReason returns null instead of throwing, plus direct normalizeImageBbox coverage (valid tuple, numeric-string coercion, object, wrong-length array, non-numeric entry, NaN, string, null).

Note: the helper matches the semantics of the uncommitted chunkImageBbox fix on the claude/pr131-review-fixes worktree; 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 changed
  • npm run verify:release — not run: not a release/handoff claim
  • npm 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 on main
  • npm 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 sites
  • npm run check:deployment-readiness — not run: no deployment behavior changed

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use — no change to answer/source verification logic
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy) — no env or project changes
  • Service-role keys and private document access remain server-only — no access-path changes
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative — malformed bbox now degrades to null (image simply not treated as header/footer or positioned evidence) rather than crashing ingestion
  • Deployment classification/TGA SaMD impact was checked — no clinical decision-support behavior changed

Notes

  • Targeted verification also ran green: npm run typecheck and npx vitest run tests/image-filtering.test.ts (15/15).

🤖 Generated with Claude Code

BigSimmoand others added 2 commits July 2, 2026 18:43
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
BigSimmo enabled auto-merge July 2, 2026 10:54

@chatgpt-codex-connectorchatgpt-codex-connectorBot 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: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".

Comment threadsrc/lib/image-filtering.ts
auto-merge was automatically disabled July 2, 2026 11:28

Merge commits are not allowed on this repository

@BigSimmo
BigSimmo merged commit 93ec48e into mainJul 2, 2026
4 checks passed
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>
@BigSimmo
BigSimmo deleted the claude/bbox-jsonb-guard branch July 2, 2026 12:32
Sign up for freeto 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

@BigSimmo