From 9dee2cb5ae1bab90ecb6443ecd444d691c814746 Mon Sep 17 00:00:00 2001 From: Michael Tawata <24485504+mtawata@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:35:21 -0800 Subject: [PATCH] fix agnos download status output --- openpilot/common/hardware/comma/agnos.py | 14 +++++++---- .../tests/test_c3_firmware_compatibility.py | 17 +++++++++++++ openpilot/starpilot/galaxy/software_status.py | 2 +- .../galaxy/tests/test_software_status.mjs | 4 ++++ .../galaxy/web/js/software-status.js | 2 +- .../updated/tests/test_retained_agnos.py | 4 ++-- .../updated/tests/test_vendored_update.py | 24 ++++++++++++++++++- openpilot/system/updated/updated.py | 16 ++++++------- prebuilt.json | 2 +- 9 files changed, 66 insertions(+), 19 deletions(-) diff --git a/openpilot/common/hardware/comma/agnos.py b/openpilot/common/hardware/comma/agnos.py index 2317f0570f..084efa31a4 100755 --- a/openpilot/common/hardware/comma/agnos.py +++ b/openpilot/common/hardware/comma/agnos.py @@ -211,7 +211,7 @@ def clear_partition_hash(target_slot_number: int, partition: dict) -> None: os.sync() -def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog): +def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog, progress=None): path = get_partition_path(target_slot_number, partition) downloader = StreamingDecompressor(partition['url']) @@ -227,6 +227,8 @@ def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog) if p != last_p: last_p = p print(f"Installing {partition['name']}: {p}", flush=True) + if progress is not None: + progress(f"Downloading and writing AGNOS {partition['name']}", p) if raw_hash.hexdigest().lower() != partition['hash_raw'].lower(): raise Exception(f"Raw hash mismatch '{raw_hash.hexdigest().lower()}'") @@ -240,7 +242,7 @@ def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog) os.sync() -def flash_partition(target_slot_number: int, partition: dict, cloudlog, standalone=False): +def flash_partition(target_slot_number: int, partition: dict, cloudlog, standalone=False, progress=None): cloudlog.info(f"Downloading and writing {partition['name']}") if verify_partition(target_slot_number, partition): @@ -254,7 +256,7 @@ def flash_partition(target_slot_number: int, partition: dict, cloudlog, standalo path = get_partition_path(target_slot_number, partition) - extract_compressed_image(target_slot_number, partition, cloudlog) + extract_compressed_image(target_slot_number, partition, cloudlog, progress=progress) # Write hash after successful flash if not full_check: @@ -278,7 +280,7 @@ def swap(manifest_path: str, target_slot_number: int, cloudlog) -> None: cloudlog.error(f"Swap failed {out}") -def flash_agnos_update(manifest_path: str, target_slot_number: int, cloudlog, standalone=False) -> None: +def flash_agnos_update(manifest_path: str, target_slot_number: int, cloudlog, standalone=False, progress=None) -> None: update = load_manifest(manifest_path) cloudlog.info(f"Target slot {target_slot_number}") @@ -291,7 +293,9 @@ def flash_agnos_update(manifest_path: str, target_slot_number: int, cloudlog, st for retries in range(10): try: - flash_partition(target_slot_number, partition, cloudlog, standalone) + if progress is not None: + progress(f"Downloading and verifying AGNOS {partition['name']}", None) + flash_partition(target_slot_number, partition, cloudlog, standalone, progress=progress) success = True break diff --git a/openpilot/common/hardware/comma/tests/test_c3_firmware_compatibility.py b/openpilot/common/hardware/comma/tests/test_c3_firmware_compatibility.py index c02bf756d1..4ecd2205f6 100644 --- a/openpilot/common/hardware/comma/tests/test_c3_firmware_compatibility.py +++ b/openpilot/common/hardware/comma/tests/test_c3_firmware_compatibility.py @@ -181,3 +181,20 @@ def test_explicit_incompatible_manual_manifest_is_not_replaced(tmp_path, release with patch.object(agnos, 'DEVICE_MODEL_PATH', model): with pytest.raises(RuntimeError, match='incompatible with comma 3'): agnos.load_manifest(str(manual)) + + +def test_agnos_download_reports_partition_progress(tmp_path): + import hashlib + + data = b'firmware' + digest = hashlib.sha256(data).hexdigest() + partition = {'name': 'system', 'url': 'https://example.invalid/system.xz', 'size': len(data), 'sparse': False, 'hash': digest, 'hash_raw': digest} + downloader = Mock(sha256=hashlib.sha256(data)) + downloader.read.side_effect = [data[:4], data[4:], b''] + progress = Mock() + with patch.object(agnos, 'get_partition_path', return_value=str(tmp_path / 'partition')), \ + patch.object(agnos, 'StreamingDecompressor', return_value=downloader), patch.object(agnos.os, 'sync'): + agnos.extract_compressed_image(1, partition, Mock(), progress=progress) + assert [call.args for call in progress.call_args_list] == [ + ('Downloading and writing AGNOS system', 50), ('Downloading and writing AGNOS system', 100)] + assert (tmp_path / 'partition').read_bytes() == data diff --git a/openpilot/starpilot/galaxy/software_status.py b/openpilot/starpilot/galaxy/software_status.py index 72bf6ebefa..4de82e6a55 100644 --- a/openpilot/starpilot/galaxy/software_status.py +++ b/openpilot/starpilot/galaxy/software_status.py @@ -27,7 +27,7 @@ def _fast_state(raw): try: value = json.loads(raw) if raw is not None else None if not isinstance(value, dict) or value.get("version") != 1 or value.get("stage") not in ( - "preparing", "fetching", "validating", "applying", "submodules", "rebooting", "complete", "error", "finalizing"): + "preparing", "fetching", "validating", "applying", "agnos", "submodules", "rebooting", "complete", "error", "finalizing"): return None detail = value.get("detail") if not isinstance(detail, str) or len(detail) > 512: diff --git a/openpilot/starpilot/galaxy/tests/test_software_status.mjs b/openpilot/starpilot/galaxy/tests/test_software_status.mjs index 0392bea32f..abe6959694 100644 --- a/openpilot/starpilot/galaxy/tests/test_software_status.mjs +++ b/openpilot/starpilot/galaxy/tests/test_software_status.mjs @@ -814,3 +814,7 @@ let toggleSettings SoftwarePage.methods.configureAutomaticInstalls.call({operations:{restartSchedule:'0 0 * * *',restartTimezone:'UTC'},restartTimezone:'Asia/Tokyo', feed:{configureInstallPreferences:(...args)=>{toggleSettings=args}}},true) assert.deepEqual(toggleSettings,[true,'0 0 * * *','UTC'],'toggle preserves the saved timezone') + +assert.deepEqual(softwareProgress({...updater, state: "downloading..."}, + {progress: {stage: "agnos", detail: "Downloading and writing AGNOS system", percent: 37}}), + {active: true, failed: false, percent: 37, label: "Downloading and installing AGNOS", detail: "Downloading and writing AGNOS system"}) diff --git a/openpilot/starpilot/galaxy/web/js/software-status.js b/openpilot/starpilot/galaxy/web/js/software-status.js index 4cf09ac2d7..e30b4627a6 100644 --- a/openpilot/starpilot/galaxy/web/js/software-status.js +++ b/openpilot/starpilot/galaxy/web/js/software-status.js @@ -70,7 +70,7 @@ export function softwareProgress(updater, operations = {}) { "finalizing update...": "Preparing update", "updating...": "Updating software", checking: "Checking for updates", downloading: "Downloading update", finalizing: "Preparing update", preparing: "Preparing update", fetching: "Downloading update", validating: "Validating update", - applying: "Applying update", submodules: "Preparing dependencies", rebooting: "Restarting device", + agnos: "Downloading and installing AGNOS", applying: "Applying update", submodules: "Preparing dependencies", rebooting: "Restarting device", complete: "Update complete", error: "Update failed", unavailable: "Updater status unavailable", timed_out: "Update is taking longer than expected" } if (!active && (!stage || ["idle", "unknown"].includes(stage))) return null const percent = Number.isFinite(progress?.percent) && progress.percent >= 0 && progress.percent <= 100 ? progress.percent : null diff --git a/openpilot/system/updated/tests/test_retained_agnos.py b/openpilot/system/updated/tests/test_retained_agnos.py index 7813291eee..1043442e62 100644 --- a/openpilot/system/updated/tests/test_retained_agnos.py +++ b/openpilot/system/updated/tests/test_retained_agnos.py @@ -238,7 +238,7 @@ class TestRetainedAgnos(unittest.TestCase): manifest.parent.mkdir(parents=True) manifest.write_text("[]") self.updater.handle_agnos_update() - self.flash.assert_called_once_with(str(self.root / 'openpilot/common/hardware/comma/agnos.json'), 1, self.updater.cloudlog) + self.flash.assert_called_once_with(str(self.root / 'openpilot/common/hardware/comma/agnos.json'), 1, self.updater.cloudlog, progress=None) self.assertTrue((ROOT / 'openpilot/common/hardware/comma/agnos.json').is_file()) self.updater.set_consistent_flag.assert_called_once_with(False) @@ -248,7 +248,7 @@ class TestRetainedAgnos(unittest.TestCase): manifest.parent.mkdir(parents=True) manifest.write_text("[]") self.updater.handle_agnos_update() - self.flash.assert_called_once_with(str(manifest), 1, self.updater.cloudlog) + self.flash.assert_called_once_with(str(manifest), 1, self.updater.cloudlog, progress=None) self.updater.set_consistent_flag.assert_called_once_with(False) def test_invalid_policy_cannot_finalize_or_flash(self): diff --git a/openpilot/system/updated/tests/test_vendored_update.py b/openpilot/system/updated/tests/test_vendored_update.py index f203756a15..ea7bb34510 100644 --- a/openpilot/system/updated/tests/test_vendored_update.py +++ b/openpilot/system/updated/tests/test_vendored_update.py @@ -174,7 +174,7 @@ class TestVendoredUpdate(unittest.TestCase): patch.object(self.updater, "normal_update") as normal: with self.assertRaises(self.updated.FastUpdateIncompatible): self.updater.fast_update(BRANCH, self.initial_commit) - normal.assert_not_called() # Explicit fast/rollback/version operations keep their contract. + normal.assert_not_called() # Explicit fast operations keep their contract. @patch('openpilot.starpilot.drive_state.evidence.PhysicalSource', return_value=Mock(update_ready=Mock(return_value=True))) def test_download_selected_version_stages_exact_commit_without_installing(self, _physical): @@ -406,6 +406,28 @@ class TestVendoredUpdate(unittest.TestCase): self.assertTrue(self.updater.params.values["UpdateAvailable"]) progress.assert_called_with("rebooting", "Update installed. Restarting device.") + @patch('openpilot.starpilot.drive_state.evidence.PhysicalSource', return_value=Mock(update_ready=Mock(return_value=True))) + def test_selected_version_falls_back_to_full_update_without_installing_branch_head(self, _physical): + installed = self.root / "installed" + self.git(self.root, "clone", "--no-local", str(self.merged), str(installed)) + self.updated.BASEDIR = str(installed) + self.git(installed, 'remote', 'set-url', 'origin', str(self.source)) + (self.source / "panda/README.md").write_text("Selected OS update") + selected = self.commit_source("Selected version") + (self.source / "panda/README.md").write_text("Newer branch head") + self.commit_source("Newer version") + self.updated.AGNOS = True + from openpilot.starpilot.software.fast_update import FastUpdateIncompatible + with patch('openpilot.starpilot.software.fast_update.fast_update', side_effect=FastUpdateIncompatible('OS update required')): + self.assertEqual(self.updater.fast_update(BRANCH, self.initial_commit, selected), 'reboot-requested') + self.assertEqual(self.git(self.finalized, 'rev-parse', 'HEAD'), selected) + self.assertEqual(self.git(installed, 'rev-parse', 'HEAD'), self.initial_commit) + self.assertTrue(self.updater.params.values['DoReboot']) + callback = self.updated.handle_agnos_update.call_args.kwargs['progress'] + callback('Downloading and writing AGNOS system', 37) + self.assertEqual(self.updater.params.values['UpdaterFastState']['stage'], 'agnos') + self.assertEqual(self.updater.params.values['UpdaterFastState']['percent'], 37) + def test_normal_fallback_never_reboots_after_parked_authority_is_lost(self): installed = self.root / "installed" self.git(self.root, "clone", "--no-local", str(self.merged), str(installed)) diff --git a/openpilot/system/updated/updated.py b/openpilot/system/updated/updated.py index ca2cf3f11f..44c017463e 100755 --- a/openpilot/system/updated/updated.py +++ b/openpilot/system/updated/updated.py @@ -361,7 +361,7 @@ def finalize_update(progress=None) -> None: cloudlog.info("done finalizing overlay") -def handle_agnos_update() -> None: +def handle_agnos_update(progress=None) -> None: cur_version = HARDWARE.get_os_version() config = run(["bash", "-c", r"unset AGNOS_VERSION AGNOS_UPDATE_POLICY; source launch_env.sh && " + "printf '%s\\n%s\\n' \"$AGNOS_VERSION\" \"${AGNOS_UPDATE_POLICY:-auto}\""], OVERLAY_MERGED).splitlines() @@ -386,7 +386,7 @@ def handle_agnos_update() -> None: if not os.path.isfile(manifest_path): # releases before the openpilot/ move manifest_path = os.path.join(OVERLAY_MERGED, "system/hardware/tici/agnos.json") target_slot_number = get_target_slot_number() - flash_agnos_update(manifest_path, target_slot_number, cloudlog) + flash_agnos_update(manifest_path, target_slot_number, cloudlog, progress=progress) class Updater: @@ -746,13 +746,13 @@ class Updater: current_os=HARDWARE.get_os_version(), invalidate=invalidate, rollback=rollback, progress=installed_progress, selected_commit=selected_commit, versions_only=versions_only) except FastUpdateIncompatible: - if not automatic: + if not automatic and (selected_commit is None or rollback): raise - return self.normal_update(branch, commit, parked, progress) + return self.normal_update(branch, commit, parked, progress, selected_commit=selected_commit) finally: source.close() - def normal_update(self, branch: str, commit: str, parked, progress) -> str: + def normal_update(self, branch: str, commit: str, parked, progress, *, selected_commit=None) -> str: def admitted(): if not parked() or self.get_commit_hash(BASEDIR) != commit: raise FastUpdateError("Update source or parked state changed") @@ -764,7 +764,7 @@ class Updater: self.params.put("UpdaterState", "checking...", block=True) if phone_uplink_active(): raise FastUpdateError("Software downloads are disabled while using phone internet") - if not self.fetch_update(): + if not self.fetch_update(selected_commit=selected_commit, admitted=admitted): raise FastUpdateError("Target branch is no longer available") admitted() self.params.put_bool("UpdateAvailable", True, block=True) @@ -833,9 +833,9 @@ class Updater: validate_update_revision(OVERLAY_MERGED, "HEAD", branch) cloudlog.info("git reset success: %s", '\n'.join(r)) - # TODO: show agnos download progress if AGNOS and not legacy_return: - handle_agnos_update() + self.progress('agnos', 'Checking AGNOS operating system update...', background=background) + handle_agnos_update(progress=lambda detail, percent: self.progress('agnos', detail, background=background, percent=percent)) # Create the finalized, ready-to-swap update self.params.put("UpdaterState", "finalizing update...", block=True) diff --git a/prebuilt.json b/prebuilt.json index aff44246e4..ef27bc5f2e 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "ae4bc80478faa81557234dc6b388fccceca513d777e4917b9854a641616b8e4a", "schema_version": 1} +{"protected_inventory_sha256": "946e55cd9ec6abdcec53773d7343faed6b3115af978cf87a246262a5824dddb1", "schema_version": 1}