Skip to content

Recover missed events and add safe history replay - #170

Draft
flinter15 wants to merge 4 commits into
OnlyCatAI:masterfrom
flinter15:codex/upstream-event-recovery
Draft

Recover missed events and add safe history replay#170
flinter15 wants to merge 4 commits into
OnlyCatAI:masterfrom
flinter15:codex/upstream-event-recovery

Conversation

@flinter15

Copy link
Copy Markdown

Summary

This draft addresses event-history fidelity and recovery after transient gateway gaps:

  • retain the exact RFID, direction, and action subevents returned by getEventSummary
  • add a manual, throttled onlycat.backfill_event_summaries action, including optional cursor-based full-history replay
  • reconnect a dropped or half-connected Socket.IO namespace with bounded exponential backoff and restore subscriptions
  • reconcile every unseen event ID from the latest gateway page after reconnecting
  • check that page every 15 minutes as a safeguard against silent push gaps

Motivation

The existing reconnect path hydrates only the newest event. If the WebSocket silently drops events and a later event is delivered, earlier event IDs can remain absent from Home Assistant Recorder indefinitely. That loses transit and contraband history even though the gateway still retains those events.

Safety and gateway load

  • Access tokens are used for summary retrieval but are never exposed as entity attributes.
  • Historical replay has a separate listener path and restores the live event afterward, so it does not rewrite current pet location, door policy, or flap state.
  • Manual backfill is bounded by default, deduplicates event IDs, detects non-advancing cursors, and sends at most one gateway request per second.
  • Automatic reconciliation requests only the latest event page every 15 minutes and fetches summaries only for unseen IDs.
  • Successfully handled IDs are retained in a bounded 200-ID set per device.
  • Incomplete summaries remain unseen and are retried on a later reconciliation.

The interval and full-history option are intentionally called out for maintainer review because the OnlyCat team can best judge the gateway's preferred load profile and API guarantees.

Compatibility

The branch is based on current upstream master and retains the new API-key setup and persisted pet/device-tracker state. It does not change upstream ownership, repository URLs, manifest version, or changelog.

The work is separated into four logical commits for easier review. I am happy to split it into smaller PRs if preferred.

Testing

  • ruff format --check .
  • ruff check .
  • git diff --check
  • full test suite in ghcr.io/home-assistant/home-assistant:stable (Python 3.14.6): 26 passed

Regression coverage includes a gap where event IDs 1331 and 1332 are missing even though a later ID has already been processed, plus retry behavior when an event summary is temporarily incomplete.

@flinter15
flinter15 force-pushed the codex/upstream-event-recovery branch from 2811fea to 1cdedc2 Compare July 22, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant