You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(llm): normalize SDK content blocks + route through db.local_today
Two issues from the new Copilot review pass.
1) chat() was appending response.content (real Anthropic SDK pydantic
blocks) verbatim to messages on tool_use iterations. The SDK *does*
accept its own block types on input, but normalizing to plain dicts
is more robust across SDK versions and makes the wire format
deterministic. New _block_to_dict helper:
- dicts pass through unchanged
- SDK objects use .model_dump() with try/except fallback
- SimpleNamespace / arbitrary attrs fall back to manual extraction
for tool_use / text shapes
The chat loop now serializes content via [_block_to_dict(b) for b
in response.content] before re-posting.
2) Promoted db._local_today → db.local_today (single underscore-free
public name) and routed _execute_chat_tool's two day-bucket lookups
through it. Now the patch hook used by the test_nutrition.py
regression cases (test_recent_calorie_balance_anchors_on_local_today,
etc.) covers the chat tool dispatcher too — one patchable seam for
all "what local day is it?" computations across db.py and llm.py.
Tests (+4)
- test_chat_normalizes_content_blocks_to_dicts_before_re_sending:
asserts the assistant turn that goes back to messages.create has
plain dicts (not SimpleNamespace / SDK objects) and the round-trip
preserves type/id/name/input.
- test_block_to_dict_uses_model_dump_when_available: real-SDK path.
- test_block_to_dict_falls_back_when_model_dump_raises: defensive path.
- test_execute_chat_tool_uses_db_local_today: patches db.local_today
to a fixed date and confirms get_balance resolves "today" through it.
Tests adjusted (rename _local_today → local_today across):
- src/db.py (definition + 4 callsites)
- tests/test_nutrition.py (4 patches + sanity test)
- tests/test_training_intel.py (1 doc reference)
Test count: 144 → 148.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments