Handle preparation-time errors separately from other booking errors - #696
Draft
nilspenzel wants to merge 12 commits into
Draft
nilspenzel wants to merge 12 commits into
nilspenzel wants to merge 12 commits into
Conversation
The intend is to ensure the code has to time to run before the offer expires
nilspenzel
marked this pull request as draft
September 28, 2026 21:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a strategy for exiting early when the intended booking is no longer possible due to insufficient preparation time, even though whitelisting was successful.
During whitelisting, we compute for each option the exact point in time until which the request will not be declined due to preparation time. This expiration time is passed through the planAndSign pipeline and added to the signature of the resulting ODM leg.
When the user clicks the button that triggers the call to bookingApi, we check whether the offer has already expired. If it has, we immediately return an error message without counting it as a booking error, avoiding noise in developer alerts.
This also allows us to inform the user when the offer will expire.
There are still two sources of inaccuracy in the computation of the expiration time:
The Date.now() call used for the early-exit check happens earlier than the Date.now() call used for the preparation-time check. I intend to address this by introducing a small buffer (e.g. 30 seconds).
Before this PR, promisedTimes are derived from the leg and are therefore rounded to full minutes by MOTIS. This requires corresponding rounding logic around the preparation-time check causing inaccuracy in the computation of the time the offer will expire.
I intend to address the second point by deriving promisedTimes from the exact values passed through the planAndSign pipeline via tripId instead. This is not yet implemented at the time of creating this PR.