From b5b3b8b80f9c7aa7f720dc95e76ab0586b76802e Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:27:05 -0600 Subject: [PATCH] Keep FLM vehicle status stable and explain parked analysis waits --- openpilot/starpilot/galaxy/tests/test_flm.mjs | 22 +++++++++++++++++++ .../tests/test_flm_training_results.mjs | 18 +++++++++++++++ .../galaxy/web/js/flm-training-results.js | 13 +++++++++++ openpilot/starpilot/galaxy/web/js/flm.js | 7 +++++- prebuilt.json | 2 +- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/openpilot/starpilot/galaxy/tests/test_flm.mjs b/openpilot/starpilot/galaxy/tests/test_flm.mjs index eb1d1df087..6e3c201ef7 100644 --- a/openpilot/starpilot/galaxy/tests/test_flm.mjs +++ b/openpilot/starpilot/galaxy/tests/test_flm.mjs @@ -102,6 +102,28 @@ function instance() { for (const [name, method] of Object.entries(FlmPage.computed)) Object.defineProperty(vm, name, { get: () => method.call(vm) }) return vm } +const drivingStatus = instance() +drivingStatus.receivedAt = 10000 +drivingStatus.report = { ...report(), preference: { ...choice, parked: false } } +for (const age of [.2, 2.1, .1, 3, .5]) { + drivingStatus.now = 10000 + drivingStatus.report.current.ageSeconds = age + assert.equal(drivingStatus.connectionState, 'Driving', 'A late learner report cannot erase fresh vehicle status') + assert.equal(drivingStatus.currentApplied, false, 'Driving status does not claim a saved tune or current application') +} +drivingStatus.report = { ...value, preference: { ...choice, parked: false } } +assert.equal(drivingStatus.connectionState, 'Learned tune in use') +drivingStatus.report.current.ageSeconds = 3 +assert.equal(drivingStatus.connectionState, 'Driving', 'Stale application evidence cannot keep an in-use claim') +drivingStatus.report.current.ageSeconds = .1 +drivingStatus.report.preference.parked = true +assert.equal(drivingStatus.connectionState, 'Parked') +drivingStatus.now = 12100 +assert.equal(drivingStatus.connectionState, 'Waiting for vehicle status', 'Stale vehicle status is never kept as current') +drivingStatus.now = 10000; drivingStatus.error = 'offline' +assert.equal(drivingStatus.connectionState, 'Waiting for vehicle status') +assert.match(FlmPage.template, /connectionState/) +assert.doesNotMatch(FlmPage.template, /Driving · use not confirmed|State not confirmed/) const originalFetch = globalThis.fetch, originalDocument = globalThis.document try { globalThis.document = { getElementById: () => null, hidden: false, addEventListener() {}, removeEventListener() {} } diff --git a/openpilot/starpilot/galaxy/tests/test_flm_training_results.mjs b/openpilot/starpilot/galaxy/tests/test_flm_training_results.mjs index d812ef7eb9..4c97e801bc 100644 --- a/openpilot/starpilot/galaxy/tests/test_flm_training_results.mjs +++ b/openpilot/starpilot/galaxy/tests/test_flm_training_results.mjs @@ -73,6 +73,24 @@ assert.equal(offroadView(completed).evidenceDrives, null, 'Older reports must no assert.equal(tunerStatus(completed, true, true).title, 'Completed drive analyzed', 'Parked status must not mask completed analysis') assert.match(tunerStatus(completed, true, true).description, /left your tune unchanged/) assert.equal(completed.current.application.applied, false) +const ignitionWait = { ...report(), preference: { version: 1, valid: true, enabled: true, parked: true, + vehicle: 'TOYOTA_RAV4_PRIME', controller: 'torque' } } +ignitionWait.current.reason = 'waiting_for_ignition_off' +const waitingStatus = tunerStatus(ignitionWait, false, true, '', true) +assert.equal(waitingStatus.title, 'Waiting to analyze your drive') +assert.match(waitingStatus.description, /ignition on.*ignition turns off/) +assert.equal(ignitionWait.current.application.applied, false) +assert.notEqual(tunerStatus(ignitionWait, false, true, '', false).key, 'waiting-parked', 'An old blocker is not current permission evidence') +for (const reason of ['waiting_for_valid_deviceState', 'waiting_for_fresh_pandaStates', 'waiting_for_vehicle_offroad', + 'waiting_for_vehicle_to_switch_off', 'waiting_for_connected_panda_status', 'waiting_for_panda_controls_to_disarm', + 'waiting_for_panda_fault_to_clear', 'waiting_for_shutdown_to_finish', 'waiting_for_parked_permission']) { + ignitionWait.current.reason = reason + assert.equal(tunerStatus(ignitionWait, false, true, '', true).key, 'waiting-parked', reason) +} +ignitionWait.preference.parked = false +assert.notEqual(tunerStatus(ignitionWait, true, true, '', true).key, 'waiting-parked') +ignitionWait.preference.parked = true; ignitionWait.preference.enabled = false +assert.equal(tunerStatus(ignitionWait, false, true, '', true).key, 'off') const earlierDrive = structuredClone(completed) Object.assign(earlierDrive.current.details, { 'Latest completed recording reviewed': 'declared-newer-manual-drive', diff --git a/openpilot/starpilot/galaxy/web/js/flm-training-results.js b/openpilot/starpilot/galaxy/web/js/flm-training-results.js index 0ec8f1c088..68e59abd4a 100644 --- a/openpilot/starpilot/galaxy/web/js/flm-training-results.js +++ b/openpilot/starpilot/galaxy/web/js/flm-training-results.js @@ -258,6 +258,17 @@ const REASONS = { accepted_target_currently_acknowledged: "The controller acknowledged the accepted correction.", } export function learningReason(reason) { + if (reason === 'waiting_for_ignition_off' || reason === 'waiting_for_vehicle_to_switch_off') + return 'The vehicle interface still reports ignition on. Drive analysis starts after the ignition turns off.' + if (/^waiting_for_(valid|fresh)_(deviceState|pandaStates|peripheralState)$/.test(reason)) + return 'Waiting for current vehicle status before analyzing the recorded drive.' + if (reason === 'waiting_for_controls_to_disengage' || reason === 'waiting_for_panda_controls_to_disarm') + return 'Drive analysis is waiting for steering controls to disengage.' + if (reason === 'waiting_for_panda_fault_to_clear') return 'Drive analysis is paused while the vehicle interface reports a fault.' + if (reason === 'waiting_for_connected_panda_status') return 'Waiting for the vehicle interface before analyzing the recorded drive.' + if (reason === 'waiting_for_shutdown_to_finish') return 'Drive analysis is waiting for shutdown to finish.' + if (reason === 'waiting_for_vehicle_offroad' || reason === 'waiting_for_parked_permission') + return 'Drive analysis is waiting for the vehicle to be offroad.' if (reason === 'vehicle_identity_unavailable') return 'This drive was reviewed on its own. Automatic saving is waiting for the car to identify itself.' if (reason === "Assessment cache full") return "FLM ran out of space in its review history. The latest analysis could not be saved; this does not mean your saved tune was erased." if (Object.hasOwn(REASONS, reason)) return REASONS[reason] @@ -415,6 +426,8 @@ export function tunerStatus(report, live = false, choiceLive = false, error = "" return { key: "off", tone: "muted", title: "Auto Learn is off", description: "No driving samples are being collected by the learner. Turn it on in steering settings to begin." } if (reportFresh && current?.status === 'fitting' && ['analyzing_last_completed_drive', 'checking_recorded_steering_recommendations'].includes(current.reason)) return { key: 'fitting', tone: 'active', title: 'Analyzing your drive', description: learningReason(current.reason) + (offroadView(report)?.retained ? ' Earlier drive findings remain below while this analysis runs.' : '') } + if (reportFresh && preference?.valid && preference.enabled && preference.parked && current?.reason?.startsWith('waiting_for_')) + return { key: 'waiting-parked', tone: 'muted', title: 'Waiting to analyze your drive', description: learningReason(current.reason) } const route = reportFresh && (!preference || preference.parked) ? offroadView(report) : null if (route) { if (route.partial) diff --git a/openpilot/starpilot/galaxy/web/js/flm.js b/openpilot/starpilot/galaxy/web/js/flm.js index 870b84ef26..866e99fee1 100644 --- a/openpilot/starpilot/galaxy/web/js/flm.js +++ b/openpilot/starpilot/galaxy/web/js/flm.js @@ -117,6 +117,11 @@ export const FlmPage = { }, connectionTone() { return this.error || !this.choiceLive ? 'muted' : this.preference?.enabled ? 'ready' : 'muted' }, + connectionState() { + if (!this.choiceLive) return 'Waiting for vehicle status' + if (this.preference.parked) return 'Parked' + return this.currentApplied ? 'Learned tune in use' : 'Driving' + }, current() { return this.report?.current }, preference() { return validLearningPreference(this.report?.preference) ? this.report.preference : null }, choiceLive() { return !this.error && !!this.preference && Math.max(0, this.now - this.receivedAt) <= 2000 }, @@ -392,7 +397,7 @@ export const FlmPage = {

{{ parameterLabel(findingDraft.parameter) }}: {{ dialPercent(findingDraft.target) }}

Use this value for your next drive. Auto Learn can keep improving this setting.

-
{{ connectionLabel }}{{ currentApplied ? 'Learned tune in use' : preference?.parked ? 'Parked' : live ? 'Driving · use not confirmed' : 'State not confirmed' }}
+
{{ connectionLabel }}{{ connectionState }}

Reset manual tune?

{{ manualState.pending.question }}