fix: enable stateless_http in add-on and fix runtime Python version - #626
Conversation
Enable stateless_http=True in the add-on's mcp.run() call, aligning it with all other HTTP deployment modes (main_web, main_sse, main_oauth). The add-on was missed when stateless mode was introduced in v6.4.0. Without stateless mode, mcp-proxy connections require consistent Mcp-Session-Id header forwarding. If the proxy fails to maintain session state, the server either creates orphaned sessions (stale data) or rejects requests silently — matching the symptoms in homeassistant-ai#585. Also fix the runtime Docker image from Python 3.14 to 3.13 to match the builder stage, which was causing ModuleNotFoundError for ha_mcp due to mismatched site-packages paths (python3.13 vs python3.14). Fixes homeassistant-ai#585
Summary of ChangesHello @sergeykad, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses two critical bug fixes for the Home Assistant add-on, enhancing its stability and reliability. It resolves session management inconsistencies by enabling stateless HTTP, and corrects a Python version mismatch in the Docker build process, which was causing module import errors and test failures. These changes ensure the add-on operates as expected and passes all relevant automated tests. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request delivers two key fixes for the Home Assistant add-on. It corrects the Python version in the Dockerfile to match the builder stage, resolving ModuleNotFoundError issues. It also enables stateless HTTP mode in start.py, which fixes session handling bugs and aligns the add-on with the project's stateless architecture. The changes are clear, correct, and well-justified. Great work!
Renovate PR homeassistant-ai#598 bumped the runtime image to Python 3.14 but left the builder stage on Python 3.13. This causes ModuleNotFoundError because the venv site-packages are under python3.13/ while the 3.14 runtime looks under python3.14/. Revert all three Dockerfiles to matching 3.13.
kingpanther13
left a comment
There was a problem hiding this comment.
Review: Approve
Thoroughly verified both fixes against the upstream codebase. This PR is correct, minimal, and well-motivated.
Fix 1: stateless_http=True in start.py
Verified correct. The add-on's start.py calls mcp.run() directly, bypassing _http_run_kwargs() in __main__.py (line 254-264) which already includes stateless_http=True for all other HTTP modes (main_web, main_sse, main_oauth). This was introduced in PR #495 and the add-on was missed.
Without stateless mode, mcp-proxy must consistently forward Mcp-Session-Id headers. If it doesn't, the server creates orphaned sessions or silently rejects requests — matching exactly the symptoms in #585 (stale reads, silent write failures).
Fix 2: Runtime Python 3.14 → 3.13
Verified correct. PR #598 (Renovate bot) bumped the runtime FROM python:3.13-slim-bookworm → python:3.14-slim-bookworm in all three Dockerfiles, but the builder stages remain on ghcr.io/astral-sh/uv:0.9.30-python3.13-bookworm-slim. The venv's site-packages lives under python3.13/ but a Python 3.14 runtime looks under python3.14/, causing ModuleNotFoundError: No module named 'ha_mcp'.
All three Dockerfiles (Dockerfile, homeassistant-addon/Dockerfile, homeassistant-addon-dev/Dockerfile) are correctly reverted.
CI
All checks green: Docker & Add-on Validation, E2E (x86 + ARM), Unit Tests, Ruff Lint.
Non-blocking observation
The Renovate dockerfile manager bumped the runtime Python image independently of the builder (which uses a different base image from ghcr.io/astral-sh/uv). Consider either:
- Adding a
packageRulesgroup to pin the runtime Python to match the builder, or - Adding a CI check that validates builder/runtime Python version consistency
This is a separate concern and shouldn't block this PR.
What does this PR do?
Two fixes for the Home Assistant add-on:
Enable
stateless_http=Trueinstart.py— The add-on was the only HTTP deployment mode missing this parameter, which was introduced in v6.4.0 (PR feat: enable stateless_http mode for restart resilience #495) for all other modes (main_web,main_sse,main_oauth). Without it, the server runs in stateful session mode, requiringmcp-proxytocorrectly forward
Mcp-Session-Idheaders on every request. If the proxy doesn't maintain session state consistently, the server either creates orphaned sessions (returning stale data) or silently rejects requests — matching the symptoms reported in mcp-proxy connection returns stale data, writes fail silently #585.Fix runtime Docker image Python version — The runtime stage used Python 3.14 while the builder stage uses Python 3.13, causing
ModuleNotFoundError: No module named 'ha_mcp'because the venv'ssite-packageslives underpython3.13/but the runtime Python looks underpython3.14/. This alsocaused the
test_addon_startup_logse2e test to always fail.Type of change
Testing
uv run pytest)uv run ruff check)All 3 add-on e2e tests now pass (previously
test_addon_startup_logsalways failed due to the Python version mismatch):Checklist
Fixes #585