fix(table): no negative or overflowed values between nearby snapped points #7766
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #7766"
general
weight: 0.35
kucukaslan
Issue
Refs #5855 and #6852.
Two snapped points on one directed road can get equal integer weight offsets, because each partial offset is truncated on its own. When the target lies behind the source, the table search sees a graph weight of zero instead of a negative one, and it accepts the backwards pairing as a direct path. Duration and distance are truncated separately, so they can come out negative:
-0.1s becomes214748364.6s oncescale_factor=1.6hits the overflow guard.-2s.The snapped distances also had two float problems of their own, which gave
-0.5m on a legal path between two points on a long road.I've benefited from all the AI tools I had on my hands including but not limited to Codex 6. Astra, Sol; Gemini 4 Neon, Claude 5. Opus, Sonnet :robot:
Fix
1. Compare the exact position at a zero-weight seed meeting
The table now does what
requiresForwardForceandrequiresBackwardForcedo for point-to-point routing, but it compares positions on the geometry instead of rounded weights, which can tie.Where:
isSourceDownstream()inmany_to_many.hpp. It is called from three places, and only when all of these hold:parent == nodeon the heap entry and the bucket; in MLD one-to-many, the manual first step at a node that is also a target,at_start).So the extra work is two short scans of the candidate lists, on a rare path. There is no benchmark.
Call sites:
| File | Search | Shape |
|---|---|---|
|
many_to_many_ch.cppforwardRoutingStep| CH many-to-many | all ||
many_to_many_mld.cppforwardRoutingStep| MLD many-to-many, forward and reverse | square, rectangular ||
many_to_many_mld.cpponeToManySearch| MLD one-to-many and many-to-one | 1×N, N×1 |If the source is downstream, the meeting is rejected like a negative one. CH then tries the node's loop edge, so
addLoopWeight's assert is relaxed from< 0to<= 0. MLD skips the meeting, and the search finds the detour elsewhere or leaves the cell unreachable.forwardRoutingStepgetscandidates_listandtarget_indices, because a bucket only stores the target column, not its phantoms.Why not check the signs of duration and distance? The first version of this PR did that. Review showed that an area approach walk hides it. Only the approach weight is subtracted before the check. Approach duration and distance stay in the totals. In the plaza scenario, the backwards road stretch is -0.084 m and the walk is 6.49 m, so the total stays positive and the table reports 6.4 m. The legal path is 6.6 m.
2. Three new
PhantomNodefields (92 → 104 bytes)The existing fields cannot order two points that tie:
locationis rounded to the 1e-6 coordinate grid, so two projections closer than one grid step get the same location,fwd_segment_positioncounts every geometry segment, including empty ones.| Field | Why |
|---|---|
|
double order_ratio| The exact, unrounded ratio from the projection on the segment. Ratio 1 is stored as ratio 0 on the next segment, so the same position always compares equal, whichever segment it was snapped from. ||
std::uint16_t forward_order_segment| The number of segments before the point that have a length, a weight or a duration in the forward direction. ||
std::uint16_t reverse_order_segment| The same for the reverse direction. |The geometry keeps a zero-length segment where compression removed a node. It holds the node's penalty, such as a traffic signal. Without a penalty it is empty, and two points on either side of it are at one position. With a penalty it separates them, because passing it takes time. A penalty can apply in one direction only, so each direction keeps its own count.
uint16_tmatchesfwd_segment_position.3. A distance that grows with the position
distanceAlongSegment()incoordinate_calculation, used ingeospatial_query.hpp.The distance to a snapped point was measured to its rounded coordinate with
greatCircleDistance. That picks its scale by the mean latitude of the two coordinates, and the scale changes every 0.05°. Two points 0.3 m apart on a 4 km road could get different scales, and the earlier one got the larger distance.The new function measures to the exact point at the ratio, using the scale of the whole segment. The distance therefore grows with the ratio and never exceeds the segment's length. The reverse distance is the length minus this distance. The ratio is in Web Mercator, so the function maps the point back to WGS84 rather than computing
length ratio, which is wrong on long segments at high latitudes.4. Reverse offset summed from the end
The forward offset adds segments from the start of the geometry. The reverse offset added them from the point toward the end, so two points summed the same segments in a different order. After a 2,200 km segment, the 0.1 m segments were lost in rounding for one point but not the other. The reverse offset is now summed from the end, the same way as the forward one.
Edge cases
Covered:
scale_factor1 and 1.6Not covered:
requiresForwardForceandrequiresBackwardForceon rounded weights. Moving them to the new position compare is a behaviour change for those plugins, so it is left for a follow-up. Trip's matrix goes through the table and is fixed.forwardRoutingStepupdates weight, duration and distance with separatestd::mincalls, so a cell can mix values from two paths. This is on master, this PR leaves it alone, and no test shows a wrong result from it.PhantomNodegrows by 12 bytes. Computing the position on demand from the facade would avoid that, but it is a larger change.Tests
The tests assert routing results, not internal offsets. Most scenarios send four request shapes: square, one source, one target, and rectangular. Each one reaches a different search in MLD (
manyToManyforward,oneToManyforward,oneToManyreverse,manyToManyreverse), so they are not repeats of each other.caruses the real profile, for side-road penalties and traffic signals.testbotgives exact control over the geometry, the speeds and the speed files."Fails on base" was measured on the merge base
364ddca49, with CH and MLD under mmap. The results are the same for both.| Feature | Scenario | What it pins | Fails on base |
|---|---|---|---|
| car | Nearby reachable points retain positive durations when scaled (scale 1, 1.6) | the original bug, both directions; scale 1.6 hits the overflow guard | yes |
| car | Nearby points with zero rounded duration still have positive distance | the distance is kept when the duration rounds to 0 | yes |
| car | Equal rounded weights do not allow travel against a one-way road | unreachable, not negative, on forward segments | yes |
| car | … against a reversed one-way road | the same on reverse segments | yes |
| car | Nearby points on a one-way loop take the reachable detour | a rejected meeting still finds the 3900 m detour | yes |
| car | A traffic signal between two points at one node keeps their order |
forward_order_segmentcounts the zero-length penalty segment | yes || car | … on a reversed one-way road | the same for
reverse_order_segment| yes || foot | An approach walk cannot hide backwards travel on the road | why sign checks are not enough | yes |
| testbot | A junction keeps its legal alternatives when a zero-cost pairing is backwards | only the backwards pairing is rejected; the loop is used | yes |
| testbot | Unrelated junction candidates do not make reverse one-way travel reachable |
isSourceDownstreampicks the phantom at the meeting node | yes || testbot | Points that snap to the same rounded coordinate keep their order (scale 1, 1.6) | needs
order_ratio, notlocation| yes || testbot | A backwards path on a two-way road does not replace the legal path (scale 1, 1.6) | a cheaper backwards path cannot replace the legal one | yes |
| testbot | … same rounded coordinate … on a reversed one-way road (scale 1, 1.6) | the reverse count and direction | yes |
| testbot | Points far apart with equal rounded weights keep their order | ties are not only sub-metre, so no distance tolerance would work | yes |
| testbot | Points on a long road keep a positive distance where the distance scale changes |
distanceAlongSegment| yes || testbot | A long segment before short segments keeps a positive reverse distance | reverse offset summed from the end | yes |
| testbot | Adjacent snapped segments at the same vertex need no detour | guard: ratio 1 equals ratio 0 on the next segment | no |
| testbot | Points on opposite sides of the road share one position | guard: one position costs 0 both ways | no |
| testbot | A point on a long road at a high latitude has the same distance in the table and the route | guard: no
length ratioshortcut | no || testbot | Returning to the same coordinate does not erase intervening travel | guard: the order segment, not the coordinate, decides | no |
On base, 20 of the 24 scenario runs fail. The four guards pass on base by design: they make sure the fix does not reject legal zero-cost paths and does not break distances.
Validation
6ccde60c2, 83 scenarios pass in all six configurations: CH and MLD × mmap, directly and datastore. They come from the threetable_quantizationfeatures,foot/area_table_trip,testbot/distance_matrixandtestbot/duration_matrix.Tasklist
- [x] self-review code for correctness and following the coding guidelines
- [x] add tests (see testing)
- [ ] review
- [ ] adjust for comments
Requirements / Relations
Scoped to the table search and phantom snapping. It does not claim to resolve every routing issue in #5855 or #6852. No query parameters, response formats, profiles or dataset formats change.