From 7a7b391656e7d0d29213cd6f4d3b13d5194d41cd Mon Sep 17 00:00:00 2001 From: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Date: Sun, 13 Sep 2026 22:36:58 -0400 Subject: [PATCH] stop lying on my chestnut --- starpilot/assets/model_manager.py | 19 +++++++ starpilot/assets/tests/test_model_pipeline.py | 55 +++++++++++++++++++ system/hardware/hardwared.py | 6 +- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/starpilot/assets/model_manager.py b/starpilot/assets/model_manager.py index 32d1ae5307..05d3bdf080 100644 --- a/starpilot/assets/model_manager.py +++ b/starpilot/assets/model_manager.py @@ -265,6 +265,25 @@ def model_accelerator_artifact_installed(model_key: str, accelerator: str = MODE ) +def selected_chestnut_artifacts_ready(params) -> bool: + """Return whether the selected Chestnut workload is installed for offroad diagnostics.""" + big_model_id, _, _ = get_model_profile(params, "big") + if big_model_id and file_chunked_exists(MODELS_PATH / driving_artifact_filename(big_model_id)): + return True + + config = load_model_lab_config(params) + lateral_model_id = canonical_model_key(config["lateralModel"]) + longitudinal_model_id = canonical_model_key(config["longitudinalModel"]) + return bool( + config["enabled"] and + lateral_model_id and + longitudinal_model_id and + lateral_model_id != longitudinal_model_id and + model_accelerator_artifact_installed(lateral_model_id) and + model_accelerator_artifact_installed(longitudinal_model_id) + ) + + def external_gpu_available() -> bool: """Return whether the supported external GPU link is ready for modeld.""" try: diff --git a/starpilot/assets/tests/test_model_pipeline.py b/starpilot/assets/tests/test_model_pipeline.py index 5b63e391d9..5490a07d71 100644 --- a/starpilot/assets/tests/test_model_pipeline.py +++ b/starpilot/assets/tests/test_model_pipeline.py @@ -211,6 +211,61 @@ def test_disabled_big_profile_does_not_migrate_from_legacy_selection(tmp_path, m assert "ActiveBigModelVersion" not in params.values +def test_selected_chestnut_artifacts_ready_ignores_cleared_runtime_flag(tmp_path, monkeypatch): + monkeypatch.setattr(model_manager, "MODELS_PATH", tmp_path) + (tmp_path / model_manager.ARTIFACT_METADATA_CACHE).write_text(json.dumps({ + "big-one": {"uses_external_gpu": True}, + })) + (tmp_path / "big-one_driving_tinygrad.pkl").write_bytes(b"compiled") + + class FakeParams: + def __init__(self): + self.values = { + "ActiveBigModel": "big-one", + "ActiveBigModelName": "Big One", + "ActiveBigModelVersion": "v16", + "UsbGpuCompiled": False, + } + + def get(self, key): + return self.values.get(key) + + params = FakeParams() + assert not params.get("UsbGpuCompiled") + assert model_manager.selected_chestnut_artifacts_ready(params) + + (tmp_path / "big-one_driving_tinygrad.pkl").unlink() + assert not model_manager.selected_chestnut_artifacts_ready(params) + + +def test_selected_chestnut_artifacts_ready_accepts_model_lab_pair(tmp_path, monkeypatch): + monkeypatch.setattr(model_manager, "MODELS_PATH", tmp_path) + (tmp_path / model_manager.ARTIFACT_METADATA_CACHE).write_text(json.dumps({ + model_id: { + "uses_external_gpu": False, + "accelerator_artifacts": {"chestnut": {"execution_device": "AMD"}}, + } + for model_id in ("lateral", "longitudinal") + })) + for model_id in ("lateral", "longitudinal"): + (tmp_path / f"{model_id}_driving_chestnut_tinygrad.pkl").write_bytes(b"compiled") + + class FakeParams: + def get(self, key): + return { + "ActiveBigModel": "none", + "ModelLabConfig": { + "enabled": True, + "lateralModel": "lateral", + "longitudinalModel": "longitudinal", + }, + }.get(key) + + assert model_manager.selected_chestnut_artifacts_ready(FakeParams()) + (tmp_path / "longitudinal_driving_chestnut_tinygrad.pkl").unlink() + assert not model_manager.selected_chestnut_artifacts_ready(FakeParams()) + + def test_runtime_model_metadata_does_not_overwrite_model_profiles(tmp_path, monkeypatch): monkeypatch.setattr(model_manager, "MODELS_PATH", tmp_path) (tmp_path / model_manager.ARTIFACT_METADATA_CACHE).write_text(json.dumps({ diff --git a/system/hardware/hardwared.py b/system/hardware/hardwared.py index 648350c3ae..4b65d33023 100644 --- a/system/hardware/hardwared.py +++ b/system/hardware/hardwared.py @@ -39,6 +39,7 @@ from openpilot.system.hardware.chestnut.status import ChestnutStatus from openpilot.system.version import terms_version, training_version from openpilot.system.athena.registration import UNREGISTERED_DONGLE_ID +from openpilot.starpilot.assets.model_manager import selected_chestnut_artifacts_ready from openpilot.starpilot.common.starpilot_variables import get_starpilot_toggles ThermalStatus = log.DeviceState.ThermalStatus @@ -434,6 +435,9 @@ def hardware_thread(end_event, hw_queue) -> None: ) chestnut_state = sm["chestnutState"] chestnut_valid = sm.alive["chestnutState"] and sm.valid["chestnutState"] + compiled = params.get_bool("UsbGpuCompiled") + if started_ts is None: + compiled = selected_chestnut_artifacts_ready(params) chestnut_status.update( started_ts is None, chestnut_expected, @@ -441,7 +445,7 @@ def hardware_thread(end_event, hw_queue) -> None: chestnut.failed, params.get_bool("UsbGpuLoading"), params.get("UsbGpuActive"), - params.get_bool("UsbGpuCompiled"), + compiled, chestnut_state if chestnut_valid else None, set_offroad_alert_if_changed, )