Skip to content

fix: prevent on_change_domain from wiping saved entity settings when domain matches current_domain - #32

Open
brombomb wants to merge 1 commit into
gensyn:mainfrom
brombomb:prevent-key-wipe
Open

fix: prevent on_change_domain from wiping saved entity settings when domain matches current_domain#32
brombomb wants to merge 1 commit into
gensyn:mainfrom
brombomb:prevent-key-wipe

Conversation

@brombomb

@brombomb brombomb commented Aug 5, 2026

Copy link
Copy Markdown

Real-World Situation & GTK Initialization Lifecycle

The domain wipe occurs due to a race condition between GTK widget initialization and StreamController's signal handling during crash recovery or layout switching:

  1. Widget Realization: When StreamController recovers from a crash or loads a page layout, GTK instantiates the ComboRow dropdown widget.
  2. Signal Firing Before Model Load: During widget creation, ComboRow emits an on_change GTK signal before StreamController populates the saved domain (current_domain) into the widget.
  3. Spurious Reset: The signal passes old_domain = None and domain = "ai_task" (the 0th alphabetical domain). base_core.py evaluates if old_domain != domain: (None != "ai_task"), which evaluates to True and invokes self.settings.reset("ai_task"). This permanently overwrites the saved domain and wipes out entity.

Steps to Reproduce

  1. Configure an action with a domain other than ai_task (e.g., domain: switch, entity: switch.living_room).
  2. Force-close or crash StreamController, or switch active page layouts while StreamController is under memory/CPU load.
  3. Upon re-opening or loading the configuration panel, GTK emits the initial widget realization signal, causing on_change_domain to reset the button's domain to ai_task and clear the configured entity ("").

Environment & System Info

  • OS: Ubuntu 26.04 LTS (Linux 7.0.0-28-generic x86_64)
  • Python Version: 3.14.4
  • StreamController Installation: Flatpak (com.core447.StreamController / stable)
  • HomeAssistantPlugin Version: v1.1.1

Proposed Fix

In base_core.py (on_change_domain), check if the emitted domain matches the domain already saved in self.settings (current_domain):

current_domain = self.settings.get_domain() if self.settings else None

if old_domain != domain and domain != current_domain:
    ...
    self.settings.reset(domain)

If domain == current_domain, on_change_domain preserves the existing entity configuration instead of wiping it out. Adds unit test test_on_change_domain_matches_current_domain in test_base_core_on_change_domain.py.


AI Disclosure

This pull request was diagnosed, developed, and verified with assistance from Google Antigravity (AGY). Antigravity was used to trace GTK widget signal lifecycle events, isolate settings reset triggers, author unit tests, and verify overall code correctness.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant