LAB02-Research / HASS.Agent

Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
https://hassagent.lab02-research.org
MIT License
1.56k stars 68 forks source link

Bug: HASS.Agent POTENTIALLY Causing Fatal HA Crash. #424

Open Anon666333 opened 1 week ago

Anon666333 commented 1 week ago

Describe the bug I want to start off with saying I do not use HASS Agent for media player requests, as this is an open bug. I'm only syncing sensors from my PC to HA, and have a couple quick action scripts mapped to macro keys, Sensors that are syncing:

To Reproduce I'm honestly not sure, and this is what's frustrating. There is no consistency, other than the same errors showing up in the logs just before HA crashes and restarts. I've been trying to figure out why HA is crashing and the best I have narrowed it down to is these errors, but I can't seem to understand why.

Expected behavior To not crash HA.

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

Additional context HA has been running fine, so has HASS.Agent, however, HA has been restarting unexpectedly, so I've been digging through the logs to figure out why this would be happening. I've come to the conclusion, after weeding out other options, that HASS.Agent may be the culprit, though I'm not entirely sure.

Logs Home assistant log:

2024-09-17 16:30:21.533 WARNING (SyncWorker_24) [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-09-17 16:30:21.556 ERROR (SyncWorker_24) [homeassistant.util.logging] Exception in updated when handling msg on 'hass.agent/devices/GHOST': '{"serial_number":"xxxxxxxxxxxxxxxxxxxx","device":{"identifiers":"hass.agent-GHOST","manufacturer":"LAB02 Research","model":"Microsoft Windows NT 10.0.19045.0","name":"GHOST","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(
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 834, in async_get_or_create
    device = self.async_update_device(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 1066, in async_update_device
    self.hass.verify_event_loop_thread("device_registry.async_update_device")
  File "/usr/src/homeassistant/homeassistant/core.py", line 462, in verify_event_loop_thread
    frame.report_non_thread_safe_operation(what)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
    report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_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.

2024-09-17 16:30:51.571 WARNING (SyncWorker_9) [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-09-17 16:30:51.599 ERROR (SyncWorker_9) [homeassistant.util.logging] Exception in updated when handling msg on 'hass.agent/devices/GHOST': '{"serial_number":"xxxxxxxxxxxxxxxxx","device":{"identifiers":"hass.agent-GHOST","manufacturer":"LAB02 Research","model":"Microsoft Windows NT 10.0.19045.0","name":"GHOST","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(
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 834, in async_get_or_create
    device = self.async_update_device(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 1066, in async_update_device
    self.hass.verify_event_loop_thread("device_registry.async_update_device")
  File "/usr/src/homeassistant/homeassistant/core.py", line 462, in verify_event_loop_thread
    frame.report_non_thread_safe_operation(what)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
    report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_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.

HASS.Agent Log (Unfortunately this is all that was there):

2024-09-17 07:29:45.642 -04:00 [INF] [SYSTEMSTATE] Session resuming
2024-09-17 07:29:54.849 -04:00 [WRN] [MQTT] Disconnected: UnspecifiedError
2024-09-17 07:29:54.850 -04:00 [ERR] [MQTT] Error while connecting: Error while connecting with host 'xxx.xxx.xxx.xx:1883'.
2024-09-17 07:29:56.355 -04:00 [FTL] [HASS_API] Error while fetching HA config: A socket operation was attempted to an unreachable network. (xxx.xxx.xxx.xx:8123)
2024-09-17 07:29:59.437 -04:00 [INF] [HASS_API] Server recovered from failed state
2024-09-17 07:29:59.868 -04:00 [INF] [MQTT] Connected
2024-09-17 16:31:49.520 -04:00 [INF] [HASS_API] Server recovered from failed state
2024-09-17 16:31:49.538 -04:00 [WRN] [HASS_API] Server returned 404 (not found) while getting entity state. This can happen after a server reboot, or if you've deleted the entity. If the problem persists, please file a ticket on github.
Entity: switch.coffee_heater
Error message: Response status code does not indicate success: 404 (Not Found).
2024-09-17 16:31:49.544 -04:00 [WRN] [HASS_API] Server returned 404 (not found) while getting entity state. This can happen after a server reboot, or if you've deleted the entity. If the problem persists, please file a ticket on github.
Entity: scene.office_lights_work_day
Error message: Response status code does not indicate success: 404 (Not Found).
2024-09-17 16:31:49.549 -04:00 [WRN] [HASS_API] Server returned 404 (not found) while getting entity state. This can happen after a server reboot, or if you've deleted the entity. If the problem persists, please file a ticket on github.
Entity: scene.office_lights_weekend
Error message: Response status code does not indicate success: 404 (Not Found).
2024-09-17 16:31:49.555 -04:00 [WRN] [HASS_API] Server returned 404 (not found) while getting entity state. This can happen after a server reboot, or if you've deleted the entity. If the problem persists, please file a ticket on github.
Entity: inputboolean.kill_switch_office_lights
Error message: Response status code does not indicate success: 404 (Not Found).
2024-09-17 16:31:49.560 -04:00 [WRN] [HASS_API] Server returned 404 (not found) while getting entity state. This can happen after a server reboot, or if you've deleted the entity. If the problem persists, please file a ticket on github.
Entity: script.matt_ai_calendar_events
Error message: Response status code does not indicate success: 404 (Not Found).
2024-09-17 17:29:04.337 -04:00 [INF] [SETTINGS] Configuration stored
2024-09-17 17:29:07.750 -04:00 [INF] [SYSTEM] Application shutting down
2024-09-17 17:29:07.756 -04:00 [INF] [MQTT] Disconnected
2024-09-17 17:29:07.826 -04:00 [INF] [SYSTEM] Application shutdown complete

There were no logs for this timeframe for the Satellite Service, however, this is from a previous day which follows the same pattern.

2024-09-16 06:56:47.085 -04:00 [INF] [MAIN] Version: 2022.20.0.0
2024-09-16 06:56:47.164 -04:00 [INF] [MAIN] Service started, initializing ..
2024-09-16 06:56:47.528 -04:00 [INF] [MAIN] Running as a service, initializing lifetime manager
2024-09-16 06:56:47.625 -04:00 [INF] [LIFETIMEMANAGER] Initialized
2024-09-16 06:56:47.801 -04:00 [INF] [WORKER] Startup completed, commencing execution ..
2024-09-16 06:56:47.804 -04:00 [INF] [SETTINGS] Config storage path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\config
2024-09-16 06:56:48.205 -04:00 [INF] [SETTINGS] Configuration loaded
2024-09-16 06:56:48.214 -04:00 [INF] [SETTINGS] MQTT configuration loaded
2024-09-16 06:56:48.215 -04:00 [INF] [SETTINGS_COMMANDS] Config not found, no entities loaded
2024-09-16 06:56:48.217 -04:00 [INF] [SETTINGS_SENSORS] Config not found, no entities loaded
2024-09-16 06:56:48.231 -04:00 [INF] [MQTT] Identifying as device: GHOST-satellite
2024-09-16 06:56:48.251 -04:00 [INF] Application started. Hosting environment: Production; Content root path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2024-09-16 06:56:48.316 -04:00 [INF] [MQTT] Connecting ..
2024-09-16 06:56:48.357 -04:00 [INF] [RPCMANAGER] Listening
2024-09-16 06:56:48.533 -04:00 [INF] [MQTT] Connected
2024-09-16 06:56:50.344 -04:00 [INF] [MQTT] Initial registration completed
2024-09-16 10:31:23.308 -04:00 [WRN] [MQTT] Disconnected: NormalDisconnection
2024-09-16 10:31:34.074 -04:00 [FTL] [MQTT] Error while connecting: Error while authenticating. Exception of type 'MQTTnet.Exceptions.MqttCommunicationTimedOutException' was thrown.
MQTTnet.Adapter.MqttConnectingFailedException: Error while authenticating. Exception of type 'MQTTnet.Exceptions.MqttCommunicationTimedOutException' was thrown.
 ---> MQTTnet.Exceptions.MqttCommunicationTimedOutException: Exception of type 'MQTTnet.Exceptions.MqttCommunicationTimedOutException' was thrown.
   at MQTTnet.PacketDispatcher.MqttPacketAwaitable`1.WaitOneAsync(TimeSpan timeout)
   at MQTTnet.Client.MqttClient.SendAndReceiveAsync[TResponsePacket](MqttBasePacket requestPacket, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MQTTnet.Client.MqttClient.AuthenticateAsync(IMqttChannelAdapter channelAdapter, MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync(CancellationToken cancellationToken)
2024-09-16 10:32:52.077 -04:00 [INF] [MQTT] Connected
2024-09-16 10:32:56.257 -04:00 [WRN] [MQTT] Disconnected: UnspecifiedError
2024-09-16 10:32:56.257 -04:00 [FTL] [MQTT] Error while connecting: Error while connecting with host 'xxx.xxx.xxx.xx:1883'.
MQTTnet.Exceptions.MqttCommunicationException: Error while connecting with host 'xxx.xxx.xxx.xx:1883'.
 ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync(CancellationToken cancellationToken)
   at MQTTnet.Internal.MqttTaskTimeout.WaitAsync(Func`2 action, TimeSpan timeout, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync(CancellationToken cancellationToken)
2024-09-16 16:55:12.779 -04:00 [INF] [MAIN] Version: 2022.20.0.0
2024-09-16 16:55:12.816 -04:00 [INF] [MAIN] Service started, initializing ..
2024-09-16 16:55:13.092 -04:00 [INF] [MAIN] Running as a service, initializing lifetime manager
2024-09-16 16:55:13.205 -04:00 [INF] [LIFETIMEMANAGER] Initialized
2024-09-16 16:55:13.560 -04:00 [INF] [WORKER] Startup completed, commencing execution ..
2024-09-16 16:55:13.563 -04:00 [INF] [SETTINGS] Config storage path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\config
2024-09-16 16:55:14.095 -04:00 [INF] [SETTINGS] Configuration loaded
2024-09-16 16:55:14.117 -04:00 [INF] [SETTINGS] MQTT configuration loaded
2024-09-16 16:55:14.118 -04:00 [INF] [SETTINGS_COMMANDS] Config not found, no entities loaded
2024-09-16 16:55:14.120 -04:00 [INF] [SETTINGS_SENSORS] Config not found, no entities loaded
2024-09-16 16:55:14.131 -04:00 [INF] [MQTT] Identifying as device: GHOST-satellite
2024-09-16 16:55:14.156 -04:00 [INF] Application started. Hosting environment: Production; Content root path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2024-09-16 16:55:14.230 -04:00 [INF] [MQTT] Connecting ..
2024-09-16 16:55:14.279 -04:00 [INF] [RPCMANAGER] Listening
2024-09-16 16:55:14.403 -04:00 [INF] [MQTT] Connected
2024-09-16 16:55:16.254 -04:00 [INF] [MQTT] Initial registration completed
2024-09-16 19:05:30.906 -04:00 [INF] [SYSTEMSTATE] Session halting: system suspending
2024-09-16 21:15:31.722 -04:00 [WRN] [MQTT] Disconnected: NormalDisconnection
2024-09-16 21:15:32.279 -04:00 [FTL] [MQTT] Error while connecting: Error while connecting with host 'xxx.xxx.xxx.xx:1883'.
MQTTnet.Exceptions.MqttCommunicationException: Error while connecting with host 'xxx.xxx.xxx.xx:1883'.
 ---> System.Net.Sockets.SocketException (10051): A socket operation was attempted to an unreachable network.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Threading.Tasks.ValueTask.GetTaskForValueTaskSource(IValueTaskSource t)
--- End of stack trace from previous location ---
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync(CancellationToken cancellationToken)
   at MQTTnet.Internal.MqttTaskTimeout.WaitAsync(Func`2 action, TimeSpan timeout, CancellationToken cancellationToken)
   at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync(CancellationToken cancellationToken)
2024-09-16 21:15:37.329 -04:00 [INF] [MQTT] Connected
2024-09-16 21:15:40.891 -04:00 [INF] [SYSTEMSTATE] Session resuming
2024-09-16 23:36:54.390 -04:00 [INF] [SYSTEMSTATE] Session halting: system suspending
7542 commented 1 week ago

same on my installation! HASS.Agent V2.0.1

Logger: homeassistant.util.logging
Quelle: util/logging.py:95
Erstmals aufgetreten: 10:49:50 (31 Vorkommnisse)
Zuletzt protokolliert: 11:04:48

Exception in updated when handling msg on 'hass.agent/devices/AM-DESKTOP': '{"serial_number":"xxxxxxxxxxxxxxxxx","device":{"identifiers":"hass.agent-DESKTOP","manufacturer":"LAB02 Research","model":"Microsoft Windows NT 10.0.19045.0","name":"AM-DESKTOP","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( File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 834, in async_get_or_create device = self.async_update_device( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 1066, in async_update_device self.hass.verify_event_loop_thread("device_registry.async_update_device") File "/usr/src/homeassistant/homeassistant/core.py", line 462, in verify_event_loop_thread frame.report_non_thread_safe_operation(what) File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation report( File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report _report_integration(what, integration_frame, level, error_if_integration) File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_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.