Fill a bill's blank category from its transactions #4374
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #4374"
general
weight: 0.35
jaysbeekay
Closes #4363
Fork pre-flight: jaysbeekay/sure#523, from the same branch and commit. Its CI runs and reviews, and the fork issue with the triage plan (jaysbeekay/sure#501), are there.
Problem
A bill's category was copied from its transactions only once, when detection first created the series. Transactions categorised later never reached it, so the bill kept "No category". The two manual routes from a transaction to a bill never set the category at all:
RecurringTransaction.create_from_transaction) built the bill without acategory_id.DeclaredBill#builddidn't assign it.Change
The rule is fill, never overwrite. A category already on the bill is left alone, and income series stay uncategorised, as they are at creation. When the transactions carry mixed categories, the most common one wins, which is the existing
Classifier#modal_category_idrule.Identifier#update_claimed_seriesfills a blank category from the cluster's most common one. The race-recovery branch calls the same method, so it is covered too. Classification runs only when the series can actually be filled.Identifier#update_manual_recurring_transactionsdoes the same from its matched entries. The batched entry query now selectstransactions.category_idbesidemerchant_id, so no per-series query is added.create_from_transactiontakes the transaction's category for an expense.- The prefill sets the category for an outflow.
- The New dialog shows the existing
DS::CategorySelectfor a bill. Income doesn't get it.-
:category_idis permitted.-
DeclaredBill#buildassigns it unless the bill is income.- Ownership is checked by the existing
category_belongs_to_familyvalidation, so another family's category gives a 422.- Smart fill shares the prefill, so its dialog keeps the transaction's category too. Its suggested category is still dropped, as before.
config/brakeman.ignore: the existing entry fornew_recurring_transaction_paramsgets its new fingerprint, plus a note on howcategory_idis checked.Deliberately unchanged:
Assistant::Function::CreateBill, which sets the category itself afterbuild.create_from_transfer, because a transfer is not spending.Known limit: a blank category can't tell "never set" from "deliberately cleared". A bill the user cleared is refilled on the next detection run if its transactions carry a category.
Screenshots
Captured by a system test against the test fixtures: before on
mainat7917bc1e4, after on this branch. Create bill opened from a transaction categorised Food & Drink.| Before | After |
|---|---|
| !Before: no category on the form | !After: the category is preselected as Food & Drink |
Tests
New tests, each run against unmodified
mainfirst. Nine failed there for the expected reason, either a missing category or a missing field. The other seven are negative controls that pass both before and after the change:- A blank series takes its entries' category.
- A set category is kept.
- Mixed categories resolve to the most common one. Two bills, with the minority at the newest entry of one and the oldest of the other, so taking either end fails.
- A blank series takes its matched entries' category.
- Mixed categories resolve to the most common one, with the same two-bill arrangement.
- A set category is kept.
- A manual income series stays blank.
create_from_transaction: an expense takes the transaction's category, and an inflow stays uncategorised.-
GET new?entry_id=preselects the entry's category.- A paycheck dialog offers no category field.
-
POST createkeeps the chosen category.- A declared paycheck stays uncategorised.
- Another family's category is rejected with a 422.
After the change, I broke each piece in turn and checked that a test fails. That covered each fill call, both halves of the fill guard, the most-common rule (including filling from the first or the last entry instead, on both paths), the selected column, the
create_from_transactioncategory and its income guard, the prefill, the permit, theDeclaredBillassignment and its income guard, the form field and its income guard, and the ownership validation. All were caught.test/models/recurring_transaction(directory),test/models/recurring_transaction_test.rb,test/controllers/recurring_transactions_controller_test.rb,test/controllers/recurring_transactions/smart_fills_controller_test.rb,test/models/assistant/function/create_bill_test.rbandtest/controllers/transactions_controller_test.rbgive 524 runs, 1796 assertions, 0 failures, 0 errors.bin/rails test): 12490 runs, 57722 assertions, 0 failures, 0 errors, 36 skips.bin/rubocopanderb_lintare clean on the changed files.bin/brakemanreports 0 warnings.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Recurring bills and other non-income transactions can now be assigned a category when created or edited. The category selector follows your family’s category-lock setting.
Categories from the original transaction are retained when setting up a recurring transaction, and recurring bills without a category may be assigned the most common category from matching transactions.
Bug Fixes
Income recurring transactions remain uncategorized, even if a category is submitted.
Categories belonging to another family are rejected when creating a recurring transaction.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->