diet-guard/diet_guard
Krzysztof kuhy Rudnicki be94b4e147 Sync before locking the gate + manual "Fetch from sync" button
The PC gate forced a re-log when a meal was already logged on the phone
but the 15-min sync had not yet propagated it. Two ways to close that gap:

- The gate now pulls the shared log right before it would lock -- and only
  when a lock is otherwise due, so the network cost is paid on the rare
  tick that matters. A meal already pushed by the phone then unlocks
  without re-entry. Fails closed: any sync error (no token, network, disk
  write-back) falls through to the local lock decision, never skips it.
- A "Fetch from sync" button on the lock screen runs the same pull on
  manual request: it auto-unlocks when the pull satisfies every pending
  slot, advances to the next meal on a partial pull, or reports no change.
  Disabled in --demo so the sandbox never triggers a real sync/push.
- Both paths share one fail-closed wrapper, _sync.pull_shared_log(), which
  also keeps the single broad-except in one place.
- _write_log is now atomic (temp file + Path.replace): the gate and the
  15-min sync timer can now both write the log, so a torn read must be
  impossible.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FtSmzACzJSGyEatgK9exkd
2026-07-11 17:54:38 +02:00
..
tests Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00
__init__.py feat(diet_guard): add meal-logging screen-lock gate with trigger fix 2026-06-10 22:32:39 +02:00
__main__.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_budget.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_cli_gate.py Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00
_cli_sync.py Migrate sync to shared crdt_sync library (Python + Dart) 2026-07-10 23:49:43 +02:00
_cli.py Add cross-device log sync (Python half of Milestone 3) 2026-06-22 19:36:27 +02:00
_coerce.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_constants.py Point sync at the consolidated utils/syncs monorepos 2026-07-10 14:12:16 +02:00
_estimator.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_foodbank.py Add cross-device log sync (Python half of Milestone 3) 2026-06-22 19:36:27 +02:00
_fuzzy.py feat(diet_guard): add meal-logging screen-lock gate with trigger fix 2026-06-10 22:32:39 +02:00
_gate.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_gatelock_core.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_gatelock_mealflow.py Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00
_gatelock_nutrition.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_gatelock_support.py feat: split oversized modules for 500-line limit, fix kasa coverage gap 2026-06-14 07:19:37 +02:00
_gatelock_ui.py Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00
_gatelock.py Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00
_mcp.py Add MCP server exposing diet status + a gated log_meal 2026-07-10 21:36:46 +02:00
_meal.py Add sync-ready log schema: stable id, tombstone undo, composite components 2026-06-22 18:22:24 +02:00
_portions.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_resolve.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_slots.py Extract diet_guard from testsAndMisc as a standalone repo 2026-06-22 12:18:39 +02:00
_state.py Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00
_sync_merge.py Migrate sync to shared crdt_sync library (Python + Dart) 2026-07-10 23:49:43 +02:00
_sync.py Sync before locking the gate + manual "Fetch from sync" button 2026-07-11 17:54:38 +02:00