fix(check-payer-extraction): tolerate trailing JSON prose, extract branch deposit fronts - #467
Open
Clarion1631 wants to merge 1 commit into
Open
fix(check-payer-extraction): tolerate trailing JSON prose, extract branch deposit fronts#467Clarion1631 wants to merge 1 commit into
Clarion1631 wants to merge 1 commit into
Conversation
…i JSON and extract branch deposit fronts
Two prod-observed bugs in scripts/extract-check-payers.mjs:
1. parseModelJson threw on a Gemini response that had trailing text after
the JSON object (SyntaxError: Unexpected non-whitespace character after
JSON at position 132), so bank reference 26236015002403 (a $25,000
cashier's check, Christensen) never got a payerName. Fixed by falling
back to extracting the first balanced top-level {...} object (brace
depth tracked with string-literal awareness) when a straight JSON.parse
fails, and rethrowing the original error when no object is found.
2. DEFAULT_KINDS omitted DEPOSIT_SLIP, but scripts/post-bank-images.mjs
assigns the FRONT image of every branch deposit (no check number) the
kind DEPOSIT_SLIP — that front image IS the substitute-check page
carrying the payer's name. A default extraction run therefore silently
skipped every branch deposit's payer. Fixed by adding DEPOSIT_SLIP to
DEFAULT_KINDS.
Added unit tests for both (tests/extract-check-payers.test.ts): trailing
prose, leading prose, fenced+trailing text, nested braces in string values,
no-object-input still throws, and DEFAULT_KINDS includes DEPOSIT_SLIP.
Mutation-checked: reverting the parseModelJson fallback fails 3 of the new
tests.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018k7m2FBp6gsBvwUZ24s3jC
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No blocking defects found. The production cases are fixed, Non-blocking
VERDICT: APPROVE |
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 free
to 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.
Two bugs found in prod today
Only 1 of 18 filed check/deposit images had ever been extracted with a payerName. Investigating found two independent bugs in
scripts/extract-check-payers.mjs.1.
parseModelJsonthrew on trailing text after the JSON objectGemini's response for bank reference
26236015002403(a $25,000 cashier's check, payer Christensen) had prose after the closing}.JSON.parsethrewSyntaxError: Unexpected non-whitespace character after JSON at position 132, so this image — a $25k check — never got a payerName.Fix: after fence-stripping, if a straight
JSON.parsefails, extract the first balanced top-level{...}object (brace depth tracked with string-literal/escape awareness so a{/}inside a string value can't miscount) and parse that. If no balanced object exists, the original parse error is rethrown — the function stays pure and exported.2.
DEFAULT_KINDSsilently skippedDEPOSIT_SLIPDEFAULT_KINDSwas["CHECK_FRONT", "DEPOSIT_PHOTO"]. Butscripts/post-bank-images.mjs(line ~101) assigns the front image of every branch deposit (one with no check number) the kindDEPOSIT_SLIP, notDEPOSIT_PHOTO— for a branch deposit, that front image IS the substitute-check page that names the payer. A default extraction run therefore silently extracted nothing for every branch deposit: exactly the images that carry the payer.Fix:
DEFAULT_KINDS = ["CHECK_FRONT", "DEPOSIT_SLIP", "DEPOSIT_PHOTO"], with the header comment and inline comment updated to explain the post-bank-images pairing. No other behavior changed — privacy scrubbing (scrubField/scrubExtraction) is untouched.Tests
Added to
tests/extract-check-payers.test.ts(existing file, matched its style):```json) response with trailing textDEFAULT_KINDSincludesDEPOSIT_SLIP(with a comment on the post-bank-images pairing)Mutation check: reverted the
parseModelJsonfallback (back to a bareJSON.parse(text)) and reran — 3 of the new tests failed as expected (trailing prose, fenced+trailing, nested braces), confirming the tests actually exercise the fix. Restored before committing.Verification
npx tsx --test tests/extract-check-payers.test.ts— 38/38 passnpm run test:bank-ledger— 577 pass, 1 pre-existing skip, 0 failnpm run test:unit— 985/985 passnpm run typecheck— clean🤖 Generated with Claude Code
https://claude.ai/code/session_018k7m2FBp6gsBvwUZ24s3jC