From f29ab3c676e8454eab1335828e4bcb2e4f5effe9 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:31:11 -0600 Subject: [PATCH] Preserve Mazda lateral authority through Cancel deadline overlap --- openpilot/selfdrive/selfdrived/selfdrived.py | 6 ++ .../aol/tests/test_mazda_cancel_deadline.py | 59 +++++++++++++++++++ prebuilt.json | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 openpilot/starpilot/aol/tests/test_mazda_cancel_deadline.py diff --git a/openpilot/selfdrive/selfdrived/selfdrived.py b/openpilot/selfdrive/selfdrived/selfdrived.py index 55824a7d38..db8d85bd69 100755 --- a/openpilot/selfdrive/selfdrived/selfdrived.py +++ b/openpilot/selfdrive/selfdrived/selfdrived.py @@ -1602,6 +1602,12 @@ class SelfdriveD: previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id, cancel_samples=getattr(self, 'car_state_envelopes', ())): user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg()) + if user_disable and fresh_successor and decision.lateral_active and not decision.longitudinal_active and self.CP.brand == 'mazda': + from openpilot.starpilot.car.mazda.aol import physical_cancel_lateral_allowed + native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id) + if physical_cancel_lateral_allowed(self.CP, CS, intent, native, settings=self.aol_settings, + previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id): + user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg()) if user_disable and fresh_successor and self.ford_source_deadline_supported(): from openpilot.starpilot.car.ford.aol import physical_cancel_lateral_allowed native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id) diff --git a/openpilot/starpilot/aol/tests/test_mazda_cancel_deadline.py b/openpilot/starpilot/aol/tests/test_mazda_cancel_deadline.py new file mode 100644 index 0000000000..b14ab36fc0 --- /dev/null +++ b/openpilot/starpilot/aol/tests/test_mazda_cancel_deadline.py @@ -0,0 +1,59 @@ +from contextlib import ExitStack +from unittest import mock + +import pytest + +from opendbc.car import gen_empty_fingerprint +from opendbc.car.mazda.interface import CarInterface +from opendbc.car.mazda.values import CAR +from openpilot.cereal import log +from openpilot.common.prefix import OpenpilotPrefix +from openpilot.starpilot.aol.intent import read_settings +from openpilot.starpilot.aol.tests import test_ioniq_availability as fixture +from openpilot.starpilot.aol.tests.test_input_deadline_continuity import BASE, intent + + +@pytest.mark.parametrize('profile', [CAR.MAZDA_CX5, CAR.MAZDA_CX5_2022, CAR.MAZDA_CX9_2021]) +@pytest.mark.parametrize('pulse', ['physical_cancel', 'permanent_eps', 'native_denied', 'driver_disarm', 'native_reordered']) +def test_mazda_cancel_after_previous_axis_deadline(profile, pulse): + with OpenpilotPrefix(), ExitStack() as cleanup: + case = fixture.IoniqAvailabilityTests(methodName='runTest') + cleanup.callback(case.doCleanups) + cp = CarInterface.get_params(profile, gen_empty_fingerprint(), [], False, False, False) + sd, _, drive = case._authority_callers(True, cp=cp, genuine_events=True) + sd.aol_settings = read_settings(sd.params) + state = fixture.car_state() + state.cruiseState.available = state.cruiseState.enabled = True + options = {'observed_state': state, 'native_request_long': False, 'long_allowed': False, 'panda_controls_allowed': True} + drive(0, **options) + prior, _, command = drive(2, state_stamp=BASE, offset_ns=6_066_613, intent_message=intent(BASE, 3), **options) + assert prior.lateralActive and command.latActive and not command.longActive + assert prior.validUntilMonoTime == BASE + 36_066_613 + + cancel_ns = BASE + 11_869_375 + now = [BASE + 18_554_693] + state.buttonEvents = [{'type': 'cancel', 'pressed': True}] + if pulse == 'permanent_eps': + state.steerFaultPermanent = True + if pulse == 'native_denied': + options['allowed'] = False + publish = sd.publish_axis_proof + + def publish_after_deadline(*args, **kwargs): + now[0] = prior.validUntilMonoTime + 320_000 + return publish(*args, **kwargs) + + offset_ns = -21_445_307 if pulse == 'native_reordered' else -1_445_307 + with mock.patch('openpilot.selfdrive.selfdrived.selfdrived.time.monotonic_ns', side_effect=lambda: now[0]), \ + mock.patch.object(sd, 'publish_axis_proof', side_effect=publish_after_deadline) as published: + axis, _, command = drive(4, state_stamp=cancel_ns, offset_ns=offset_ns, + intent_message=intent(cancel_ns, 4, latched=pulse != 'driver_disarm'), **options) + assert published.called + assert not command.longActive and not sd.enabled + if pulse == 'physical_cancel': + assert log.OnroadEvent.EventName.buttonCancel in sd.events.names + assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names + assert not sd.aol_authority_lost + assert axis.sourceCarStateMonoTime == cancel_ns and axis.lateralActive and command.latActive + else: + assert not axis.lateralActive and not command.latActive diff --git a/prebuilt.json b/prebuilt.json index a2df94e003..b4f68332d4 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "d99e2885e775ca43cbf6c44120ac59d9ac08d235ddfbf2aaff0f243f185a321a", "schema_version": 1} +{"protected_inventory_sha256": "fcfbc1af4b5534aa28c75925e17ed6c025e49c0a25bd31b985261f37584e4cfe", "schema_version": 1}