Skip to content

fix(data): correct calorie rows behind #192's ingredient re-pins (kcal audit) - #205

Merged
SamGu-NRX merged 5 commits into
alphafrom
obv/burst12-fridgeluck-kcal-repin-audit
Oct 16, 2026
Merged

SamGu-NRX merged 5 commits into
alphafrom
obv/burst12-fridgeluck-kcal-repin-audit

Conversation

@obvious-autobuild

@obvious-autobuild obvious-autobuild Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

What this branch ships — and what it does not

Ships: the audit (evaluation/kcal-audit/ — report, script, pytest gate) and one catalog row — FDC 173627 "Chicken, broilers or fryers, dark meat, thigh, meat only, raw", with five search aliases — plus the catalog SQLite rebuilt from canonical (960 records). Nothing else.

Does not ship: any change to data/ingredients/vocabulary.json, data/recipes/build/recipes-v2.json, apps/ios/Resources/RecipeCatalog/recipes-v2.json, or the nutrition-changes file. Those belong to the rebuild packet (burst12-fridgeluck-catalog-rebuild), which owns the vocabulary and shipped bundles. Shipped per-serving calories are unchanged by this branch, and test_kcal_drift.py fails here exactly as it fails on alpha's head (the pre-rebuild changes-file assert).

Context: PR #192 re-pinned catalog ingredient rows so typed pantry text resolves (reach v3). Eleven of those re-pins also re-sourced the vocabulary's per-100 g nutrition, and for four keys the new row describes a different preparation form than the recipes measure — cooked thigh on raw thigh lines, cooked rice on dry rice cups, "canned, cooked" on as-sold crushed/chopped tomatoes. On alpha, test_kcal_drift.py fails (16 recipes over the 40 percent drift gate with no recorded reason) and validate_bundle.py --real-bundles reports the same 16 drift problems. This branch is the audit input that packet must apply.

Fidelity anchor: corpus, rights, name mappings, and the compiler are unchanged 9e4a3af5..alpha (verified with git diff --stat), so the audit's in-memory prev state reproduces the published bundle exactly: max |delta| 0.0000 kcal over all 762 recipes.

For the rebuild packet: exact vocabulary pin changes to apply

Identity pins from #192 stay untouched (chicken thigh(s) 2706027, white rice 2708403, canned tomatoes 2709722). The packet must change only each entry's per-100 g nutrients and nutrition-source citation:

vocabulary key nutrient row to cite per-100 g (kcal / protein / carbs / fat / sodium) replaces
chicken_thighs fdc 173627 — SR Legacy "Chicken, broilers or fryers, dark meat, thigh, meat only, raw" 121.0 / 19.66 / 0.0 / 4.12 / 0.095 g FNDDS thigh cooked skin-eaten, 226
chicken_thigh fdc 173627 — same row 121.0 / 19.66 / 0.0 / 4.12 / 0.095 g FNDDS thigh stewed skin-eaten, 227
white_rice fdc 168877 — SR Legacy "Rice, white, long-grain, regular, raw, enriched" 365.0 / 7.13 / 79.95 / 0.66 / 0.005 g FNDDS cooked rice, 96/129
canned_tomatoes fdc 170501 — SR Legacy "Tomatoes, crushed, canned" 32.0 / 1.64 / 7.29 / 0.28 / 0.186 g FNDDS canned cooked, 43

Evidence per decision is in evaluation/kcal-audit/kcal-audit.md (read from USDA FoodData Central bulk CSVs — Survey 2024-10-31, SR Legacy 2018-04, CC0 — not the web UI). Corpus form evidence: all 23 chicken_thighs lines are "boneless chicken thighs" pieces of 110 g; 41 of 41 chicken_thigh lines measure raw thigh; 59 of 60 white_rice lines measure dry rice by cup (185 g), with the 14 cooked-rice lines (rcp-000573, 580, 586, 589, 599, 605, 610, 631, 634, 645, 649, 652, 686, 722) listed exceptions; canned_tomatoes lines use the as-sold product. Rows kept after verification (documented in the audit): lentils 172420 (352), sugar 169655 (387), banana 173944 (89), cinnamon 171320 (247), almonds 170567 (579), bacon 2705885 (484), heavy cream 2346386 (343.31), pork chop 2705866 (183, kept as closest cited row).

For the rebuild packet: the exact nutrition-change records to write

The rebuild's changes file must record (recipe id, old kcal, new kcal, reason) for every recipe the fixed state moves more than 40 percent versus the published bundle — 55 records (16 pre-existing drifts plus honest corrections the audit surfaces). Full reasons per record are in evaluation/kcal-audit/kcal-audit.md; the records:

