Skip to content

Refuse quantity-led serving names in add/update_custom_food - #3

Merged
ColinToft merged 5 commits into
mainfrom
colin/unify-serving-names
Oct 12, 2026
Merged

ColinToft merged 5 commits into
mainfrom
colin/unify-serving-names

Conversation

@ColinToft

@ColinToft ColinToft commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

update_custom_food split a leading number off serving_name ("2 cookies" became "cookies" × 2); the recipe tools refuse it. Now add_custom_food and update_custom_food fail fast too, via one shared _serving_name: the number goes in serving_quantity.

  • Removes _QUANTITY_LED_NAME.
  • add_custom_food gains serving_quantity (default 1); default name "serving".
  • create_custom_food now settles its serving like create_recipe (shared _settle_serving): a name the server re-parses, e.g. "serving (1/2 batch)", is re-sent once. It returns the real measure_id.
  • Resizing still resets the quantity to serving_quantity (or 1), as upstream update_custom_food: set the default serving's quantity rwestergren/cronometer-api-mcp#66 does.
  • Tests cover refusals with no request sent, the re-parsing fake server, and the tool reaching amount.
  • Live: "cookies" × 2 (update and create) read back correctly; "2 cookies" sent nothing; "serving (1/2 batch)" came back as 0.5 × "batch)", was re-sent, and stuck.

Behaviour change: names like "0 calorie syrup" or "1/2 cup" are now refused, matching the recipe tools. serving_grams of 0 or less, NaN or inf is refused. update_custom_food raises when the stored serving weight is unusable, the food has no serving, or its default measure id matches none, instead of falling back.

🤖 Generated with Claude Code

update_custom_food quietly split a leading number off serving_name
("2 cookies" became "cookies" x 2), while add_recipe/update_recipe refuse
the same input. Guessing the server's name parser proved fragile (mixed
numbers, "8 fl oz", unicode fractions), so both tools now fail fast through
one shared _serving_name helper: the number goes in serving_quantity.

Drops _QUANTITY_LED_NAME and its splitting branch. Resizing a custom food
still resets the quantity to serving_quantity (or 1), as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ColinToft
ColinToft force-pushed the colin/unify-serving-names branch from 5bc2ca7 to f46d115 Compare October 12, 2026 23:10
create_custom_food defaulted to "1 serving" and relied on the server to
split the number off a new measure's name. It now takes serving_quantity
(default 1, sent as the measure's amount), defaults the name to "serving",
and runs both through the same checks as the edit tools before any request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ColinToft ColinToft changed the title Refuse quantity-led serving names in update_custom_food Refuse quantity-led serving names in add/update_custom_food Oct 12, 2026
ColinToft and others added 3 commits October 12, 2026 16:15
A serving_grams of 0 or less used to fall back to a scale of 1, storing the
per-serving numbers as per-100g. It is now checked with _check_positive
before any request, like update_custom_food (NaN and inf are refused too).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Split _settle_recipe_serving into a shared _settle_serving (read the
  serving back, re-send once if the server re-parsed its name, raise if it
  still doesn't match) plus the recipe-only nutrient-derivation check.
  create_custom_food now uses it, so "serving (1/2 batch)" no longer comes
  back as 0.5 x "batch)", and it returns the real measure_id (the
  add_custom_food tool no longer re-fetches the food for it).
- update_custom_food raises instead of falling back to 100 g or a scale of
  1 when the default serving's weight isn't a positive finite number, and
  refuses serving or nutrient edits on a food with no serving measure.
- Share _is_positive_number between _check_positive and diary enrichment.
- serving_grams docstrings: total weight of all serving_quantity units.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- create_custom_food and create_recipe index defaultMeasureId directly.
- _default_measure returns None only for a food with no measures, and
  raises when defaultMeasureId matches none, instead of quietly using the
  first measure.
- Tests for create's failure paths after the food exists: a failing
  read-back, a failing re-send, and a read-back missing the default
  measure or its id all raise with the food's id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ColinToft
ColinToft merged commit dabe4d9 into main Oct 12, 2026
@ColinToft
ColinToft deleted the colin/unify-serving-names branch October 12, 2026 23:40
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