Files
supervisor/tests/misc
1a7853de9a Start the Supervisor auto update on every version reload (#7201)
* Start the Supervisor auto update on every version reload

A pending Supervisor update blocks Core, OS and app updates through the SUPERVISOR_UPDATED job condition. Only the startup and the daily scheduled reload started the auto update. Every other reload, such as the one Core requests when the user opens Settings, made the new version known without installing it. The user then saw "supervisor needs to be updated first" until the daily task ran.

The updater now starts the auto update task after every reload while the system is running. The scheduled task calls the updater reload directly. The Supervisor update job rejects a concurrent update request, so a user requested update during the auto update fails cleanly instead of creating an update failed issue.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAWqYzDiFEvYjZwfBWoxkC

* Report success for an update request during a running Supervisor update

The auto update can already run when Core or a user requests the update. The requested outcome is underway, so the API reports success and the caller sees the result through the Supervisor restart.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAWqYzDiFEvYjZwfBWoxkC

* Trim comments around the Supervisor auto update

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAWqYzDiFEvYjZwfBWoxkC

* Drop comment on the updater auto update trigger

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SAWqYzDiFEvYjZwfBWoxkC

* Raise specific errors when restoring a backup requires a Supervisor update

Move the supervisor version check in do_restore_full/do_restore_partial into
a shared _check_supervisor_version helper. If the backup requires a newer
Supervisor version:
- Raise the new translatable BackupSupervisorVersionError (400) with the
  existing message when auto update is disabled.
- Otherwise kick off the Supervisor auto update in the background via
  sys_create_task(auto_update_supervisor()) and raise the new translatable
  BackupSupervisorUpdateInProgressError (503), telling the caller to retry
  once the update completes.

* Recheck for Supervisor update before failing a version-mismatch restore

When a restore requires a newer Supervisor version and auto update is
enabled, refresh version info first in case a newer Supervisor was just
released. If an update is already known to be needed, make sure it gets
kicked off directly instead of waiting on a reload. Only fall back to
the translatable version-mismatch error if no update is available after
the recheck.

Also move auto_update_supervisor from Tasks to the Supervisor class so
it can be reused outside of the task scheduler.

* Track auto update and version fetch tasks to close restore-check races

Supervisor.auto_update_supervisor() now stores and returns its update
task (created with eager_start so a synchronous failure is reflected
immediately) instead of firing-and-forgetting it. This lets callers
check the task's actual done state rather than guessing based on
need_update, which could be wrong if the update job rejected the call
for an unrelated reason.

HomeAssistantCore's install retry loop now also catches
SupervisorJobError when triggering the Supervisor update it depends on,
so it keeps retrying while an update is already in progress instead of
giving up.

Add Updater.start_fetch_data(), which starts (or reuses) a version
fetch and returns its task. fetch_data() sets its throttle timestamp
before running, even on failure, so a caller relying on fetch_data()
directly can't tell "someone else just refreshed" from "someone else's
fetch just failed" - it would silently skip either way. Callers that
need to know the true outcome should await the shared task instead.
reload() and BackupManager._check_supervisor_version() are updated to
use it: the latter awaits the fetch task directly (skipping it entirely
if there's no connectivity to fetch with) before checking
auto_update_supervisor()'s task, closing a race where a stale/failed
throttle window could cause a 400 (version mismatch) response instead
of a 503 (update in progress).

* Use Job decorator's detach option for update and version fetch tasks

#7211 added a `detach` option to the Job decorator, making the manual
task-tracking previously added here redundant. Replace it with the
decorator-native option:

- `Supervisor.update()` is now `detach=True` with
  `concurrency=JobConcurrency.REJECT`. Calling it returns the task
  performing the update - which may already be in progress from any
  previous caller, manual or automatic - instead of raising
  `SupervisorJobError` or blocking the caller until it (and the
  Supervisor restart it triggers) completes. Errors are raised on the
  returned task, not to the immediate caller.
- `Supervisor.auto_update_supervisor()` is now a thin, non-detached
  method that simply returns `update()`'s own task directly instead of
  tracking a separate task itself. This ensures a concurrent manual
  update and an auto update share the exact same underlying task
  regardless of which caller started it. It never awaits the task to
  completion, since update() restarts Supervisor and awaiting that here
  could drop the caller's connection before a response is sent.
- `Updater.fetch_data()` is now `detach=True` with
  `concurrency=JobConcurrency.REJECT`, replacing the bespoke
  `start_fetch_data()`/`_fetch_task` tracking. `reload()` and
  `BackupManager._check_supervisor_version()` await the returned task
  directly to get the real outcome of a fetch instead of relying on the
  throttle window.
- The Supervisor update API endpoint and the Home Assistant Core
  install retry loop now use `if task := await ...: await task` instead
  of catching `SupervisorJobError`, since a concurrent call no longer
  raises that error - it returns the shared in-progress task instead.

Updated tests across supervisor.py, updater.py, the API and Home
Assistant Core install retry loop to match the new return values and
removed now-obsolete `SupervisorJobError`-based concurrency tests.

* Fix too-many-nested-blocks pylint warning in HomeAssistantCore.install()

Flatten the nested need_update/auto_update if/else into an if/elif so
the Supervisor update retry try/except isn't nested one level deeper,
which pylint 4.0.8 (unlike the previously installed version in this
container) now flags as too-many-nested-blocks (6/5). Cache
need_update in a local variable since it's now referenced twice in the
same iteration and must be consistent between both checks.

* Update supervisor/api/supervisor.py

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
Co-authored-by: Stefan Agner <stefan@agner.ch>
2026-09-14 15:56:21 +02:00
..