recipe prev kcal fixed kcal swing deciding keys
rcp-000213 363.1 614.1 +69% chicken_thighs, white_rice
rcp-000221 441.5 699.7 +58% canned_tomatoes, chicken_thighs, white_rice
rcp-000260 548.2 785.1 +43% pork_chop, white_rice
rcp-000266 472.3 721.1 +53% white_rice
rcp-000267 441.8 690.7 +56% white_rice
rcp-000270 296.6 545.4 +84% white_rice
rcp-000279 360.1 546.8 +52% white_rice
rcp-000293 412.4 663.4 +61% chicken_thighs, white_rice
rcp-000298 482.4 793.4 +64% white_rice
rcp-000304 413.1 661.9 +60% white_rice
rcp-000305 626.5 999.7 +60% bacon, white_rice
rcp-000322 568.8 817.7 +44% white_rice
rcp-000352 353.7 602.5 +70% white_rice
rcp-000373 348.4 721.7 +107% white_rice
rcp-000378 320.6 693.9 +116% white_rice
rcp-000386 568.0 941.2 +66% canned_tomatoes, white_rice
rcp-000402 289.8 173.2 -40% chicken_thigh
rcp-000410 317.7 568.7 +79% chicken_thighs, white_rice
rcp-000411 232.2 408.0 +76% heavy_cream, lentils
rcp-000428 222.5 346.9 +56% white_rice
rcp-000429 144.9 269.3 +86% white_rice
rcp-000461 278.2 161.6 -42% chicken_thigh
rcp-000465 365.2 551.9 +51% white_rice
rcp-000482 230.7 417.4 +81% white_rice
rcp-000486 213.4 400.1 +87% white_rice
rcp-000487 234.2 483.0 +106% white_rice
rcp-000488 382.6 569.3 +49% white_rice
rcp-000504 442.3 691.1 +56% white_rice
rcp-000511 205.8 469.0 +128% canned_tomatoes, white_rice
rcp-000512 181.7 444.9 +145% canned_tomatoes, white_rice
rcp-000516 350.8 599.6 +71% white_rice
rcp-000518 392.5 579.2 +48% white_rice
rcp-000524 176.6 370.5 +110% canned_tomatoes, white_rice
rcp-000525 441.2 690.0 +56% white_rice
rcp-000546 192.6 379.3 +97% white_rice
rcp-000548 262.4 451.3 +72% chicken_thighs, white_rice
rcp-000564 150.0 383.7 +156% lentils
rcp-000567 206.5 393.2 +90% white_rice
rcp-000569 309.1 495.8 +60% white_rice
rcp-000573 389.2 1026.7 +164% white_rice
rcp-000580 208.0 526.7 +153% white_rice
rcp-000586 338.1 663.0 +96% sugar, white_rice
rcp-000597 39.0 63.6 +63% sugar
rcp-000599 560.7 852.6 +52% chicken_thigh, sugar, white_rice
rcp-000605 300.8 640.8 +113% white_rice
rcp-000610 292.0 717.0 +146% white_rice
rcp-000631 407.7 840.9 +106% sugar, white_rice
rcp-000634 420.0 853.3 +103% sugar, white_rice
rcp-000645 352.8 699.2 +98% sugar, white_rice
rcp-000649 420.0 853.3 +103% sugar, white_rice
rcp-000652 456.3 802.7 +76% sugar, white_rice
rcp-000666 143.7 276.5 +92% lentils
rcp-000686 585.7 904.4 +54% white_rice
rcp-000702 356.8 208.4 -42% chicken_thigh
rcp-000728 160.4 293.3 +83% lentils

Reason groups: raw thigh row (fdc 173627) for thigh recipes; dry-rice row (fdc 168877) for white-rice recipes, with the 14 cooked-rice-line exceptions carrying their own exception reason; dry-lentil row (fdc 172420); granulated-sugar row (fdc 169655); crushed-canned row (fdc 170501).

Reach, re-measured (this review round)

python3 evaluation/catalog-reach/reach_report_v3.py --before-sqlite <origin/alpha b33239f5 sqlite> --before-bundle <origin/alpha data/recipes/build/recipes-v2.json>, after = this branch's head:

state exact medians (omn/veg/vegan/gf/df) near medians wrong-ID lost lines
before (origin/alpha b33239f5) 1.5 / 0.5 / 0 / 0 / 0 108.5 / 58.5 / 23.5 / 47.5 / 49.5 2044
after (this branch) 4.5 / 1.5 / 0 / 2.5 / 2.0 162.5 / 93.5 / 29 / 76 / 78 0

Unbridged lines 1220 and not-in-pantry 28131 in both states. The two catalog databases differ only in physical row ordering/ids, the added row 173627, and its five aliases; the numbers above are the measured output of the replay over them. The after-state matches the after-numbers PR #192 published (exact 4.5 / 1.5 / 0 / 2.5 / 2.0; near 162.5 / 93.5 / 29 / 76 / 78; wrong-ID 0).

