Trust the build check over needrestart when it's conclusive

needrestart run unprivileged (the agent's DynamicUser) can't read
Ubuntu's root-only /boot images and reported a false ABI-compatible
upgrade (KSTA=2) on a 24.04 HWE host whose running build matched its
installed package. When the uname -v / package-version comparison is
conclusive, decide from it plus the newest-installed comparison and
ignore needrestart; fall back to needrestart only for unrecognised
build formats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 11:31:28 -04:00
1 parent 818a2e7a1c
commit a430a13fc8
2 files changed
+37 -11

No files matched your search

+17 -11
View File
@@ -47,29 +47,36 @@ _UBUNTU_BUILD = re.compile(r"^#(\S+)-Ubuntu\b")
_UBUNTU_PKG = re.compile(r"^\d+\.\d+\.\d+-\d+\.(\S+)$")
def running_build_outdated(report: dict[str, Any]) -> tuple[str, str] | None:
"""(running build, installed package version) if the running kernel's package was
upgraded in place since boot (same `uname -r`, new build), else None.
def running_build(report: dict[str, Any]) -> tuple[str, str] | None:
"""(build of the running kernel, installed package version of that kernel), in
comparable form, or None if we can't tell (e.g. an unrecognised build string).
None also means "can't tell", e.g. an unrecognised build string."""
If they differ, the package was upgraded in place since boot (same `uname -r`)."""
build = report.get("kernel_build") or ""
pkg = report.get("kernel_running_pkg_version")
if not pkg:
return None
if m := _DEBIAN_BUILD.search(build):
running = m.group(1)
return (running, pkg) if running != pkg else None
return m.group(1), pkg
if (m := _UBUNTU_BUILD.match(build)) and (p := _UBUNTU_PKG.match(pkg)):
return (m.group(1), p.group(1)) if m.group(1) != p.group(1) else None
return m.group(1), p.group(1)
return None
def kernel_reboot_pending(report: dict[str, Any]) -> str | None:
"""Why the running kernel is out of date, or None if it isn't (as far as we can tell)."""
running = report.get("kernel_running") or "?"
if outdated := running_build_outdated(report):
built, installed = outdated
return f"running {running} build {built}, package upgraded in place to {installed}"
newest = report.get("kernel_newest_installed")
if build := running_build(report):
built, installed = build
if built != installed:
return f"running {running} build {built}, package upgraded in place to {installed}"
# Conclusive, so skip needrestart: run unprivileged it can't read Ubuntu's
# root-only /boot images and reports false ABI upgrades.
if newest and newest != running:
return f"running {running}, {newest} installed"
return None
ksta = report.get("needrestart_ksta")
if ksta == KSTA_VERSION_UPGRADE:
@@ -81,7 +88,6 @@ def kernel_reboot_pending(report: dict[str, Any]) -> str | None:
return None
# No usable needrestart result: compare against the newest installed image.
newest = report.get("kernel_newest_installed")
if newest and newest != running:
return f"running {running}, {newest} installed"
return None