From d151e4d5354798079fae2b6d032ca6680cacaab2 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:22:15 -0600 Subject: [PATCH] Allow fresh qualification after a legacy inconclusive FLM timeout --- openpilot/starpilot/flm/offroad_worker.py | 35 +++++++++++--- .../flm/tests/test_offroad_retained_trials.py | 46 +++++++++++++++++++ prebuilt.json | 2 +- 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/openpilot/starpilot/flm/offroad_worker.py b/openpilot/starpilot/flm/offroad_worker.py index 0ae50ccf53..dd53b384c2 100644 --- a/openpilot/starpilot/flm/offroad_worker.py +++ b/openpilot/starpilot/flm/offroad_worker.py @@ -175,6 +175,32 @@ def trial_document(cache, digest): return trial_origin(cache, digest)[1] +def rejected_trial_change(cache, row, proposal): + """A historical inconclusive timeout is not measured rejection of a tune.""" + if row is None or row['state'] != 'rolled_back': + return False + outcome = cache.get(row['analysis_sha256']) + comparisons = outcome.get('comparisons') + timeout = ( + outcome.get('kind') == 'next_drive_outcome' + and outcome.get('outcome') == 'rolled_back' + and outcome.get('reason') == 'trial_inconclusive_drive_limit' + and outcome.get('observed_only') is True + and type(comparisons) is list + and type(outcome.get('assessment')) is dict + and not outcome['assessment'].get('quality_stop_markers') + and all( + type(comparison) is dict and type(comparison.get('independent')) is list and len(comparison['independent']) == 2 + and all(type(result) is dict and result.get('worse') is False for result in comparison['independent']) + for comparison in comparisons + ) + ) + if timeout: + return False # Fresh independent/native qualification still runs below; no old value is restored here. + trial = trial_document(cache, row['analysis_sha256']) + return trial['parameter'] == proposal['parameter'] and trial['delta'] == proposal['delta'] + + def trial_source_history(cache, digest): from openpilot.starpilot.flm.offroad_route import original_segment_hashes @@ -1093,10 +1119,7 @@ class OffroadWorker: for group, cohort, proposal in choices: selected_profile_windows = cohort['whole_windows'] offered = {'values': proposal['values'], 'parameter': proposal['parameter'], 'delta': proposal['delta']} - blocked = False - if row is not None and row['state'] == 'rolled_back': - trial = trial_document(self.cache, row['analysis_sha256']) - blocked = trial['parameter'] == proposal['parameter'] and trial['delta'] == proposal['delta'] + blocked = rejected_trial_change(self.cache, row, proposal) if blocked: reason = 'same_rejected_change_requires_different_evidence_or_reset' continue @@ -1144,9 +1167,7 @@ class OffroadWorker: if fitted is not None: proposal = fitted offered = {'values': proposal['values'], 'parameter': proposal['parameter'], 'delta': proposal['delta']} - if row is not None and row['state'] == 'rolled_back': - trial = trial_document(self.cache, row['analysis_sha256']) - feasible = not (trial['parameter'] == proposal['parameter'] and trial['delta'] == proposal['delta']) + feasible = not rejected_trial_change(self.cache, row, proposal) if not feasible: reason = 'no_new_native_feasible_training_step' if independent_checks is not None: diff --git a/openpilot/starpilot/flm/tests/test_offroad_retained_trials.py b/openpilot/starpilot/flm/tests/test_offroad_retained_trials.py index 6865661629..ff522e7b2c 100644 --- a/openpilot/starpilot/flm/tests/test_offroad_retained_trials.py +++ b/openpilot/starpilot/flm/tests/test_offroad_retained_trials.py @@ -193,5 +193,51 @@ class TestRetainedTrialSources(unittest.TestCase): self.assertEqual(restored['values'], accepted['values'], 'A later trial restores its immediate prior tune, not the first baseline') +class TestLegacyInconclusiveRejection(unittest.TestCase): + def legacy(self, cache, *, reason='trial_inconclusive_drive_limit', comparisons=None, markers=()): + original = cache.put({'kind': 'next_drive_trial', 'parameter': 'ff_gain_left', 'delta': .005}) + outcome = cache.put({'kind': 'next_drive_outcome', 'trial_analysis_sha256': original, + 'outcome': 'rolled_back', 'reason': reason, 'observed_only': True, + 'comparisons': [] if comparisons is None else comparisons, 'assessment': {'quality_stop_markers': list(markers)}}) + return {'state': 'rolled_back', 'analysis_sha256': outcome} + + def test_timeout_does_not_blacklist_a_fresh_qualified_change_or_restore_any_params(self): + with tempfile.TemporaryDirectory() as directory: + cache = AssessmentCache(directory) + row = self.legacy(cache) + before = cache.get(row['analysis_sha256']) + proposal = {'parameter': 'ff_gain_left', 'delta': .005} + self.assertFalse(worker.rejected_trial_change(cache, row, proposal)) + self.assertEqual(cache.get(row['analysis_sha256']), before) + self.assertFalse(worker.rejected_trial_change(cache, None, proposal)) + self.assertFalse(worker.rejected_trial_change(cache, dict(row, state='ready_for_next_drive'), proposal)) + + def test_actual_regression_safety_and_explicit_user_rollback_still_reject_same_change(self): + with tempfile.TemporaryDirectory() as directory: + cache = AssessmentCache(directory) + proposal = {'parameter': 'ff_gain_left', 'delta': .005} + for reason in ('next_drive_observed_tracking_worse', 'actual_next_drive_controller_or_native_delivery_unproven', 'explicit_user_rollback'): + row = self.legacy(cache, reason=reason) + self.assertTrue(worker.rejected_trial_change(cache, row, proposal)) + row = self.legacy(cache, markers=[{'reason': 'declared-safety-withdrawal'}]) + self.assertTrue(worker.rejected_trial_change(cache, row, proposal)) + self.assertFalse(worker.rejected_trial_change(cache, row, dict(proposal, delta=.006))) + # Explicit RouteStorage.rollback keeps the trial document, rather than + # fabricating a next-drive measurement or timeout outcome. + original = cache.get(row['analysis_sha256'])['trial_analysis_sha256'] + self.assertTrue(worker.rejected_trial_change(cache, dict(row, analysis_sha256=original), proposal)) + + def test_malformed_or_worsening_comparison_does_not_become_a_timeout_exception(self): + with tempfile.TemporaryDirectory() as directory: + cache = AssessmentCache(directory) + proposal = {'parameter': 'ff_gain_left', 'delta': .005} + for comparisons in ([None], [{'independent': []}], [{'independent': [{}, {'worse': False}]}], + [{'independent': [{'worse': True}, {'worse': False}]}]): + row = self.legacy(cache, comparisons=comparisons) + self.assertTrue(worker.rejected_trial_change(cache, row, proposal)) + row = self.legacy(cache, comparisons=[{'independent': [{'worse': False}, {'worse': False}]}]) + self.assertFalse(worker.rejected_trial_change(cache, row, proposal)) + + if __name__ == '__main__': unittest.main() diff --git a/prebuilt.json b/prebuilt.json index 75af503e7b..c2d5441dc3 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "2fa9d14e5695587fb58d6e2094c031d23a2bb9f8ced580c7c957ae8095f7b6db", "schema_version": 1} +{"protected_inventory_sha256": "52dee78f8a1643fc46aa9bc5d6277f74d88cabbea589d38fd0fd5a0871b78d53", "schema_version": 1}