fix: clamp negative turn duration penalties to prevent negative route durations#7416
Merged
DennisOSRM merged 1 commit intomasterfrom Mar 20, 2026
Merged
fix: clamp negative turn duration penalties to prevent negative route durations#7416DennisOSRM merged 1 commit intomasterfrom
DennisOSRM merged 1 commit intomasterfrom
Conversation
…5967) Negative turn duration penalties were not being clamped during traffic updates or at extraction time, unlike turn weight penalties. This caused edge durations to go negative, producing physically impossible negative route durations. Changes: - src/updater/updater.cpp: Clamp turn duration penalty in update_edge using num_nodes as the floor (mirrors existing weight clamping). Add logWARNING when a negative turn duration penalty would underflow. - src/extractor/scripting_environment_lua.cpp: Clamp turn.duration at extraction time in ProcessTurn with a lower bound of -GetMaxTurnWeight(), preventing int16_t overflow and matching the existing upper-bound handling of turn.weight. - features/testbot/traffic_turn_penalties.feature: Add reproducer scenario for issue #5967 (penalty -70 on middle turn, verifying duration is clamped to positive). Update two existing speed expectations (72->71 km/h) to match the corrected behaviour where negative penalties are no longer silently swallowed by the phantom-node first-edge clamp in routing_base.hpp. Fixes #5967 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Issue
Fixes #5967
Negative turn duration penalties were not being clamped during traffic updates or at extraction time, unlike turn weight penalties which were. This caused
edge.data.durationto go negative, producing physically impossible negative route durations.Was this change primarily generated using an AI tool? Yes — GitHub Copilot (claude-sonnet-4.6) was used to assist with analysis, implementation, and test writing.
Tasklist
Requirements / Relations
No other PRs required.
Changes
src/updater/updater.cpp— core fix (traffic update path):update_edge, clamp the turn duration penalty usingnum_nodesas the floor (deciseconds), mirroring the existing weight clamping block. Log a warning when the penalty is too negative.updateTurnPenalties, add alogWARNINGfor negativeturn_duration_penaltyvalues (mirrors existing weight warning).src/extractor/scripting_environment_lua.cpp— extraction-time fix:ProcessTurn, clampturn.durationto-MAXIMAL_TURN_PENALTY / 10.0(seconds). This prevents int16_t overflow and keeps durations in a physically meaningful range. Uses the fixed decisecond resolution (÷10), notGetMaxTurnWeight()which is scaled byweight_precisionand only applies to weights.features/testbot/traffic_turn_penalties.feature— tests:-70on a middle turn that would yield-10stotal without the fix, now correctly produces~40s.c→gspeed expectations from72 km/h→71 km/h. The old code masked the negative penalty via a phantom-node first-edge clamp inrouting_base.hpp; with the fix applied upstream the route is 0.1s longer, changing the truncated speed by 1 km/h.Testing
All 363 testbot scenarios pass with MLD. Turn penalty feature file also verified with CH.