HASS.Agent-Integration icon indicating copy to clipboard operation
HASS.Agent-Integration copied to clipboard

'hass_agent' calls device_registry.async_update_device from a thread .....

Open ThomasCr opened this issue 1 year ago • 10 comments

I noticed the following error message in the logfiles:

Detected that custom integration 'hass_agent' calls device_registry.async_update_device from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#device_registryasync_update_device at custom_components/hass_agent/init.py, line 29: device_registry.async_get_or_create(. Please report it to the author of the 'hass_agent' custom integration.

2024-10-03 13:23:55.974 ERROR (SyncWorker_12) [homeassistant.util.logging] Exception in updated when handling msg on 'hass.agent/devices/PCT': '{"serial_number":"7705d518-a4f9-4e2d-9b39-eb26d6272e1e","device":{"identifiers":"hass.agent-PCT","manufacturer":"LAB02 Research","model":"Microsoft Windows NT 10.0.19045.0","name":"PCT","sw_version":"2022.14.0"},"apis":{"notifications":true,"media_player":false}}'

    _report_integration(what, integration_frame, level, error_if_integration)

    raise RuntimeError(

RuntimeError: Detected that custom integration 'hass_agent' calls device_registry.async_update_device from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#device_registryasync_update_device at custom_components/hass_agent/__init__.py, line 29: device_registry.async_get_or_create(. Please report it to the author of the 'hass_agent' custom integration.

ThomasCr avatar Oct 03 '24 11:10 ThomasCr

Same issue. This is my complete log

RuntimeError: Detected that custom integration 'hass_agent' calls device_registry.async_update_device from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#device_registryasync_update_device at custom_components/hass_agent/__init__.py, line 29: device_registry.async_get_or_create(. Please report it to the author of the 'hass_agent' custom integration
2024-12-08 01:31:24.995 WARNING (SyncWorker_10) [homeassistant.helpers.frame] Detected that custom integration 'hass_agent' calls device_registry.async_update_device from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#device_registryasync_update_device at custom_components/hass_agent/__init__.py, line 29: device_registry.async_get_or_create(. Please report it to the author of the 'hass_agent' custom integration
2024-12-08 01:31:25.004 ERROR (SyncWorker_10) [homeassistant.util.logging] Exception in updated when handling msg on 'hass.agent/devices/MINI-GALAXY': '{"serial_number":"33975f83-eea1-4485-befc-bc4c9878696b","device":{"identifiers":"hass.agent-MINI-GALAXY","manufacturer":"LAB02 Research","model":"Microsoft Windows NT 10.0.22631.0","name":"MINI-GALAXY","sw_version":"2022.14.0"},"apis":{"notifications":true,"media_player":true}}'
Traceback (most recent call last):
  File "/config/custom_components/hass_agent/__init__.py", line 144, in updated
    update_device_info(hass, entry, payload)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hass_agent/__init__.py", line 29, in update_device_info
    device_registry.async_get_or_create(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        config_entry_id=entry.entry_id,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        sw_version=new_device_info["device"]["sw_version"],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 829, in async_get_or_create
    device = self.async_update_device(
        device.id,
    ...<16 lines>...
        via_device_id=via_device_id,
    )
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 1044, in async_update_device
    self.hass.verify_event_loop_thread("device_registry.async_update_device")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 474, in verify_event_loop_thread
    frame.report_non_thread_safe_operation(what)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 368, in report_non_thread_safe_operation
    report(
    ~~~~~~^
        f"calls {what} from a thread other than the event loop, "
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
        error_if_integration=True,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 164, in report
    report_usage(
    ~~~~~~~~~~~~^
        what,
        ^^^^^
    ...<4 lines>...
        level=level,
        ^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 242, in report_usage
    _report_integration_frame(
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
        what,
        ^^^^^
    ...<3 lines>...
        integration_behavior is ReportBehavior.ERROR,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 340, in _report_integration_frame
    raise RuntimeError(
    ...<5 lines>...
    )

a-maggi avatar Dec 08 '24 04:12 a-maggi

I am having the same issue. 100s of instances of the same error clogging up the HA logs.

devangapatel avatar Dec 11 '24 19:12 devangapatel

Any news?

sammyke007 avatar Dec 13 '24 14:12 sammyke007

Is anyone actively working on this project?

devangapatel avatar Dec 13 '24 14:12 devangapatel

Same problem here HAOS 2024.12.4

itm1960 avatar Dec 24 '24 13:12 itm1960

@devangapatel and @itm1960 switch to this fork, working great! https://github.com/hass-agent/HASS.Agent-Integration

sammyke007 avatar Dec 25 '24 13:12 sammyke007

@devangapatel and @itm1960 switch to this fork, working great! https://github.com/hass-agent/HASS.Agent-Integration

I am confused by this. How do I install the Hass Agent 2 integration? I am trying to follow the instructions and add in a custom repository in HACS (url = https://github.com/hass-agent/HASS.Agent-Integration) but it says it already exists in HACS. This url seems to be for the original HASS agent. What us the url for the custom repo for the HASS Agent 2 integration?

devangapatel avatar Jan 02 '25 17:01 devangapatel

@devangapatel and @itm1960 switch to this fork, working great! https://github.com/hass-agent/HASS.Agent-Integration

I am confused by this. How do I install the Hass Agent 2 integration? I am trying to follow the instructions and add in a custom repository in HACS (url = https://github.com/hass-agent/HASS.Agent-Integration) but it says it already exists in HACS. This url seems to be for the original HASS agent. What us the url for the custom repo for the HASS Agent 2 integration?

https://github.com/hass-agent/HASS.Agent-Integration and https://github.com/hass-agent/HASS.Agent

you need to change both

sammyke007 avatar Jan 02 '25 18:01 sammyke007

Same issue HASS.Agent on PC 2022.14.0 HASS.Agent Integration 2022.11.9

walterpet avatar Jan 20 '25 19:01 walterpet

Same issue

romanad avatar Mar 09 '25 09:03 romanad

I am experiencing the same issue with the latest Home Assistant version.

Home Assistant enters a restart loop on startup when hass_agent is enabled. The same RuntimeError appears:

RuntimeError: Detected that custom integration 'hass_agent' calls device_registry._async_update_device from a thread other than the event loop.
  File "/config/custom_components/hass_agent/__init__.py", line 29, in update_device_info
    device_registry.async_get_or_create(...)

Disabling or removing the integration immediately stops the crashes.

System details: Home Assistant Core: core-2025.12.2 HASS.Agent Integration version: Version 2022.11.9 Installation method: Home Assistant OS

Please confirm whether the integration is still maintained or if a safe workaround exists for newer HA versions.

Thank you.

edleran avatar Dec 10 '25 07:12 edleran