diet-guard/app/lib/services
Krzysztof kuhy Rudnicki e23f7ac3b4
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
Push under a persisted per-install uuid, not a fixed role id
diet_guard pushed as "pc" (Python), "phone" (Android) and "desktop" (web).
A role constant collides the moment a second machine takes the same role,
and after a reinstall the new install inherits the previous one's CRDT
identity -- the same reasoning home_inventory already records for choosing a
uuid. Both halves now mint a uuid once and persist it: the PC in
~/.local/share/diet_guard/.device_id, the app under SharedPreferences
'crdt.nodeId' (the key todo and home_inventory already use).

The old constant survives as the legacy id and is passed to sync_log /
syncLog, so devices/<legacy>/ is skipped as this device's own. Without that
every tick would re-download and re-merge this device's own pre-migration
log as though a peer had written it -- idempotent under LWW, but hundreds of
KB, 96 times a day. It drops to None once that path is reclaimed; a test
covers both states, including a negative control proving the skip is the
legacy id's doing.

All four documents move together (food_log, food_bank, food_bank_manual,
budget), and the hist:<date> fields riding on the budget record are
untouched -- merge_record unions field names, so they relay through
unchanged.

The resolver lives in its own module (_device.py / sync_device_id.dart)
because _sync_merge needs it for HLC stamping too and importing _sync there
would be a cycle. Dart resolves it asynchronously at startup, before
LogStorageService.init(); currentSyncDeviceId falls back to the compile-time
role constant until then, so a too-early Hlc stamp gets a valid id rather
than crashing.

conftest redirects the new id file in the same change that introduces it --
without that a test mints a uuid into the real state dir and this machine's
live sync identity is decided by whichever test ran first. Verified by
checking ~/.local/share/diet_guard/ before and after: untouched.

Verified live, not just against mocks: the sync timer ran mid-change and
migrated this machine to f8f46da6. All 358 food_log records and all 100
food_bank records are present under the new path (0 missing vs devices/pc/),
and the new log's HLCs carry only its own id -- confirming it did not
re-merge the old path as a peer.

Python: 687 tests, 100% branch coverage. App: 518 tests, analyzer clean.
Pins bumped to crdt-sync-v0.6.0 / crdt_sync_dart-v0.7.0 (pyproject,
requirements.txt, .pre-commit-config.yaml, pubspec), and the new library is
installed into /usr/bin/python's user site-packages so the production timer
does not ImportError on its next tick.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZH89WEqAjuJT8WZdqc7AP
2026-08-09 17:18:42 +02:00
..
app_settings_service.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
average_service.dart Step Dart dates by the calendar, not by 24 hours 2026-08-09 15:06:41 +02:00
background_check_service.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
background_sync_service.dart Sync meals and the food bank through Firebase, mirroring to GitHub 2026-08-05 08:35:21 +02:00
background_tasks_io.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
background_tasks_web.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
background_tasks.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
budget_history_service.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
budget_schedule.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
day_status_service.dart Step Dart dates by the calendar, not by 24 hours 2026-08-09 15:06:41 +02:00
desktop_wrapper.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
document_store_factory.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
document_store_indexeddb.dart app: test the IndexedDB stores instead of shipping them unverified 2026-07-20 16:56:15 +02:00
document_store_io.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
document_store_web.dart app: test the IndexedDB stores instead of shipping them unverified 2026-07-20 16:56:15 +02:00
document_store.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
due_slot_check.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
firebase_backend.dart Sync meals and the food bank through Firebase, mirroring to GitHub 2026-08-05 08:35:21 +02:00
foodbank_service.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
frame_stats.dart app: package the desktop app as the web build, and delete the Linux embedder 2026-07-20 16:32:24 +02:00
fuzzy.dart Add Flutter companion app skeleton with local meal logging 2026-06-22 18:22:42 +02:00
github_client_factory_io.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
github_client_factory_web.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
github_client_factory.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
github_device_auth.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
log_storage_service.dart Remove unused features; fix reminder false alarms; share all state 2026-07-26 16:39:52 +02:00
notification_backend_factory.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
notification_backend_io.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
notification_backend_web.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
notification_backend.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
notification_service.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
sync_device_id.dart Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
sync_merge.dart Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
sync_service.dart Push under a persisted per-install uuid, not a fixed role id 2026-08-09 17:18:42 +02:00
sync_settings.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
sync_state_factory_io.dart Sync meals and the food bank through Firebase, mirroring to GitHub 2026-08-05 08:35:21 +02:00
sync_state_factory_web.dart Sync meals and the food bank through Firebase, mirroring to GitHub 2026-08-05 08:35:21 +02:00
sync_state_factory.dart Sync meals and the food bank through Firebase, mirroring to GitHub 2026-08-05 08:35:21 +02:00
token_vault_factory.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
token_vault_io.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
token_vault_web.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00
token_vault.dart app: run the companion app's desktop target as a web build 2026-07-20 16:31:32 +02:00