Skip to content

[BUG] Server history gives up after startup upstream resolution miss #53

Description

@CaneTLOTW

Follow-up discovered during Issue #52 read-only audit on exact runtime/develop SHA 4b00b81e3f85c012504ea99b8b50f02d742d378e.

Observed live store state after successful HA restart:

server_history_ready=false
server_history_source=local_fallback
server_history_reason=upstream_vehicle_unavailable
last_sync=2026-09-02T19:59:43Z

This means PR #51's historical /trips transport is present but the current runtime never reached it because ServerHistoryManager._resolve_upstream() did not resolve a client/vehicle during initialization.

Current lifecycle is fragile:

  • async_setup_entry() starts server_history.async_initialize() immediately in the background;
  • async_initialize() resolves the upstream client/vehicle and, on failure, schedules only three retries;
  • _retry_initialize() sleeps 5 seconds, so the manager gives up after a short startup window;
  • after those retries there is no later reacquisition/resync trigger when Stellantis Vehicles becomes fully available.

Current resolution path also depends first on the selected HA device's config_entries relation and only then checks that entry's runtime_data / legacy cache. The upstream's current supported runtime contract is ConfigEntry.runtime_data = StellantisVehicles, with per-VIN coordinators stored on that object.

Required investigation/fix:

  1. On the live runtime, determine exactly which resolution step fails after restart: selected device reference, device config_entries, upstream config entry lookup, runtime_data, async_get_coordinator_by_vin(vin), or cached _vehicle VIN match.
  2. Keep VIN verification strict. Never bind to a different vehicle merely because only one upstream entry exists.
  3. Make upstream resolution resilient to startup ordering. A missed initial lookup must not permanently disable server history for the whole HA uptime.
  4. Prefer a narrow local solution in sv_dashboard; do not modify or monkey-patch andreadegiovine/homeassistant-stellantis-vehicles.
  5. A safe fallback may scan loaded stellantis_vehicles config entries when the device-registry link is absent/stale, but only accept an entry whose already-cached coordinator/vehicle matches the exact configured VIN.
  6. Add a cancellable delayed/background reacquisition strategy (or equivalent event-driven retry) so upstream_vehicle_unavailable can recover later without blocking HA startup or creating an unbounded tight loop.
  7. Once resolution succeeds, run the normal historical sync and canonical rebuild, update readiness/source truthfully, and refresh entities.
  8. Preserve local fallback while unresolved and preserve archived server rows; do not mark them fresh until a successful sync.
  9. Add regression tests for startup-order miss → later recovery, stale/missing device-registry config-entry linkage, strict VIN mismatch rejection, cancellation/unload, and no duplicate concurrent sync loops.

This issue should be solved before relying on Issue #52's historical server-row backfill in the UI, because while server_history_ready=false the Trip History card intentionally uses its Recorder/local fallback path.

No main promotion or release until runtime validation on an exact merged develop SHA.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions