Show updater failures and restore Software error details

This commit is contained in:
firestar5683
2026-11-18 09:13:51 -06:00
parent 7e37c44d40
commit 070bc1fdf8
5 changed files with 87 additions and 6 deletions
@@ -232,11 +232,17 @@ class SoftwareLayout(Widget):
ui_state.params.put_bool(AUTOMATIC_DOWNLOADS, enabled, block=True)
def _on_error_log(self):
try:
text = Path("/data/error_logs/error.txt").read_text(encoding="utf-8", errors="replace")
except OSError:
text = tr("No error log found.")
gui_app.push_widget(ConfirmDialog(text, tr("OK"), cancel_text="", rich=True))
error = ui_state.params.get("LastUpdateException") or ""
if isinstance(error, bytes):
error = error.decode("utf-8", "replace")
if error:
text = error[:4096]
else:
try:
text = Path("/data/error_logs/error.txt").read_text(encoding="utf-8", errors="replace")
except OSError:
text = tr("No error log found.")
gui_app.push_widget(ConfirmDialog(text, tr("OK"), cancel_text="", rich=not bool(error)))
def _on_install_update(self):
if not ui_state.is_offroad() or not ui_state.params.get_bool("UpdateAvailable"):
+4 -1
View File
@@ -867,9 +867,12 @@ class RuntimeSnapshotAdapter:
available = _flag(params, "UpdaterFetchAvailable")
status = "updater status unavailable" if not updater_state else updater_state if updater_state != "idle" else (
"update available" if available else "up to date, last checked " + ("previously" if _text(params, "LastUpdateTime") else "never"))
if updater_state == "idle" and _text(params, "UpdateFailedCount", "0") not in ("", "0"):
error = _text(params, "LastUpdateException", "Updater reported a failure")[:4096]
status = "Update failed: " + " ".join(error.split())
software_actions: set[SoftwareRequest] = set()
if confirmed_offroad:
software_actions.add(SoftwareRequest.OPEN_UNINSTALL_CONFIRMATION)
software_actions.update((SoftwareRequest.OPEN_UNINSTALL_CONFIRMATION, SoftwareRequest.OPEN_ERROR_LOG))
if updater_state == "idle":
software_actions.update((SoftwareRequest.FAST_UPDATE, SoftwareRequest.ROLLBACK))
software_actions.add(SoftwareRequest.DOWNLOAD_UPDATE if available else SoftwareRequest.CHECK_FOR_UPDATES)
@@ -28,6 +28,8 @@ def deliver_software(self: Any, request: SoftwareAction, *, shell_mode, destinat
owner._on_select_branch(self._confirmed_offroad)
elif request.request == software_request.OPEN_UNINSTALL_CONFIRMATION:
owner._on_uninstall(self._confirmed_offroad)
elif request.request == software_request.OPEN_ERROR_LOG:
owner._on_error_log()
else:
return False
return True
@@ -582,6 +582,25 @@ class TestRuntimeSnapshot(unittest.TestCase):
self.assertEqual(state.personality, 2)
self.assertEqual(reads.count('LongitudinalPersonality'), 1)
def test_updater_failure_is_visible_bounded_and_clears_after_success(self):
ui = ui_fake()
ui.params.values.update(UpdaterState="idle", UpdateFailedCount=1,
LastUpdateException="AGNOS hash mismatch\n" + "x" * 5000)
adapter = RuntimeSnapshotAdapter(ui)
failed = adapter.build(ShellMode.SETTINGS, now_ns=NOW).software
self.assertTrue(failed.download_status.startswith("Update failed: AGNOS hash mismatch "))
self.assertLessEqual(len(failed.download_status), 4111)
ui.params.values["UpdaterState"] = "downloading..."
self.assertEqual(adapter.build(ShellMode.SETTINGS, now_ns=NOW+1).software.download_status, "downloading...")
ui.params.values.update(UpdaterState="idle", UpdateFailedCount=0)
self.assertNotIn("hash mismatch", adapter.build(ShellMode.SETTINGS, now_ns=NOW+2).software.download_status)
def test_updater_missing_exception_retains_failure(self):
ui = ui_fake()
ui.params.values.update(UpdaterState="idle", UpdateFailedCount="2")
snapshot = RuntimeSnapshotAdapter(ui).build(ShellMode.SETTINGS, now_ns=NOW).software
self.assertEqual(snapshot.download_status, "Update failed: Updater reported a failure")
def test_onroad_ancillary_reads_are_bounded_and_settings_refreshes_immediately(self):
ui = ui_fake()
ui.params.values['UpdaterState'] = 'idle'
@@ -1123,6 +1142,14 @@ class TestParkedClockDomains(unittest.TestCase):
self.assertEqual(current, self.adapter.build(ShellMode.SETTINGS, now_ns=self.mono).device.offroad)
return current
def test_updater_error_log_requires_fresh_offroad_state(self):
from openpilot.starpilot.ui.software_state import SoftwareRequest
self.assertIn(SoftwareRequest.OPEN_ERROR_LOG,
self.adapter.build(ShellMode.SETTINGS, now_ns=self.mono).software.available_actions)
self.ui.sm.valid["deviceState"] = False
self.assertNotIn(SoftwareRequest.OPEN_ERROR_LOG,
self.adapter.build(ShellMode.SETTINGS, now_ns=self.mono).software.available_actions)
def test_authority_check_does_not_read_preferences_or_change_display_mode(self):
self.adapter._last_mode = ShellMode.ONROAD
with patch.object(self.ui.params, 'get', side_effect=AssertionError('unexpected preference read')), \
@@ -0,0 +1,43 @@
from types import SimpleNamespace as NS
from unittest.mock import Mock, patch
import pytest
from openpilot.starpilot.ui.runtime_software import deliver_software
from openpilot.starpilot.ui.software_state import SoftwareAction, SoftwareRequest, DownloadLabel
from openpilot.starpilot.ui.settings_state import Destination
from openpilot.starpilot.ui.shell import ShellMode
@pytest.mark.parametrize("allowed", [False, True])
def test_error_log_request_uses_fresh_permission(allowed):
owner = Mock()
software = NS(available_actions={SoftwareRequest.OPEN_ERROR_LOG} if allowed else set())
shell = NS(star=NS(adapter=NS(build=lambda *a, **k: NS(software=software))), _panel_owner=lambda panel: owner)
assert deliver_software(shell, SoftwareAction(SoftwareRequest.OPEN_ERROR_LOG), shell_mode=ShellMode,
destination=Destination, clock=NS(monotonic_ns=lambda: 1),
software_request=SoftwareRequest, download_label=DownloadLabel) is allowed
assert owner._on_error_log.call_count == int(allowed)
@pytest.mark.parametrize("error", ["AGNOS <hash> mismatch\n" + "x" * 5000, b"AGN\xffOS failure"], ids=["long-text", "invalid-utf8"])
def test_native_error_log_prefers_bounded_plain_updater_error(error):
from openpilot.selfdrive.ui.layouts.settings import software
expected = error.decode("utf-8", "replace") if isinstance(error, bytes) else error
with (patch.object(software, "ui_state", NS(params=NS(get=lambda key: error))),
patch.object(software, "gui_app") as app, patch.object(software, "ConfirmDialog") as dialog,
patch.object(software.Path, "read_text", side_effect=AssertionError("must not read crash log"))):
software.SoftwareLayout._on_error_log(None)
assert dialog.call_args.args[0] == expected[:4096]
assert dialog.call_args.kwargs["rich"] is False
app.push_widget.assert_called_once()
def test_native_error_log_preserves_crash_log_fallback():
from openpilot.selfdrive.ui.layouts.settings import software
with (patch.object(software, "ui_state", NS(params=NS(get=lambda key: None))),
patch.object(software, "gui_app"), patch.object(software, "ConfirmDialog") as dialog,
patch.object(software.Path, "read_text", return_value="Existing crash log")):
software.SoftwareLayout._on_error_log(None)
assert dialog.call_args.args[0] == "Existing crash log"
assert dialog.call_args.kwargs["rich"] is True