Propose a transaction split from an attached receipt

Draft
BH
17h ago
+1165-31

An attached receipt can fill the transaction split editor with proposed line items. The user reviews amounts, categories, merchants and tags before saving. AI extraction runs on the interactive queue and never creates a split itself.

Review base and merge plan

Draft, targeting refactor/ai-plumbing for review only, as requested by the maintainers. Do not merge this feature into that integration branch. The current AI plumbing was merged into this branch, preserving the existing merge history. The review diff is now 40 files rather than carrying the whole AI stack.

After the AI stack reaches main, change this PR's base back to main and integrate any remaining generation-job window/step-claim changes before marking it ready for final approval. This feature should land separately after the plumbing.

Behavior

  • An interactive extract_receipt route uses Ai::Generations::ExtractReceipt, the shared structured-output generation and PDF/image attachment support, and the requesting user's AI consent.
  • A private ReceiptItemization result queues Ai::GenerationJob, stores pending/completed/failed state and broadcasts a split-dialog reload. A polling fallback handles missed broadcasts. Consent and account access are checked again before execution and before storing the answer.
  • POST /api/v1/transactions/:id/split/itemize returns 202 with a result ID and URL. GET /api/v1/transactions/:id/split/itemization/:receipt_itemization_id returns that user's result for the accessible transaction. The completed proposal can be submitted to the existing split endpoint after review.
  • Transaction::ReceiptItemizer retains the allocation maths: proportional tax/discounts, currency precision capped at the four-place storage scale, rounding residue, unmatched remainder, refunds and tax-inclusive receipts. Currency mismatches are rejected.
  • Existing split row templates and category/merchant/tag controls are preserved. Errors shown to clients are generic; debug entries contain error classes without receipt text.

The change adds the receipt_itemizations table and regenerates API and routing documentation. Category selection remains manual. Two inherited AI workflow Ruby setup pins match main's working version so Ruby 3.4.13 can run their checks.

Validation

  • Final integrated Rails suite: 19,441 tests, 217,087 assertions, 0 failures/errors, 32 skips.
  • Executable API documentation: 497 examples, 0 failures, 89 existing documentation-only pending examples.
  • Full Ruby lint and changed split-template lint pass; Brakeman reports 0 errors and 0 security warnings. Feature/architecture checks passed 352 tests; dedicated consent/requester checks passed 25 tests.
  • CI exposed an inherited chart-touch timing issue. The test now waits for the rendered frame before dispatching input and for scrolling afterward, retaining every assertion. The entire chart gesture class passes: 16 tests, 80 assertions, no failures/errors/skips; changed-test Ruby lint passes.
  • Coverage includes image/text/scanned PDF inputs, revoked consent, per-user result isolation, missing storage, enqueue failure, private errors, allocation precision and split-editor behavior.
  • Recorded-evaluation tasks have no response cassettes in the prerequisite stack and skip their model comparisons; no live model evaluation was performed.

This replaces #4321, which was closed after an earlier accidental force-push.