From e5ea759719fef7b75fee596e6d79d1b104faef97 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:33:27 -0600 Subject: [PATCH] Separate usable steering samples from complete native history checks --- .github/workflows/flm-offroad.yaml | 1 + openpilot/starpilot/flm/offroad_checks.py | 2 +- .../flm/offroad_controller_checks.py | 3 ++- .../flm/tests/test_offroad_backend.py | 21 ++++++++++++++++++- .../tests/test_offroad_nonemitted_controls.py | 14 ++++++++++++- prebuilt.json | 2 +- 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/flm-offroad.yaml b/.github/workflows/flm-offroad.yaml index 21266e5f89..7719cb0d3f 100644 --- a/.github/workflows/flm-offroad.yaml +++ b/.github/workflows/flm-offroad.yaml @@ -88,6 +88,7 @@ jobs: --json-output ci-results/flm-offroad.json .venv/bin/python -m pytest -q --import-mode=importlib \ openpilot/starpilot/flm/tests/test_steering_compatibility.py \ + openpilot/starpilot/flm/tests/test_offroad_nonemitted_controls.py \ openpilot/starpilot/flm/tests/test_observed_maneuvers.py \ openpilot/starpilot/flm/tests/test_upstream_producer_transport.py \ openpilot/starpilot/flm/tests/test_clock_resolution_budget.py \ diff --git a/openpilot/starpilot/flm/offroad_checks.py b/openpilot/starpilot/flm/offroad_checks.py index 2a6de8ec12..299c5b7362 100644 --- a/openpilot/starpilot/flm/offroad_checks.py +++ b/openpilot/starpilot/flm/offroad_checks.py @@ -203,7 +203,7 @@ def _original_input_refusal(rows): reason = numerical.get('reason') if not row['qualified'] and ( reason == 'original_hint_requires_exact_unclipped_native_pair' - or reason == 'same_state_controller_checks_only' and type(numerical.get('scored_frames')) is int and numerical['scored_frames'] < 50 + or reason == 'same_state_controller_checks_only' and type(numerical.get('scored_frames')) is int and numerical['scored_frames'] <= 0 ): return True return False diff --git a/openpilot/starpilot/flm/offroad_controller_checks.py b/openpilot/starpilot/flm/offroad_controller_checks.py index d19865eded..02e56a3a9c 100644 --- a/openpilot/starpilot/flm/offroad_controller_checks.py +++ b/openpilot/starpilot/flm/offroad_controller_checks.py @@ -251,7 +251,8 @@ def check_candidate(cp, controls, values, *, score_start_ns=0, score_end_ns=2**6 maximum = max(maximum, delta) last_ns, last_sequence = frame.control_ns, frame.frame_sequence return { - 'qualified': bool(scored >= 50 and (changed > 0 or not require_change)), + # Replication is assessed across independent windows; full native history is checked separately. + 'qualified': bool(scored > 0 and (changed > 0 or not require_change)), 'reason': 'same_state_controller_checks_only', 'verified_frames': verified, 'scored_frames': scored, diff --git a/openpilot/starpilot/flm/tests/test_offroad_backend.py b/openpilot/starpilot/flm/tests/test_offroad_backend.py index 248652bd6f..9eeb4b1541 100644 --- a/openpilot/starpilot/flm/tests/test_offroad_backend.py +++ b/openpilot/starpilot/flm/tests/test_offroad_backend.py @@ -343,7 +343,7 @@ class TestOffroadSurface(unittest.TestCase): from opendbc.car.hyundai.values import CAR from openpilot.starpilot.flm import controller_replay from openpilot.starpilot.flm.controller_replay import SelectedControllerFactory, capture_snapshot, frame_input, final_command - from openpilot.starpilot.flm.offroad_controller_checks import check_candidate + from openpilot.starpilot.flm.offroad_controller_checks import check_candidate, check_original_native from openpilot.starpilot.flm.torque_adapter import Objective from openpilot.starpilot.flm.torque_observation import TorqueObservation @@ -413,6 +413,25 @@ class TestOffroadSurface(unittest.TestCase): self.assertEqual(len(result['commands']), len(original)) self.assertTrue(all(before == after for _, before, after in result['commands'])) self.assertFalse(check_candidate(cp, original, values(), require_change=True)['qualified']) + # A few usable commands may be numerically checked, but cannot replace native history or an actual change. + for end_tick, expected_scored in ((4, 1), (24, 17), (59, 48)): + with self.subTest(end_tick=end_tick): + sparse = check_candidate(cp, original, values(), score_end_ns=original[end_tick].control_ns, require_change=False) + self.assertTrue(sparse['qualified'], sparse) + self.assertEqual(sparse['scored_frames'], expected_scored) + self.assertEqual(sparse['changed_frames'], 0) + self.assertEqual(sparse['verified_frames'], len(original)) + self.assertFalse(check_candidate(cp, original, values(), score_end_ns=original[end_tick].control_ns)['qualified']) + commands = sparse['commands'] + stamps = {stamp for stamp, _, _ in commands} + native_controls = tuple(control for control in original if control.control_ns in stamps) + if len(native_controls) < 50: + with self.assertRaisesRegex(ValueError, 'Complete bounded source controller/native history required'): + check_original_native(cp, native_controls, (), commands, require_change=False) + else: + native = check_original_native(cp, native_controls, (), commands, require_change=False) + self.assertFalse(native['qualified']) + self.assertEqual(native['reason'], 'insufficient_original_native_delivery') hinted = tuple(replace(row, limited=True) for row in original) no_delivery = check_candidate(cp, hinted, values(), require_change=False) self.assertFalse(no_delivery['qualified']) diff --git a/openpilot/starpilot/flm/tests/test_offroad_nonemitted_controls.py b/openpilot/starpilot/flm/tests/test_offroad_nonemitted_controls.py index 1ef5f16749..ef3040b56f 100644 --- a/openpilot/starpilot/flm/tests/test_offroad_nonemitted_controls.py +++ b/openpilot/starpilot/flm/tests/test_offroad_nonemitted_controls.py @@ -146,7 +146,9 @@ def test_native_history_counts_real_emissions_and_preserves_each_hold(native_his @pytest.mark.parametrize('reason,scored,attempts', ( ('original_hint_requires_exact_unclipped_native_pair', None, 1), - ('same_state_controller_checks_only', 49, 1), + ('same_state_controller_checks_only', 0, 1), + ('same_state_controller_checks_only', 1, len(TRAINING_FRACTIONS)), + ('same_state_controller_checks_only', 49, len(TRAINING_FRACTIONS)), ('same_state_controller_checks_only', 50, len(TRAINING_FRACTIONS)), ('candidate_dependent_quality_refusal', None, len(TRAINING_FRACTIONS)), )) @@ -161,3 +163,13 @@ def test_only_original_source_refusal_ends_redundant_strength_search(reason, sco assert fitted is None and proof['selected_fraction'] is None assert len(proof['attempts']) == checker.call_count == attempts assert proof['heldout_windows_not_evaluated'] == ('d', 'e', 'f') + + +def test_sparse_numerical_credit_never_replaces_real_native_emissions(native_history): + cp, controls, chain, commands = native_history + retained = set(sorted({output.apply_ns for output in chain})[:24]) + fewer = tuple(output for output in chain if output.apply_ns in retained) + result = check_original_native(cp, controls, fewer, commands, require_change=False) + assert not result['qualified'] and result['reason'] == 'insufficient_original_native_delivery' + unchanged = check_original_native(cp, controls, chain, commands, require_change=True) + assert not unchanged['qualified'], 'A complete unchanged history cannot earn a changed tune' diff --git a/prebuilt.json b/prebuilt.json index 8cd764dd52..6a45cb8c8d 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "28fcd3ed89612c4b8cdc262e0df2381ca978c1dbe8792072df2564f9991a05e5", "schema_version": 1} +{"protected_inventory_sha256": "9b542a5eaf10d5a0a5bb94304cd3334a63ad1fcc39e225f6014be4b69c8660eb", "schema_version": 1}