Skip to content

Conversation

@binh-dam-ibigroup
Copy link
Contributor

Summary

Proposing to improve handling of added trips in GTFS-rt feeds that don't exist in the static schedule by guessing the service date. This will address an NPE that prevents portions of a trip update feed to be processed entirely.

Issue

Fix #7177
Related: #7008 and #6176

Unit tests

Added

Documentation

N/A

Changelog

The changelog file
is generated from the pull-request title, make sure the title describe the feature or issue fixed.
To exclude the PR from the changelog add the label +Skip Changelog to the PR.

Bumping the serialization version id

Not needed.

@binh-dam-ibigroup binh-dam-ibigroup requested a review from a team as a code owner January 7, 2026 22:22
@binh-dam-ibigroup binh-dam-ibigroup changed the title fix(RealtimeVe...Matcher): Infer service date if staticTripTimes miss… Infer service date if staticTripTimes missing Jan 7, 2026
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.16%. Comparing base (5b12871) to head (fa72449).
⚠️ Report is 1 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #7179      +/-   ##
=============================================
- Coverage      72.17%   72.16%   -0.01%     
+ Complexity     20878    20876       -2     
=============================================
  Files           2273     2273              
  Lines          84437    84440       +3     
  Branches        8424     8424              
=============================================
- Hits           60942    60940       -2     
- Misses         20519    20522       +3     
- Partials        2976     2978       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leonardehrenfried leonardehrenfried changed the title Infer service date if staticTripTimes missing Infer vehicle position's service date for ADDED trip Jan 8, 2026
@leonardehrenfried
Copy link
Member

Can you fix the build?

Copy link
Contributor

@miklcct miklcct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see test cases for both resolving to today and yesterday.

// yesterday, today or tomorrow. whichever one has the lowest "distance" to now is guessed to be
// the service day of the undated vehicle position
// if this is concerning to you, you should put a start_date in your feed.
return Stream.of(yesterday, today, tomorrow)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a daily journey spans over 24 hours (or close to it and delayed), this distance match may result in matching today's unstarted trip rather than the trip currently in progress. Is this a concern or such feeds are so rare that they should put in a start_date anyway in their feed? (This is just a general comment and I am not requesting a change on this.)

@@ -373,6 +380,17 @@ void inferServiceDateCloseToMidnight() {
assertEquals(LocalDate.parse("2022-04-04"), inferredDate);
}

Copy link
Contributor

@miklcct miklcct Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also add a test case where the vehicle position is given in the morning after daytime routes have typically started, resolving to today rather than yesterday?

@miklcct
Copy link
Contributor

miklcct commented Jan 13, 2026

Also, after some thinking, I believe this is not the correct way to fix the bug and it will cause an incorrect match with a valid feed.

Trip Update:
NEW trip X12345 which runs from 00:00 to 06:00, without a date given in the feed. Current time now is 01:00.
In this case, the GTFS-RT updater will guess that the trip runs right now today.

serviceDate = tripDescriptor.startDate().orElse(localDateNow.get());

Vehicle position.
Vehicle position for X12345 is given without a date. This PR will guess it to yesterday, resulting in an incorrect match.

I think that the correct way to fix this issue is to use the real-time timetable data (which is an overlay on the static data) in guessing the service date to identify the service date it runs. In case, the X12345 only runs today (as it is added by the updater) so it should be today.

If the trip ID can be found but there is no service for yesterday, today or tomorrow for this trip ID, the vehicle position should be discarded in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException for GTFS-rt added trips not in static feed

3 participants