PetCare Sync

Multi-caregiver pet medication and chronic-care journal with create-only dose attribution, offline queue reconciliation, Europe/Warsaw DST scheduling, and two-tier safety gating for real-time voice logging.

PetCare Sync shared schedule timeline alongside the two-tier voice medication confirmation prompt
Shared household schedule timeline (left) and two-tier voice readback confirmation gate (right).

Overview

PetCare Sync (pet_journal) is a cross-platform mobile/web application and Python backend designed for households and pet sitters coordinating daily chronic-care medications and veterinary observations. It pairs an Expo / TypeScript client with Python 3.12 Cloud Functions, Cloud Firestore security rules, and a FastAPI real-time voice gateway.

Problem

Shared household medication tracking presents subtle concurrency and safety hazards:

  • Concurrent or offline double-dosing: If two caregivers confirm a morning capsule while one phone is on a flaky connection, last-write-wins updates silently overwrite attribution, while naive durable retry queues can deadlock if server rules reject a stale payload or an auth token expires after an hour offline.
  • Unconfirmed voice mutations: Connecting a full-duplex streaming voice model directly to database write tools risks mislogging medication doses due to background speech, acoustic echo, or model hallucination.
  • Schedule and unit drift: Spring/autumn DST transitions in Europe/Warsaw shift or duplicate wall-clock slots if stored as naive UTC offsets, and IEEE-754 floating-point conversions between kilograms and pounds introduce rounding drift in longitudinal weight histories.

Approach and architecture

  • Create-only occurrence reconciliation: Scheduled doses map to deterministic scheduleId|YYYY-MM-DD|HH:mm document IDs evaluated in the household’s IANA timezone with explicit DST gap and fold rules. firestore.rules enforces create-only dose records so concurrent confirmations resolve deterministically into a single winner and explicit conflict visibility rather than overwriting state.
  • Two-tier real-time voice gateway: A FastAPI WebSocket service streams 16 kHz/24 kHz PCM audio to the Gemini Live API with client-side hardware acoustic echo cancellation. Low-risk Tier-1 observations log immediately with session-scoped undo, whereas Tier-2 medication writes create a staged PendingVoiceProposal, read back the exact pet, medication, dose, and status, and block persistence until explicit verbal or tap confirmation.
  • Offline survival and canonical precision: Client queues distinguish transient network failures from terminal rule rejections, resolve actor metadata locally when offline past the 1-hour JWT window, and store all weights as canonical integer grams across TypeScript BigInt, Python Decimal, and Firestore validation rules.

Engineering decisions and trade-offs

  • Dual demo and firebase backends: Implementing an in-memory two-caregiver simulation adapter alongside the Firebase/Cloud Run adapter allowed deterministic race, replay, and DST testing locally without cloud credentials, at the cost of maintaining strict interface parity across both adapters.
  • Mandatory confirmation latency on voice medication actions: Requiring an extra readback turn for Tier-2 voice actions trades conversational speed for zero unconfirmed writes on safety-critical records.

Evaluation and results

Verified across 289 automated Python and TypeScript tests and an 8-suite local consistency scorecard (make eval):

  • 20-thread simultaneous administration race: 1 record created, 19 deterministic conflicts returned, 0 silent overwrites.
  • Tier-2 voice safety gate: 0 unconfirmed medication writes across voice gateway and client sheet test suites.
  • Timezones and precision: Verified Europe/Warsaw spring-forward (02:30 -> 03:00) and autumn fold behavior, time-bounded sitter handover expiry in firestore.rules, and 0.00 g conversion drift across kg/lb round-trips.

Limitations

PetCare Sync is an open-source portfolio prototype; live Firebase, Cloud Run voice gateway, and RevenueCat integrations require self-provisioned credentials outside the local simulation mode, and veterinary trend charts are strictly observational rather than diagnostic.