Skip to content

[BUG] Reacquired upstream history transport can bind to a closed aiohttp connector #55

Description

@CaneTLOTW

Follow-up/blocker discovered during the live runtime validation of Issue #53 on exact merged develop SHA 3f458b3906ce2c1db13ea982f2488418978ef0d3.

Runtime result from Issue #53:

initial:
server_history_ready=false
server_history_source=local_fallback
server_history_reason=upstream_vehicle_unavailable

later reacquisition:
server_history_ready=false
server_history_source=local_fallback
server_history_reason=sync_failed
server_history_capability=authenticated_trips_transport
server_history_error=Connector is closed.

The reacquisition worker therefore did what #53 intended: it later resolved a VIN-matching loaded upstream client/vehicle and reached the authenticated historical transport. The remaining blocker is that the resolved upstream HTTP transport was not usable at request time.

Relevant upstream lifecycle code at inspected upstream commit 950cc93074c7a43974956a3134579e2cbc81228d:

  • StellantisBase.start_session() creates a new aiohttp.ClientSession() only when self._session is falsey;
  • close_session() returns immediately when self._session.closed is already true and in that early-return path does not reset self._session = None;
  • make_http_request() catches request failures and calls close_session();
  • normal upstream config-entry shutdown also closes the shared session.

This makes a stranded closed-session/closed-connector reference a plausible cause, but it is NOT yet proven. A concurrent upstream request closing the shared session, a stale/shutting-down runtime client, or another lifecycle race must also be ruled out.

Required audit first

On the current HA runtime, without modifying source or stores, reproduce/inspect the failure and capture for the exact client object that SV resolves:

  1. upstream ConfigEntry id, loaded state and runtime_data object identity;
  2. exact VIN and coordinator identity returned by async_get_coordinator_by_vin(vin);
  3. client._shutting_down if present;
  4. client._session identity and whether it is None;
  5. client._session.closed when present;
  6. connector identity and connector.closed when present;
  7. whether a normal upstream coordinator/API refresh immediately before/after the SV history attempt succeeds or fails;
  8. whether the resolved runtime_data object changes across reload/reacquisition;
  9. exact exception type/traceback for Connector is closed. rather than only the message.

Do not expose tokens/credentials in the report.

Fix constraints

After the root cause is proven, implement the smallest SV-side compatibility fix. Keep the Stellantis Vehicles repository unchanged.

Architecture constraints:

  • exact VIN matching remains mandatory;
  • no independent OAuth/login/credential stack;
  • do not monkey-patch upstream methods/classes;
  • do not silently bind to a stale or shutting-down client;
  • prefer the currently loaded ConfigEntry.runtime_data object;
  • preserve local/archive fallback until an authenticated /trips sync actually succeeds;
  • transient transport/session lifecycle failures must remain recoverable in the same HA uptime and must not permanently strand server history in sync_failed;
  • do not clear/archive raw history on failure.

If the proven cause is a closed/stale upstream session object, the implementation must explicitly document why the chosen SV compatibility action is safe and narrowly scoped. Do not introduce a second long-lived HTTP session owned by SV without an explicit architecture review.

Regression tests

Cover the proven failure mode, including:

  • resolved client with unusable/closed transport;
  • later recovery to a usable authenticated transport;
  • strict VIN matching;
  • no duplicate retry loops;
  • unload cancellation;
  • archive/local fallback preservation;
  • readiness only after successful sync.

Issue #53 remains open until this blocker is fixed and the same runtime acceptance reaches server_history_ready=true, source=server, reason=sync_succeeded with a fresh last_sync.

No main promotion or release before runtime validation.

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