Report a failed apt simulation instead of reading it as "no updates"
CI / tests (Python 3.10) (pull_request) Successful in 26s
CI / tests (Python 3.11) (pull_request) Successful in 25s
CI / tests (Python 3.12) (pull_request) Successful in 25s
CI / tests (Python 3.13) (pull_request) Successful in 25s
CI / lint (pull_request) Failing after 3s

The agent ran `apt-get -s dist-upgrade 2>/dev/null || true`, so when apt
failed (unmet dependencies, a broken sources entry, a damaged package cache)
the empty output counted as zero updates and the host could show ok while
nothing could be installed. The agent now keeps apt's exit status and stderr,
reports apt_simulation_ok and the first "E:" line as apt_simulation_error,
and sends the update counts as null. The server puts such a host in update
with "apt can't work out pending updates: ...", and the host page shows the
result. Agents before 0.5.0 don't send the field and are judged as before.

Also show "–" rather than "None" for an unknown count in a host's history,
and stop hard-coding the agent version in the status CLI tests. Agent 0.5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-30 23:22:24 -04:00
1 parent 1350c78676
commit 6d29197cfc
10 files changed
+100 -15

No files matched your search

+1 -1
View File
@@ -4,4 +4,4 @@ __version__ = "0.4.0"
# Version of agent/kernelwatch-agent shipped alongside this server; older agents
# are noted on the dashboard. tests/test_status.py checks the two stay in sync.
AGENT_VERSION = "0.4.1"
AGENT_VERSION = "0.5.0"
+2
View File
@@ -40,6 +40,8 @@ FIELDS: dict[str, str] = {
"livepatch_supported": "str",
"livepatch_upgrade_required": "str",
"livepatch_fix_count": "int",
"apt_simulation_ok": "bool",
"apt_simulation_error": "str",
"apt_lists_age_seconds": "int",
"uptime_seconds": "int",
}
+5
View File
@@ -198,6 +198,11 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
if livepatch_note and not covered:
status.note(livepatch_note)
# An agent whose apt simulation failed sends no update counts, so "no security
# updates" would be a guess. Agents before 0.5.0 don't send the field.
if report.get("apt_simulation_ok") is False:
why = report.get("apt_simulation_error") or "no error message"
status.raise_to("update", f"apt can't work out pending updates: {why}")
if kernels := report.get("kernel_upgradable"):
status.raise_to("update", f"kernel update available: {', '.join(kernels)}")
if sec := report.get("security_count"):
+3 -1
View File
@@ -502,6 +502,8 @@ class Handler(BaseHTTPRequestHandler):
field("Kernel packages upgradable", r.get("kernel_upgradable"), code=True),
field("Updates pending", r.get("upgradable_count")),
field("Security updates", r.get("security_count")),
field("apt simulation", None if r.get("apt_simulation_ok") is None else
"ok" if r["apt_simulation_ok"] else f"failed: {r.get('apt_simulation_error') or '?'}"),
field("Deferred by phasing", r.get("phased_packages"), code=True),
field("Reboot-required packages", r.get("reboot_required_pkgs"), code=True),
field("Services needing restart", services_summary(r)[1]),
@@ -518,7 +520,7 @@ class Handler(BaseHTTPRequestHandler):
f'<td title="{e(utc(h["received_at"]))}">{e(ago(h["received_at"], now))}</td>'
f"<td>{badge(evaluate(h['received_at'], h['report'], h['received_at'], self.cfg).level)}</td>"
f"<td><code>{e(h['report'].get('kernel_running') or '–')}</code></td>"
f"<td>{e(str(h['report'].get('upgradable_count', '–')))}</td>"
f"<td>{e('–' if (n := h['report'].get('upgradable_count')) is None else str(n))}</td>"
"</tr>"
for h in history
)