How I checked it (commands and results)

  • cd scripts/data && uv run usda validate --canonical catalog/usda_curated_ingredients.json — Validation OK (960 records, 3947 unique aliases, 14 required terms); uv run usda build-sqlite ... — 960 rows.
  • python3 -m pytest evaluation/kcal-audit/test_kcal_audit.py -q — 4 passed (fidelity anchor; every gate recipe documented and nothing else; audit rows exist in canonical catalog with cited macros; idempotence over the rebuilt vocabulary).
  • python3 -m pytest data/recipes/tools/tests -q — 75 passed, 1 failed, 1 skipped; the failure is test_kcal_drift.py changes-file consistency, unchanged from alpha's head by design (this branch does not touch the shipped bundle).
  • python3 evaluation/kcal-audit/kcal_audit.py — fidelity max |delta| 0.0000 kcal vs the published 9e4a3af bundle (762 recipes); 55 recipes above the gate at the fixed state, all tabulated; 16 above the gate at alpha.
  • Reach rerun as specified above (JSON at /tmp/audit/reach-v3-review.json in the sandbox); alias and content diffs between the two catalog databases checked directly.
  • Merged origin/alpha (b33239f5, merge — no rebase; alpha's move — PRs feat(data): add shipped-bundle safety invariants with a claims-vs-gate sweep #194/fix(onboarding): real setup lands in your kitchen, not a demo #206/feat(evaluation): audit legacy recipes that mislead or slip past the safety boundary #209 — touches none of this branch's files or the shipped bundle/vocabulary).

What I could not check

  • No Xcode here: no iOS build/simulator run (no Swift files changed; hosted macOS CI covers the repo build).
  • The rebuild packet's own outputs (re-sourced vocabulary, regenerated bundles, changes-file entries, test_kcal_drift.py going green) are not in this PR.
  • Reach replay is the report's Python model of IngredientRepository.search, not the app binary.

Assumptions

  • Majority measurement form decides single-form nutrient rows (the repo gate's own rule); minority-form lines are listed exceptions with their over/under-count disclosed, not silently accepted.
  • "Boneless chicken thighs" pieces are raw, skinless; generic "chicken thighs" purchase weights include bone+skin — the raw meat-only row is the closer approximation on both (documented residual error in the audit).
  • Pork chops keep the pinned FNDDS as-consumed row as closest cited row (raw twins within ~7 percent); no pork recipe approaches the gate.
  • Row 173627's aliases follow neighbouring meat-only rows' lowercase style (raw chicken thigh, chicken thigh meat only, ...); the pipeline normalized the parenthesized form to chicken thigh raw meat only.

Human author: Sam Gu (sgu07966@gmail.com)

🔗 Obvious Project · 🧵 Obvious Thread · 🔀 Obvious PR Artifact

…g sqlite

PR #192 re-pinned catalog ingredients for reach; four keys re-sourced
per-100g nutrition from rows that describe a different preparation form
than the recipes measure (cooked thigh on raw thigh lines, cooked rice on
dry rice cups, canned-cooked tomatoes on as-sold product). This audit
re-chooses the nutrient row per measurement form, keeps every identity
pin, and rebuilds the sqlite from canonical (restoring #192's claimed
reach, which the stale shipped sqlite had regressed).

- evaluation/kcal-audit: report, script (real compiler, three vocab
  states, fidelity 0.0000 vs published 9e4a3af bundle), pytest gate
- canonical catalog: add FDC 173627 (raw thigh meat only) -> 960 records
- shipped sqlite rebuilt from canonical (uv run usda validate OK)

Co-authored-by: Sam Gu <sgu07966@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9ccbba7e-6e81-4170-85f9-c85469fdfccc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

ObviousApp and others added 4 commits October 16, 2026 10:33
Co-authored-by: Sam Gu <sgu07966@gmail.com>
Row 173627 shipped with no alt_names, so users would see the raw USDA
string. Adds five aliases in the style of neighbouring meat-only rows
(mirrors 171129 Turkey Thigh (Raw, Meat Only)); the pipeline normalizes
the parenthesized form. Rewrites the reach section to measured numbers
with recorded inputs and states the branch scope: shipped calories are
unchanged; vocabulary.json and the bundles belong to the rebuild packet.

Co-authored-by: Sam Gu <sgu07966@gmail.com>
PR description lives on the pull request itself.

Co-authored-by: Sam Gu <sgu07966@gmail.com>
@SamGu-NRX
SamGu-NRX marked this pull request as ready for review October 16, 2026 13:57
@SamGu-NRX
SamGu-NRX merged commit 9e5af91 into alpha Oct 16, 2026
3 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T13:58:48.318229Z cd816c2 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codemetrics-ai

Copy link
Copy Markdown

Note

Review skipped

Codemetrics is installed on this repository, but it hasn't been added to your team yet.

To enable AI code reviews for this repo, go to your dashboard and add FridgeLuck to your team's repositories.

Sign up for free to 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.

2 participants