HA showing sensors as recently updated but nothing new written to states or statistics tables

I encountered a weird situation today and not sure what triggered it.

Suddenly, all my sensors stopped recording data to the states and statistics tables for all my sensors – whether system defaults, MQTT, or any other integration. No new entries and no changes to existing entries (e.g., no last_changed_ts updates either).

However, HA continued to otherwise seem to run normally with no high level log errors shown in the GUIand no ‘notifications’. Indeed, when looking at the sensor in the Overview dashboard, the states would all say they were updated during the past few minutes – but the sensor values never changed.

My automations also seemed to stop running – ironically, even the one that I use to warn me of stale sensors.

The detailed logs (using ‘ha core logs’) showed thousands of entries of form:

2025-01-06 17:55:09.030 ERROR (Recorder) [homeassistant.components.recorder.core] SQLAlchemyError error processing task CommitTask()
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 894, in _process_one_task_or_event_or_recover
    task.run(self)
    ~~~~~~~~^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 295, in run
    instance._commit_event_session_or_retry()  # noqa: SLF001
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1193, in _commit_event_session_or_retry
    self._commit_event_session()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1219, in _commit_event_session
    session.execute(
    ~~~~~~~~~~~~~~~^
        update(States),
        ^^^^^^^^^^^^^^^
    ...<6 lines>...
        ],
        ^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2362, in execute
    return self._execute_internal(
           ~~~~~~~~~~~~~~~~~~~~~~^
        statement,
        ^^^^^^^^^^
    ...<4 lines>...
        _add_event=_add_event,
        ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2247, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,
        ^^^^^
    ...<4 lines>...
        conn,
        ^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/bulk_persistence.py", line 1627, in orm_execute_statement
    result = _bulk_update(
        mapper,
    ...<8 lines>...
        enable_check_rowcount=enable_check_rowcount,
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/bulk_persistence.py", line 357, in _bulk_update
    persistence._emit_update_statements(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        base_mapper,
        ^^^^^^^^^^^^
    ...<6 lines>...
        enable_check_rowcount=enable_check_rowcount,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/persistence.py", line 948, in _emit_update_statements
    raise orm_exc.StaleDataError(
    ...<3 lines>...
    )
sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'states' expected to update 7 row(s); 6 were matched.

This all resolved after restarting HA – and there doesn’t seem to be any (permanent) database corruption.

However, I don’t know what triggered the problem and why this failure was silent.

Any idea what caused these failures of the recorder component?
Has anyone else experienced this???

strong text

Delayed commit on the databases, heavy database action or maybe even a failed database commit that needed to be rolled back, could be causes.

Delayed commit on the databases, heavy database action or maybe even a failed database commit that needed to be rolled back, could be causes.

Unlikely to be the first two as:

  1. There was no new data for about 8 hours (!) and no special load on the system
  2. After restarting ha core still gap of 8 hours of no data.
  3. Log shows thousands of errors

So could be #3 or some bug/error in the code…
Just was hoping someone could figure it out from the log error messages :frowning:

Thanks!

I am also running into the same issue, did you find any solutions for this yet? I need to keep restarting my HA

SQLAlchemyError error processing task CommitTask()
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 894, in _process_one_task_or_event_or_recover
  File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 295, in run
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1193, in _commit_event_session_or_retry
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1219, in _commit_event_session
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2362, in execute
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2237, in _execute_internal
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2106, in _connection_for_bind
  File "<string>", line 2, in _connection_for_bind
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/state_changes.py", line 103, in _go
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 996, in _raise_for_prerequisite_state
sqlalchemy.exc.InvalidRequestError: This session is in 'prepared' state; no further SQL can be emitted within this transaction.

Nope… it hasn’t recurred since then…