Skip to content

B-6GRG-curated-food-packs-still-build-portion-ids-positionally

build/corpus.rs:2312 builds portion ids for foods-starter and foods-test as format!("{}-p{}", f.id, i + 1) — a re-indexed ordinal. Adding or removing one portion for a food shifts every later portion’s id, and intake_entries.portion_id / recipe_ingredients.portion_id point at those ids, so a logged meal can silently change measure.

This is the same corruption class fixed for the USDA pack, where portion ids now come from FDC’s own food_portion.id primary key. It needs a different fix: these portions come from vault notes with no upstream key, so the id must either be a hash of the portion’s own content (label, amount, unit, modifier, grams) or a key declared in the note itself.

  • Decide between a content hash and a declared key in the note
  • Handle collisions if hashing — two portions of one food with identical content must not collapse
  • Pin it with a test that inserts and removes a portion on the same food and asserts survivors keep their ids. A test that churns a different food passes under the broken form too, because the ordinal is per-food

Checked and clean nearby: panel_kind_members.id and corpus_notes.id are content-derived; only their sort_order is positional, which is presentation.


← Back to Backlog