Skip to content

[somatic-scripts] MacroChef remaining macros wrong: planner.calories ≠ MF displayed target (base strategy vs expenditure-adjusted) #28

@githumps

Description

@githumps

Problem

MacroChef shows Cal -1797 but MF app shows consumed 3583 of target 2433 → expected remaining ≈ -100 (after 1050 active energy buffer). The difference is 647 cal.

Root Cause

get_goals() in macrofactor.py:641-662 reads planner.calories from MF Firestore. This is the base strategy target (1786 for this user on Wed Apr 22). MF's app displays the expenditure-adjusted target (2433). MacroChef never sees the adjusted value.

Arithmetic proof: 3583 (consumed) - 1786 (planner goal) = -1797 (matches MacroChef display). The delta 2433 - 1786 = 647 is MF's coaching/expenditure adjustment.

planner.tdeeValue IS already extracted (macrofactor.py:658-661) but never used in the remaining calculation (http_macrofactor_port.py:174).

Code Path

  1. http_macrofactor_port.py:148goals = await mf.get_goals()
  2. macrofactor.py:652-657 → reads planner.{calories,protein,carbs,fat} arrays
  3. http_macrofactor_port.py:174cal = _pick(goals["calories"]) - consumed_cal
  4. Result stored as session.remaining_cal (frozen at session creation)
  5. Template session.html:19 → renders raw session.remaining_cal = -1797
  6. Stacked bar web.py:230max(0.0, remaining) = 0 (hides the problem)

Investigation Needed

  • Add /debug/probe-mf-goals route to dump the full planner dict — find whether MF stores an adjusted target field
  • Check if tdeeValue can be used to compute the adjustment (adjusted = planner.calories + (tdee - planner.calories))
  • Compare planner.calories values across multiple days vs MF-displayed targets to validate the formula

Related

  • Active energy "over 2h old (122 min)" is a separate VT staleness issue, not related
  • Meal generation stalling at 3/10 is a separate Ollama/recipe-DB issue
  • web.py:230 max(0.0, ...) is by-design for the stacked bar, not a bug itself

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions