Explain why FLM findings cannot be accepted

This commit is contained in:
firestar5683
2026-11-20 13:42:44 -06:00
parent 5da0140842
commit 4e0e99039a
4 changed files with 111 additions and 7 deletions
@@ -210,6 +210,42 @@ class TestDiagnosticState(unittest.TestCase):
self.assertIn('independent', result['checkpoints'][0]['explanation'])
self.assertEqual(result['learning_diagnostics']['status'], 'not_recorded')
def test_download_distinguishes_old_configuration_from_changed_finding_source(self):
from opendbc.car.toyota.interface import CarInterface
from opendbc.car.toyota.values import CAR
from openpilot.starpilot.flm.runtime_adapter_registry import car_params_digest
from openpilot.starpilot.schema_cache import put_cache
cp = CarInterface.get_non_essential_params(CAR.TOYOTA_COROLLA_TSS2)
cp.carVin = 'JTDAC3EH0B3000000'
self.params.put_bool('IsOffroad', True, block=True)
put_cache(self.params, 'CarParamsPersistent', cp.as_reader(), block=True)
cache = AssessmentCache(directory_for_params(self.params))
parked = car_params_digest(cp)
cp.mass += 50
old, source = car_params_digest(cp), 'a' * 64
def assessment(digest):
return cache.put({'kind': 'partial_assessment', 'assessment': {'route': {'cp_sha256': digest, 'source_sha256': source}}})
older, matching = assessment(old), assessment(parked)
report = {'preference': {'valid': True, 'parked': True, 'vehicle': str(cp.carFingerprint)}, 'current': {'details': {
'Recorded suggestion assessments': [
['turn_in_boost_left', older, source], ['turn_in_boost_right', matching, 'b' * 64],
['unwind_taper_right', matching, source], ['unwind_taper_left', 'f' * 64, source],
],
}}}
before = {p.name: p.read_bytes() for p in cache.directory.iterdir()}
review = self.exported(report)['finding_review']
self.assertEqual(review['manual_coordinates'], 'not_configured')
self.assertEqual(review['findings'], {
'turn_in_boost_left': 'vehicle_configuration_mismatch', 'turn_in_boost_right': 'recording_mismatch',
'unwind_taper_right': 'matches_parked_configuration', 'unwind_taper_left': 'assessment_unavailable',
})
self.assertEqual({p.name: p.read_bytes() for p in cache.directory.iterdir()}, before)
for private in (parked, old, cp.carVin):
self.assertNotIn(private, json.dumps(self.exported(report)))
self.params.put_bool('IsOffroad', False, block=True)
self.assertEqual(self.exported(report)['finding_review']['status'], 'parked_configuration_unavailable')
def test_native_cache_is_reported_separately_from_parked_route_analysis(self):
from openpilot.cereal import messaging
from openpilot.starpilot.schema_cache import put_cache
+25 -6
View File
@@ -40,6 +40,28 @@ def _finding(report, parameter, target, assessment):
return report.get('vehicle'), links[0][2] if links else details.get('Original completed route hash'), tuple(matches[0])
REVIEW_REFUSALS = {
'vehicle_identity_unavailable': 'The vehicle must identify itself before a finding from this review can be accepted.',
'unexpected_review_type': 'This drive review is unavailable for accepting findings. Refresh the findings.',
'recording_mismatch': 'This finding’s recording no longer matches its drive review. Refresh the findings.',
'vehicle_configuration_mismatch': 'This finding was recorded with a different vehicle configuration. Review a drive from the current setup.',
}
def review_binding_issue(document, vehicle_digest, source_digest):
kind = document.get('kind')
if kind == 'identity_review':
return 'vehicle_identity_unavailable'
if kind not in ('completed_assessment', 'partial_assessment'):
return 'unexpected_review_type'
route = document['assessment']['route']
if route['source_sha256'] != source_digest:
return 'recording_mismatch'
if route['cp_sha256'] != vehicle_digest:
return 'vehicle_configuration_mismatch'
return None
def accept_finding(settings, reports, payload, *, authorized):
if (type(payload) is not dict or set(payload) != {'parameter', 'target', 'assessment'} or payload['parameter'] not in ROUTE_NAMES
or type(payload['target']) not in (int, float) or not math.isfinite(payload['target']) or
@@ -72,12 +94,9 @@ def accept_finding(settings, reports, payload, *, authorized):
if not directory.exists():
raise ValueError('The original drive review is unavailable. Refresh the findings.')
document = AssessmentCache(directory).get(assessment)
if document.get('kind') == 'identity_review':
raise ValueError('The vehicle must identify itself before a finding from this review can be accepted.')
route = document['assessment']['route']
if (document.get('kind') not in ('completed_assessment', 'partial_assessment') or
route['cp_sha256'] != car_params_digest(cp) or route['source_sha256'] != found[1]):
raise ValueError('The original drive review does not match this vehicle.')
issue = review_binding_issue(document, car_params_digest(cp), found[1])
if issue is not None:
raise ValueError(REVIEW_REFUSALS[issue])
from openpilot.starpilot.flm.learned_lifecycle import decode
scope = current_scope(cp, settings.params)
@@ -41,6 +41,8 @@ def _explanation(reason):
'Known vehicle and no manual coordinates required': 'This older build rejected its vehicle/settings identity before route analysis. In the parked ' +
'analysis path, missing or invalid recorded vehicle identity causes this refusal; it does not establish route corruption.',
'Valid manual coordinate settings required': 'Saved manual steering settings require review; existing choices were preserved.',
'Manual coordinate settings require review: context_changed':
'The saved steering settings do not match the vehicle configuration or controller for this recording.',
'partial_drive_provisional_only': 'Intact portions were analyzed. This partial recording can provide suggestions, not automatic changes.',
'bounded_trial_configured_for_next_drive': 'A bounded adjustment was saved for the next drive.',
'no_consistent_adjustment_in_completed_drive': 'The analyzed evidence did not support a consistent adjustment.',
@@ -66,6 +68,48 @@ def _result(value):
return result
def _finding_review(report, params, cache):
"""Compare retained findings to the cached parked configuration without exporting it."""
from opendbc.car.structs import car
from openpilot.starpilot.flm.manual_coordinates import load
from openpilot.starpilot.flm.offroad_surface import ROUTE_NAMES
from openpilot.starpilot.flm.runtime_adapter_registry import car_params_digest
from openpilot.starpilot.galaxy.flm_acceptance import review_binding_issue
from openpilot.starpilot.lateral.controller_selection import read_selection
from openpilot.starpilot.schema_cache import inspect_cache
preference = report.get('preference') or {}
if preference.get('valid') is not True or preference.get('parked') is not True:
return {'status': 'parked_configuration_unavailable'}
key = 'CarParamsPersistent'
snapshot = read_saved(params, key, 1024 * 1024)
raw, readable = snapshot
payload = inspect_cache(key, raw).payload if readable and raw is not None else None
if payload is None:
return {'status': 'parked_configuration_unavailable'}
with car.CarParams.from_bytes(payload, traversal_limit_in_words=1024 * 1024 // 8) as cp:
if cp.notCar or cp.carFingerprint != preference.get('vehicle'):
return {'status': 'parked_configuration_unavailable'}
digest = car_params_digest(cp)
_, manual_state = load(cp, read_selection(params, cp).mode, params)
details = (report.get('current') or {}).get('details') or {}
findings, checked = {}, {}
for name, review, source in details.get('Recorded suggestion assessments', ())[:len(ROUTE_NAMES)]:
if name not in ROUTE_NAMES:
continue
binding = (review, source)
if binding not in checked:
try:
checked[binding] = review_binding_issue(cache.get(review), digest, source) or 'matches_parked_configuration'
except (OSError, ValueError, TypeError, KeyError):
checked[binding] = 'assessment_unavailable'
findings[name] = checked[binding]
if (read_saved(params, key, 1024 * 1024) != snapshot
or read_saved(params, 'IsOffroad', 1) != (b'1', True)):
return {'status': 'parked_configuration_unavailable'}
return {'status': 'checked', 'scope': 'Stored parked configuration at download', 'manual_coordinates': manual_state, 'findings': findings}
def diagnostics(report, params):
current = report.get('current') or {}
details = current.get('details') or {}
@@ -120,6 +164,11 @@ def diagnostics(report, params):
files = list(directory.iterdir())
result['storage'] = {'status': 'readable', 'documents': len(files), 'bytes': sum(path.lstat().st_size for path in files)}
result['checkpoints'] = [_result(row['result']) for row in cache.checkpoints()]
if details.get('Recorded suggestion assessments'):
try:
result['finding_review'] = _finding_review(report, params, cache)
except (OSError, RuntimeError, ValueError, TypeError, KeyError, KjException):
result['finding_review'] = {'status': 'unavailable'}
except (OSError, ValueError, TypeError, KeyError) as error:
result['storage'] = {'status': 'unavailable', 'reason': _reason(error)}
result['storage']['scope'] = 'Parked route analysis in the current settings store only'
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "8ccaba1ab0f9c1daec467049a028f7893257dd6ec1b2f6ad763c9eb5e895fafd", "schema_version": 1}
{"protected_inventory_sha256": "58fff7c4909208cd803848183a254fdfa9f23e10eaa8aa07c16077bf410e37c2", "schema_version": 1}