You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: tolerate setuptools editable-finder KeyError on Python 3.14 bring-up (#1989)
On Python 3.14 with `homeassistant` installed as a setuptools editable package
(official HA container image / HA OS), CPython's `PathFinder.invalidate_caches()`
raises `KeyError` at its `del sys.path_importer_cache[name]` line — the synthetic
`__editable__.<dist>.finder.__path_hook__` placeholder is not an absolute path,
so CPython takes the `del` branch on a key an earlier iteration already removed
(a CPython bug; should be a `pop`). That aborts `importlib.invalidate_caches()`
and crashes `_installed_ha_mcp_version()` on the `async_start()` bring-up path,
so the in-process server never comes up and every tool fails (#1891, #1985).
Deterministic on Python 3.14; invisible on 3.13 / non-editable installs.
The four `importlib.invalidate_caches()` call sites route through
`_safe_invalidate_caches()`: on that `KeyError` it prunes the stale dead/relative
`sys.path_importer_cache` entries with `pop` (the offending placeholder among
them), then re-runs `importlib.invalidate_caches()` so CPython completes its full
sweep — path-entry finders, namespace-path epoch, and metadata. The retry is
guarded (a second KeyError from a concurrent re-add is tolerated, best-effort,
never re-crashes bring-up); recovery is logged at WARNING for diagnosis. The
broad `except KeyError` is deliberate — the same CPython bug also fires via the
`finder is None` branch with an absolute-path key, so narrowing by key would
re-raise that variant.
Covered by unit tests (`TestSafeInvalidateCaches`) and an in-container e2e probe
that injects the exact KeyError against the real component in a live HA
container. Rides under the pending 1.2.3 component version.
Closes#1985.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments