Repository navigation
Make Supervisor startup resilient to transient network failures - #4874
Conversation
|
No actionable comments were generated in the recent review. ๐ โน๏ธ Recent review infoโ๏ธ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ๐ Files selected for processing (1)
๐ง Files skipped from review as they are similar to previous changes (1)
๐ WalkthroughWalkthroughThis PR updates supervisor startup cleanup and version fetching, makes AppArmor profile download atomic, and increases the supervisor unit restart burst limit. ChangesSupervisor hardening
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
๐ฅ Pre-merge checks | โ 5โ Passed checks (5 passed)
โจ Finishing Touches๐งช Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When the Supervisor image is missing and no local updater information is available (e.g. on first boot after a factory reset/data wipe), the start script fetches the current stable version from version.home-assistant.io. This fetch can fail transiently: since #3669 the boot waits at most 15s for time synchronization, so the script may run with an unsynced clock (making TLS validation fail), or before the network is fully functional. Today such a failure makes the script exit within ~400ms (via jq -e exit code 4 under set -e). Combined with RestartSec=5s and StartLimitBurst=3, three quick failures trip the start rate limit within ~15 seconds and the unit stays failed until reboot - even if NTP syncs moments later, leaving the device at the emergency console (as seen in #4863). Make this path more robust: - Let curl retry the version fetch (5 retries, 10s apart). Use --retry-all-errors so DNS/TLS failures are retried as well, not just transient HTTP errors. - Increase the service start rate limit from 3 to 5 attempts per 30 minutes, so a slightly longer network/time-sync hiccup at boot doesn't permanently disable the unit. - Skip "docker image rm" in the startup-marker recovery path when there are no Supervisor images at all, avoiding a spurious usage error. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d0145ce to
2be565b
Compare
The haos-apparmor script only downloads the Supervisor AppArmor profile when the profile directory is missing - but it creates the directory before attempting the download. If the first download fails (e.g. no DNS/network on first boot after a data wipe), every subsequent boot skips the download because the directory exists, and the unit exits successfully without loading any profile. The Supervisor container is then created with --security-opt apparmor=hassio-supervisor and fails to start forever with: apparmor failed to apply profile: write .../attr/apparmor/exec: no such file or directory (observed in #4863 after the reporter fixed their DNS setup). Key the download on the profile file instead of the directory, download to a temporary file that is moved into place only on success, and let curl retry transient failures like in the Supervisor version fetch. Also fail the unit loudly when the download does not succeed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
๐งน Nitpick comments (1)
buildroot-external/rootfs-overlay/usr/libexec/haos-apparmor (1)
17-22: ๐ฉบ Stability & Availability | ๐ต Trivial | โก Quick winConsider capping total retry time with
--retry-max-time.
--max-time 30bounds each individual transfer attempt, not the whole retry sequence โ curl's own documentation notes "The --max-time option still specifies the longest time a single of these transfers is allowed to spend." total retry duration is instead capped via "With --retry-max-time you cap the total time allowed for retries." As written, worst case is roughly(max-time + retry-delay) * (retries + 1)โ 4 minutes if the server is consistently slow/unreachable, which could noticeably delay boot before eventually failing loudly. Adding--retry-max-timewould give an explicit upper bound on total wait time during startup.This mirrors the same curl flag combination introduced in the
haos-supervisorscript for the stable-version fetch, so the same consideration applies there too.โป๏ธ Optional: bound total retry time
- if ! curl -sfL --retry 5 --retry-delay 10 --retry-all-errors --max-time 30 \ + if ! curl -sfL --retry 5 --retry-delay 10 --retry-all-errors --retry-max-time 120 --max-time 30 \ -o "${PROFILES_DIR}/.hassio-supervisor.tmp" "${APPARMOR_URL}"; then๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@buildroot-external/rootfs-overlay/usr/libexec/haos-apparmor` around lines 17 - 22, The curl download in haos-apparmor currently limits only each attempt via the existing timeout, so the total retry window can grow much longer than intended. Update the download command in the AppArmor profile fetch logic to add a total retry cap with retry-max-time alongside the existing retry settings, using the same pattern as the stable-version fetch in haos-supervisor. Keep the current retry and max-time behavior, but ensure the overall startup wait is explicitly bounded.
๐ค Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@buildroot-external/rootfs-overlay/usr/libexec/haos-apparmor`:
- Around line 17-22: The curl download in haos-apparmor currently limits only
each attempt via the existing timeout, so the total retry window can grow much
longer than intended. Update the download command in the AppArmor profile fetch
logic to add a total retry cap with retry-max-time alongside the existing retry
settings, using the same pattern as the stable-version fetch in haos-supervisor.
Keep the current retry and max-time behavior, but ensure the overall startup
wait is explicitly bounded.
โน๏ธ Review info
โ๏ธ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a65ebf10-2555-4958-87d8-89e8b8b4e0e9
๐ Files selected for processing (1)
buildroot-external/rootfs-overlay/usr/libexec/haos-apparmor
There was a problem hiding this comment.
Pull request overview
This PR hardens first-boot recovery paths so transient network/time issues donโt permanently prevent Supervisor startup after a factory reset/data wipe.
Changes:
- Make Supervisor version resolution from
version.home-assistant.ioretryable and less fragile under transient DNS/TLS failures. - Prevent a โpoisonedโ AppArmor state by keying downloads on the actual profile file and downloading atomically with retries + hard failure on download errors.
- Increase
haos-supervisorsystemd start rate-limit tolerance and avoid spuriousdocker image rmusage errors when no images match.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| buildroot-external/rootfs-overlay/usr/sbin/haos-supervisor | Adds retrying version fetch behavior and guards image cleanup against empty ID lists. |
| buildroot-external/rootfs-overlay/usr/libexec/haos-apparmor | Makes Supervisor AppArmor profile download self-healing, atomic, and fail-fast with retries. |
| buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-supervisor.service | Increases StartLimitBurst to reduce permanent failure during boot-time transient issues. |
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Match the naming convention of the other variables in the script. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
Issue #4863 exposed two independent first-boot fragilities that turn a transient network failure into a permanent one. Both sit on the recovery path after a factory reset / data wipe, where the pre-seeded data partition content is gone and the OS must fetch things from the network on first boot.
1. Supervisor version fetch (permanent until reboot)
When the Supervisor image is missing and no local updater information exists,
haos-supervisorfetches the current stable version fromversion.home-assistant.ioin a single attempt with no error handling: if it fails,jq -eexits with code 4 underset -eand the script dies within ~400ms.RestartSec=5s+StartLimitBurst=3+StartLimitIntervalSec=30mmeans three quick failures trip the start rate limit within ~15 seconds, and the unit then stays failed until reboot โ even if NTP syncs moments later (status=4/NOPERMISSIONร3 โ "Start request repeated too quickly" in the Home Assistant Green recovery leaves system with zero Docker images and Supervisor cannot startย #4863 journal).2. AppArmor profile download (permanent across reboots)
haos-apparmoronly downloads the Supervisor profile when the profile directory is missing โ but it creates the directory before attempting the download. One failed first download (no DNS on first boot after wipe) poisons the state: every subsequent boot skips the download because the directory exists, the unit exits successfully having loaded nothing, and the Supervisor container fails to start forever withapparmor failed to apply profile: write .../attr/apparmor/exec: no such file or directoryโ exactly what the #4863 reporter hit after fixing their DNS.Changes
haos-supervisor: let curl retry the version fetch itself:--retry 5 --retry-delay 10 --retry-all-errors --max-time 30.--retry-all-errorsis needed so DNS and TLS failures (the unsynced-clock case) are retried too, not just transient HTTP errors.haos-supervisor.service: increase the start rate limit from 3 to 5 attempts per 30 minutes. The rate limit stays in place to avoid hammering the update infrastructure, but a slightly longer network/time-sync hiccup at boot no longer permanently disables the unit.haos-supervisor: guard thedocker image rmin the startup-marker recovery path against an empty image list, which currently logs a spuriousdocker: 'docker image rm' requires at least 1 argumentusage error.haos-apparmor: key the profile download on the profile file instead of the directory (self-healing on the next boot), download to a temporary file moved into place only on success, add-fand the same curl retry flags, and fail the unit loudly when the download does not succeed.Testing
sh -nand shellcheck pass on both scripts.๐ค Generated with Claude Code
Summary by CodeRabbit