Skip to content

Count custom-food ingredients in a recipe's batch; verify every recipe save - #11

Merged
ColinToft merged 3 commits into
mainfrom
colin/recipe-custom-ingredient
Oct 13, 2026
Merged

ColinToft merged 3 commits into
mainfrom
colin/recipe-custom-ingredient

Conversation

@ColinToft

@ColinToft ColinToft commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

When a recipe used one of our custom foods as an ingredient, it was stored with the wrong batch weight, and create_recipe still reported success.

Root cause (verified live): Cronometer adds every ingredient's nutrients to a recipe, but adds its grams to "full recipe" only when all of the food's measures are Weight. create_custom_food saved servings as Atomic. In one test, 80 g of a 400 kcal/100 g food gave a 0 g batch at 320 kcal/100 g. The web client saves a weighed serving as Weight; Atomic is for count units.

Changes

  • create_custom_food saves the serving as Weight. The server adds a g measure, which _custom_food_serving ignores.
  • create_recipe / update_recipe refuse non-Weight ingredients before saving. After saving, they check the batch weight and macros, and raise on a mismatch.

The only legacy Atomic custom food is the milk, 85083211. Colin's six recipes and 160 database foods were all Weight.

Live: I tested these on ZZ foods (now retired): new food → update → recipe, the refusal, and a broken batch being caught. 830 tests pass; ruff is clean.

🤖 Generated with Claude Code

ColinToft and others added 3 commits October 13, 2026 13:19
…e save

Cronometer adds an ingredient's grams to a recipe's "full recipe" weight only
when all of the ingredient food's measures are type "Weight". create_custom_food
saved its serving as "Atomic", so a recipe using one of those foods got a 0 g
(or short) batch and inflated per-100 g nutrients, while create_recipe still
reported success.

- create_custom_food saves the serving as "Weight", as the web client does for
  a serving with a gram weight. The server then adds its own "g" measure, so
  the serving is found as the measure that isn't that g.
- update_custom_food re-types weighed "Atomic" measures as "Weight" on every
  save, so older foods are fixed by any edit (diary math is unchanged).
- create_recipe / update_recipe refuse ingredients with a non-"Weight" measure
  before saving, and after saving check the stored batch weight and the
  energy/protein/fat/carbs against the ingredients, raising on a mismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e-type shim

A Weight serving gets a server-added g, so update_custom_food's per-serving
edits on new foods needed measure_id. _custom_food_serving now ignores g/oz
when exactly one other measure remains, replacing _created_serving.

Older custom foods with Atomic servings are refused as recipe ingredients
rather than silently re-typed on any edit; they get a one-time migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant