diff --git a/openpilot/starpilot/car/subaru/paused_intent.py b/openpilot/starpilot/car/subaru/paused_intent.py index ef0f0f88b3..cd169d67ca 100644 --- a/openpilot/starpilot/car/subaru/paused_intent.py +++ b/openpilot/starpilot/car/subaru/paused_intent.py @@ -1,4 +1,4 @@ -"""Retain established Subaru OFF intent; this proof never grants a command.""" +"""Preserve established Subaru intent; this proof never grants a command.""" from dataclasses import dataclass from math import isfinite @@ -135,19 +135,21 @@ def retain_stopped_source_feedback(feedback, sm, cp, state, axis, stamp, now_ns, def retain_paused_restriction(feedback, sm, cp, state, axis, stamp, now_ns, *, latched, producer): + """Accepted intent survives coherent OFF, waiting, and active LAT phases.""" if retain_pending_restriction_recovery(feedback, sm, cp, state, axis, stamp, now_ns, latched=latched, producer=producer): return True from openpilot.starpilot.aol.transport_pause import _configured_transport_native previous = feedback.signature - if (cp.carFingerprint != CAR.SUBARU_IMPREZA_2020 or not qualified(cp, marked_only=True) or + if (not qualified(cp, marked_only=True) or cp.openpilotLongitudinalControl or not latched or feedback.failed or feedback.paused or - feedback.retention_started_ns or feedback.source_retention_started_ns or not feedback.ever_lateral_active or + feedback.retention_started_ns or feedback.source_retention_started_ns or previous is None or not feedback.session or not producer or previous[0] != previous[7] or previous[0] != feedback.session or previous[5] != 'none' or - previous[10] or previous[12] or previous[9] != previous[11] or not previous[13] or previous[14:16] != (producer, int(axis.intentIntegrityEpoch)) or + previous[10] or previous[12] or previous[9] and not previous[11] or not previous[13] or previous[14:16] != (producer, int(axis.intentIntegrityEpoch)) or axis.intentProducerSessionId != producer or str(axis.sessionId) != feedback.session or - str(axis.faultReason) != 'none' or str(axis.mode) != 'off' or not axis.nativeAcknowledged or - any((axis.desiredLateral, axis.lateralActive, axis.desiredLongitudinal, axis.longitudinalActive)) or + str(axis.faultReason) != 'none' or not axis.nativeAcknowledged or + str(axis.mode) != ('lateralOnly' if axis.lateralActive else 'off') or + axis.lateralActive and not axis.desiredLateral or axis.desiredLongitudinal or axis.longitudinalActive or not 0 < previous[8] <= previous[2] <= now_ns <= previous[4] or now_ns - previous[8] > AXIS_MAX_AGE_NS or not previous[8] <= axis.sourceCarStateMonoTime <= stamp <= now_ns or now_ns - axis.sourceCarStateMonoTime > AXIS_MAX_AGE_NS or not state.steerFaultTemporary or state.steerFaultPermanent or not state.canValid or state.canTimeout or @@ -178,7 +180,8 @@ def retain_paused_restriction(feedback, sm, cp, state, axis, stamp, now_ns, *, l return False native = _configured_transport_native(sm, cp, feedback.session, now_ns, allow_restricted_lateral=True) if (native is None or not native.pandaInventory or native.requestedLateral != native.lateralAllowed or - native.requestedLongitudinal or native.longitudinalAllowed or native.observedMonoTime < feedback.healthy_native_ns or + axis.lateralActive and not native.lateralAllowed or native.requestedLongitudinal or native.longitudinalAllowed or + native.observedMonoTime < feedback.healthy_native_ns or feedback.healthy_inventory != (native.pandaSerial, tuple(slot.hardwareSerial for slot in native.pandaInventory))): return False if matched: @@ -199,7 +202,7 @@ def retain_pending_restriction_recovery(feedback, sm, cp, state, axis, stamp, no pending, restriction = feedback.pending_event, getattr(feedback, 'temporary_eps_event_ns', 0) if (not qualified(cp, marked_only=True) or not cp.pcmCruise or cp.openpilotLongitudinalControl or not latched or feedback.failed or feedback.paused or feedback.retention_started_ns or - feedback.source_retention_started_ns or not feedback.ever_lateral_active or + feedback.source_retention_started_ns or not 0 < feedback.healthy_feedback_ns <= now_ns or previous is None or not feedback.session or cp_identity(cp) != feedback.cp or not 0 < restriction < pending <= now_ns or now_ns - pending > AXIS_MAX_AGE_NS or previous[0] != previous[7] or previous[0] != feedback.session or previous[5] != 'none' or diff --git a/openpilot/starpilot/car/subaru/tests/test_paused_intent.py b/openpilot/starpilot/car/subaru/tests/test_paused_intent.py index f4b1b09ea1..c3970850b5 100644 --- a/openpilot/starpilot/car/subaru/tests/test_paused_intent.py +++ b/openpilot/starpilot/car/subaru/tests/test_paused_intent.py @@ -192,7 +192,7 @@ def test_paused_restriction_preserves_independent_fault_user_and_authority_vetoe elif fault == 'failed': feedback.failed = True elif fault == 'no_history': - feedback.ever_lateral_active = False + feedback.healthy_feedback_ns = 0 elif fault == 'other_car': cp.carFingerprint = 'SUBARU_OUTBACK' elif fault != 'off': @@ -273,7 +273,7 @@ def test_pending_subaru_recovery_does_not_bypass_independent_vetoes(fault): elif fault == 'failed': feedback.failed = True elif fault == 'no_history': - feedback.ever_lateral_active = False + feedback.healthy_feedback_ns = 0 elif fault == 'new_event': sm.logMonoTime['onroadEvents'] += 1 elif fault == 'no_warning': @@ -354,3 +354,28 @@ def test_recovery_brake_release_preserves_only_a_known_pending_eps_brake(): assert retain_pending_restriction_recovery(feedback, sm, cp, state, sm['aolAxisState'], sm.logMonoTime['aolAxisState'], now, latched=True, producer=PRODUCER) assert leases(feedback) == before + + +@pytest.mark.parametrize('previous_role', ('off', 'waiting', 'active')) +@pytest.mark.parametrize('current_role', ('off', 'waiting', 'active')) +@pytest.mark.parametrize('native_granted', (False, True)) +@pytest.mark.parametrize('ever_active', (False, True)) +@pytest.mark.parametrize('steering_pressed', (False, True)) +@pytest.mark.parametrize('brake_pressed', (False, True)) +def test_subaru_temporary_intent_depends_on_accepted_proof_not_actuation_phase( + previous_role, current_role, native_granted, ever_active, steering_pressed, brake_pressed): + from openpilot.starpilot.car.subaru.paused_intent import retain_paused_restriction + cp, state, feedback, sm, native, stamp = paused_case() + state.steeringPressed, state.brakePressed = steering_pressed, brake_pressed + feedback.ever_lateral_active = ever_active + previous = list(feedback.signature) + previous[9], previous[11] = previous_role == 'active', previous_role != 'off' + feedback.signature = tuple(previous) + change(sm, 'aolAxisState', lambda a: (setattr(a, 'lateralActive', current_role == 'active'), + setattr(a, 'desiredLateral', current_role != 'off'), setattr(a, 'mode', 'lateralOnly' if current_role == 'active' else 'off'))) + native_change(sm, native, requestedLateral=native_granted, lateralAllowed=native_granted) + before = leases(feedback), feedback.signature, sm['aolAxisState'].to_dict() + retained = retain_paused_restriction(feedback, sm, cp, state, sm['aolAxisState'], stamp, stamp, + latched=True, producer=PRODUCER) + assert retained == (current_role != 'active' or native_granted) + assert (leases(feedback), feedback.signature, sm['aolAxisState'].to_dict()) == before diff --git a/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py b/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py index d7efcdd106..20e1bdd0fb 100644 --- a/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py +++ b/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py @@ -30,7 +30,7 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, high_angle_guard=False, main_on_brake=False, guard_brake_release=False, stopped_feedback_gap=False, rearm_on_brake=0, main_during_eps=False, angle_continuation=0, stopped_source_gap=False, paused_eps=0, - eps_clear_join=0, eps_clear_axis_first=False): + eps_clear_join=0, eps_clear_axis_first=False, stop_creep_eps=0, cold_stop=False): angle_handoff = fixed_angle_handoff or vm_angle_handoff fw = firmware_records(candidate, FW_VERSIONS, 'subaru') if firmware is None else firmware rows = [] @@ -77,7 +77,7 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, published = {} ticks = (list(range(30)) + list(range(30, 50)) * 16 + list(range(50, 460)) if main_during_eps else list(range(125)) + list(range(125, 135)) * 30 + list(range(135, 460)) - if hard_stop_native_first else list(range(70)) + list(range(70, 90)) * 16 + list(range(90, 460)) + if hard_stop_native_first or stop_creep_eps else list(range(70)) + list(range(70, 90)) * 16 + list(range(90, 460)) if angle_continuation else range(460)) gap_tick = 75 if main_only else 210 last_card_published = {} @@ -101,9 +101,13 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, reverse = 150 <= tick < 185 temporary = not guard_brake_release and 225 <= tick < 260 main = not 310 <= tick < 350 and (tick >= 30 or not main_only) - stopped = stop_resume and (125 <= tick < 135 if hard_stop_native_first or host_first_stop else 185 <= tick < 195) + stopped = stop_resume and (125 <= tick < 135 if hard_stop_native_first or host_first_stop or stop_creep_eps else 185 <= tick < 195) + if stop_creep_eps: + stopped = tick < 135 and (cold_stop or tick >= 125) + brake = bool(stopped and tick < 129) + first_resume = False first_resume = 145 <= tick < 150 if hard_stop_native_first or host_first_stop else 125 <= tick < 145 - if paused_eps or eps_clear_join: + if paused_eps or eps_clear_join or stop_creep_eps: first_resume = False # Blinker debounce overlaps the later reverse pause. source_missing = bool(source_outage and 75 <= tick < 81) if paused_eps: @@ -175,6 +179,15 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, values['Brake_Pressure_L_R'] = {'Steering_Angle': 101 if 95 <= tick < 102 else 0} else: values['Steering_Torque']['Steer_Warning'] = int(95 <= tick < 102 or temporary) + if stop_creep_eps: + values['Dashlights'] = {'LEFT_BLINKER': 0, 'RIGHT_BLINKER': 0} + values['Brake_Pedal'] = {'Speed': 0 if stopped else .171 if 135 <= tick < 137 else .356 if 137 <= tick < 148 else 14.4} + values['Wheel_Speeds'] = dict.fromkeys(('FL', 'FR', 'RL', 'RR'), values['Brake_Pedal']['Speed']) + values['Steering_Torque']['Steer_Torque_Sensor'] = -121 if 125 <= tick < 137 else -118 if 137 <= tick < 148 else 0 + if stop_creep_eps == 1: + values['Brake_Pressure_L_R'] = {'Steering_Angle': 101 if 125 <= tick < 148 else 0} + else: + values['Steering_Torque']['Steer_Warning'] = int(137 <= tick < 148 or temporary) incoming = stream.frames(values, tick=tick) if source_outage: pending_host_can.append((now, incoming)) @@ -401,7 +414,7 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, assert card.aol_card_intent.allowed_latch, ('SUBARU_STOPPED_FEEDBACK_GAP_CLEARED', row) assert not command.latActive and not command.longActive and row['permission'] == 0, row assert row['fault'] == 'none' and 'controlsMismatch' not in row['events'], row - if stopped: + if stopped and (not stop_creep_eps or tick >= 40): assert not row['lat'] and row['cardLatch'] and row['permission'] == 0 and row['fault'] in ( ('none', 'availabilityPause') if stopped_source_gap else ('none',)), ('SUBARU_STOP_LOST_ARMED_INTENT', row) if source_outage and 78 <= tick < 81: @@ -414,10 +427,13 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, if eps_clear_join and 100 <= tick < 145: assert row['cardLatch'] and row['armed'] and not row['lat'] and not row['long'], ('SUBARU_EPS_CLEAR_LOST_INTENT', row) assert all(not frame['request'] and frame['output'] == 0 and frame['nativeAccepted'] for frame in row['steering']), row + if stop_creep_eps and 135 <= tick < 148: + assert row['cardLatch'] and row['armed'] and not row['lat'] and not row['long'], ('SUBARU_STOP_CREEP_EPS_LOST_INTENT', row) + assert all(not frame['request'] and frame['output'] == 0 and frame['nativeAccepted'] for frame in row['steering']), row assert not command.longActive, row if 10 <= tick < 30: assert not command.latActive and not bool(intent and intent.allowedLatch) and row['permission'] == 0, row - if 65 <= tick < 90 and not (main_during_eps and tick < 75) and not (source_outage and 75 <= tick < 84): + if 65 <= tick < 90 and not (stop_creep_eps and cold_stop) and not (main_during_eps and tick < 75) and not (source_outage and 75 <= tick < 84): assert command.latActive and bool(intent and intent.allowedLatch) == aol and row['permission'] == int(aol), row if not stopped and (first_resume or 205 <= tick < 220 or 280 <= tick < 300): assert command.latActive == aol and bool(intent and intent.allowedLatch) == aol and row['permission'] == int(aol) and not row['controls'], row @@ -697,3 +713,22 @@ def test_actual_subaru_paused_restriction_event_join(subaru_native_pair, tmp_pat CAR.SUBARU_IMPREZA_2020, subaru_native_pair, tmp_path, main_only=True, paused_eps=restriction, eps_clear_axis_first=axis_first, preferences={'PauseLateralOnSignal': True, 'PauseLateralSpeed': 100., 'LateralResumeDelay': 0.}) + + +@pytest.mark.parametrize('cold_stop', (False, True), ids=('previously-active', 'first-main-at-stop')) +@pytest.mark.parametrize('restriction', (1, 2), ids=('host-guard', 'raw-eps')) +def test_actual_subaru_stop_creep_restriction_preserves_armed_intent( + subaru_native_pair, tmp_path, restriction, cold_stop, candidate=CAR.SUBARU_IMPREZA_2020): + test_actual_full_engage_brake_reverse_temporary_recovery_mainoff( + candidate, subaru_native_pair, tmp_path, main_only=candidate in ( + CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_IMPREZA_2025, CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_OUTBACK_2023), + stop_resume=True, hard_stop_native_first=not cold_stop, stop_creep_eps=restriction, cold_stop=cold_stop) + rows = json.loads((tmp_path / (str(candidate) + '-True-actual.json')).read_text()) + assert any(row['cardLatch'] and row['armed'] and not row['lat'] and row['permission'] == 0 for row in rows if 135 <= row['tick'] < 137) + assert all(row['cardLatch'] and row['armed'] for row in rows if 135 <= row['tick'] < 148) + + +@pytest.mark.parametrize('candidate', (CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025, CAR.SUBARU_CROSSTREK_2025, + CAR.SUBARU_IMPREZA_2025, CAR.SUBARU_FORESTER, CAR.SUBARU_OUTBACK, CAR.SUBARU_OUTBACK_2023)) +def test_actual_subaru_family_stop_creep_restriction(candidate, subaru_native_pair, tmp_path): + test_actual_subaru_stop_creep_restriction_preserves_armed_intent(subaru_native_pair, tmp_path, 2, False, candidate=candidate) diff --git a/prebuilt.json b/prebuilt.json index 540d248d97..c8088abc16 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "37a514391bb45b7864a68918439d9498f419a894e75a89abd1616a44c0f1aba9", "schema_version": 1} +{"protected_inventory_sha256": "b15e9da8b92e2cf391d24d4035a2c2b955cf86be9bcabe102970b030d664b3da", "schema_version": 1} diff --git a/tools/ci/run_vehicle_tests.py b/tools/ci/run_vehicle_tests.py index 7c50a71197..fa3426e52b 100644 --- a/tools/ci/run_vehicle_tests.py +++ b/tools/ci/run_vehicle_tests.py @@ -283,6 +283,8 @@ RELEASE_TARGETS = ( "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_subaru_eps_clear_during_blinker_pause_keeps_armed_intent", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_subaru_family_eps_recovery_join", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_subaru_paused_restriction_event_join", + "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_subaru_stop_creep_restriction_preserves_armed_intent", + "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_subaru_family_stop_creep_restriction", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_repeat_main_with_brake_and_signal_pause", "openpilot/starpilot/aol/tests/test_subaru_temporary_eps.py", "openpilot/starpilot/car/subaru/tests/test_paused_intent.py",