From 25ca42a8cebf64498cde471ab16855c6dff255bb Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:30:56 -0600 Subject: [PATCH] Recover Galaxy recording dates from late GPS fixes --- openpilot/starpilot/galaxy/drive_analysis.py | 31 +++++++++++++------ .../galaxy/tests/test_drive_analysis.py | 22 +++++++++++-- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/openpilot/starpilot/galaxy/drive_analysis.py b/openpilot/starpilot/galaxy/drive_analysis.py index 3039bb7766..19451c36eb 100644 --- a/openpilot/starpilot/galaxy/drive_analysis.py +++ b/openpilot/starpilot/galaxy/drive_analysis.py @@ -27,7 +27,7 @@ MAX_SPEED_MPS = 70.0 # Route bytes are processed one bounded segment at a time, never concatenated. # Admit long recordings above the old 256 MiB cap without unbounded offroad work. MAX_ROUTE_COMPRESSED_BYTES = 1024 * 1024 * 1024 -ANALYSIS_VERSION = 7 +ANALYSIS_VERSION = 8 MAX_MODEL_METADATA_SECONDS = 4.0 DISTRACTED_EVENT = 'driverDistracted2' UNRESPONSIVE_EVENT = 'driverUnresponsive3' @@ -362,7 +362,9 @@ def analyze_route(root: Path, route: dict, *, permitted: Callable[[], bool], pre car_pairs = state_pairs = 0 coverage_gap = False end_of_route = False - clocks_offset = None + clocks_offset = gps_offset = None + gps_conflict = False + latest_wall_time = datetime.now(UTC).timestamp() + 86400 model = None model_outputs = [] model_loads = [] @@ -385,7 +387,8 @@ def analyze_route(root: Path, route: dict, *, permitted: Callable[[], bool], pre try: events = decode_segment(compressed, codec, cancelled=lambda: not allowed(), retain=frozenset(('clocks', 'initData', 'logMessage', 'modelV2', 'drivingModelData', - 'carState', 'selfdriveState', 'carControl', 'onroadEvents', 'sentinel'))) + 'carState', 'selfdriveState', 'carControl', 'onroadEvents', 'sentinel', + 'gpsLocation', 'gpsLocationExternal'))) except LogDecodeCancelled: raise except LogDecodeError: @@ -406,12 +409,21 @@ def analyze_route(root: Path, route: dict, *, permitted: Callable[[], bool], pre if stamp <= 0 or not event.valid: continue if kind == 'clocks': - wall = int(event.clocks.wallTimeNanos) - if 946684800 * 1_000_000_000 <= wall <= (datetime.now(UTC).timestamp() + 86400) * 1_000_000_000: - offset = (wall - stamp) / 1e9 + wall = event.clocks.wallTimeNanos / 1e9 + if 946684800 <= wall <= latest_wall_time: + offset = wall - stamp / 1e9 if clocks_offset is not None and abs(offset - clocks_offset) > 5: raise _Incomplete('Conflicting logged wall clocks') clocks_offset = offset if clocks_offset is None else clocks_offset + elif kind in ('gpsLocation', 'gpsLocationExternal'): + gps = getattr(event, kind) + wall = gps.unixTimestampMillis / 1e3 + if gps.hasFix and 946684800 <= wall <= latest_wall_time: + offset = wall - stamp / 1e9 + if gps_offset is None: + gps_offset = offset + elif abs(offset - gps_offset) > 5: + gps_conflict = True elif kind == 'initData' and model is None: model = _recorded_model(event.initData) elif kind == 'logMessage': @@ -497,10 +509,9 @@ def analyze_route(root: Path, route: dict, *, permitted: Callable[[], bool], pre if last <= first: raise _Incomplete('Route has no observed duration') duration = (last - first) / 1e9 - if clocks_offset is not None: - start_time = first / 1e9 + clocks_offset - else: - start_time = _route_wall_time(route_id) + if clocks_offset is None and not gps_conflict: + clocks_offset = gps_offset + start_time = first / 1e9 + clocks_offset if clocks_offset is not None else _route_wall_time(route_id) if start_time is not None: result['startTime'] = start_time result['endTime'] = start_time + duration diff --git a/openpilot/starpilot/galaxy/tests/test_drive_analysis.py b/openpilot/starpilot/galaxy/tests/test_drive_analysis.py index 5fd77955b1..cee86b5fc3 100644 --- a/openpilot/starpilot/galaxy/tests/test_drive_analysis.py +++ b/openpilot/starpilot/galaxy/tests/test_drive_analysis.py @@ -31,8 +31,8 @@ def event(kind, stamp, **fields): return message -def write(root, number, events, *, lock=False, kind='rlog'): - name = f'{ROUTE}--{number}' +def write(root, number, events, *, lock=False, kind='rlog', route=ROUTE): + name = f'{route}--{number}' segment = root / name segment.mkdir() (segment / f'{kind}.zst').write_bytes(zstd.compress(b''.join(item.as_reader().as_builder().to_bytes() for item in events))) @@ -46,6 +46,24 @@ def selection(*segments): class DriveAnalysisTest(unittest.TestCase): + def test_recovers_route_date_from_late_gps_fix_after_invalid_boot_clock(self): + corrected = 1_790_334_400 + final = BASE + 500_000_000 + for has_fix in (True, False): + with self.subTest(has_fix=has_fix): + root = self.root / str(has_fix) + root.mkdir() + boot_clock = event('clocks', BASE, wallTimeNanos=1_760_534_400_000_000_000) + boot_clock.valid = False + events = [boot_clock, *self.sample(BASE, 10, True), *self.sample(final, 10, True), + event('gpsLocationExternal', final, unixTimestampMillis=corrected * 1000 + 500, hasFix=has_fix), + event('sentinel', final, type='endOfRoute')] + route = '00000009--f93c55a690' + segment = write(root, 0, events, route=route) + result = analyze_route(root, dict(selection(segment), routeId=route), permitted=lambda: True) + self.assertEqual(result['complete'], has_fix, result) + self.assertEqual(result['startTime'], corrected if has_fix else None) + def test_dashboard_recovers_prefix_before_locked_and_empty_tail_without_changing_logs(self): first = write(self.root, 0, [*self.sample(BASE, 10, True), *self.sample(BASE + 500_000_000, 10, True), event('sentinel', BASE + 500_000_000, type='endOfSegment')], kind='qlog')