Repository navigation
refactor(hints): replace PhantomNode in SegmentHint with fixed placeholder - #7649
Conversation
… of 0 sentinel Replace the ambiguous 'return 0 to mean not found' pattern in IntersectionHandler::findObviousTurn with std::optional<std::size_t>. The sentinel value 0 was overloaded - it both represents the u-turn approach road (intersection[0]) and 'no obvious turn found'. Update all four call sites in turn_handler.cpp and sliproad_handler.cpp to use optional truthiness checks and dereferences. Fixes #3337.
… alignment Guard to_index_if_valid against returning index 0 (the u-turn approach road) as a valid obvious turn. This ensures the call-site truthiness checks (!obvious_index / if (obvious_index)) are semantically identical to the old 0-sentinel checks — an engaged optional now always means a non-u-turn road was found. Also fix clang-format-18 alignment in the declaration.
…older Hints are deprecated and ignored by the server on consumption. They are still generated for API backward compatibility. Replace the 80-byte PhantomNode copy in SegmentHint with a fixed-size std::array<unsigned char, 80> placeholder, removing the compile-time dependency between hint serialization and PhantomNode internals. This allows PhantomNode to change freely without breaking the hint wire format or requiring all clients to update cached hints. Also fix a transitive include in table_parameters.hpp which was relying on hint.hpp -> phantom_node.hpp -> util/typedefs.hpp.
There was a problem hiding this comment.
Pull request overview
This PR decouples hint wire-format serialization from engine::PhantomNode by turning SegmentHint into a fixed-size deprecated placeholder while preserving the existing Base64 size for backward compatibility. It also modernizes “obvious turn” detection to use std::optional instead of a 0 sentinel.
Changes:
- Replace
SegmentHint’s embeddedPhantomNodewith a fixed 80-byte placeholder and keep checksum-only validation/roundtrips. - Stop populating real PhantomNode data when generating response hints (placeholders only).
- Refactor
findObviousTurnto returnstd::optional<std::size_t>and update guidance handlers accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| include/engine/hint.hpp | Removes PhantomNode coupling; introduces fixed-size deprecated placeholder storage and size assertions. |
| src/engine/hint.cpp | Simplifies hint validity and equality semantics to placeholder-bytes + checksum. |
| include/engine/api/base_api.hpp | Generates placeholder segment hints instead of copying real phantom data into hints. |
| include/engine/api/table_parameters.hpp | Adds missing direct include (util/typedefs.hpp) to avoid reliance on removed transitive includes. |
| include/guidance/intersection_handler.hpp | Changes findObviousTurn to return std::optional<std::size_t> (no more 0 sentinel). |
| src/guidance/turn_handler.cpp | Updates turn handling logic to consume optional obvious-index correctly. |
| src/guidance/sliproad_handler.cpp | Updates sliproad logic and obvious-index propagation to use optional. |
| unit_tests/engine/base64.cpp | Updates hint tests to reflect checksum-only placeholder semantics and correct bytewise sizing. |
| unit_tests/server/parameters_parser.cpp | Updates parameter parsing tests to stop depending on PhantomNode fields in hints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Hints are deprecated; always report as valid to avoid rejecting requests | ||
| // that still include hints from older responses. | ||
| return facade.GetCheckSum() == data_checksum; |
There was a problem hiding this comment.
Fixed — updated the comment to say "only validate via dataset checksum" instead of "always report as valid."
| bool Hint::IsValid(const util::Coordinate /*new_input_coordinates*/, | ||
| const datafacade::BaseDataFacade &facade) const | ||
| { | ||
| // Hints are deprecated; always report as valid. |
There was a problem hiding this comment.
Fixed — updated the comment to say "validate each segment hint via checksum-only check" instead of "always report as valid."
Format std::all_of call and inline short function bodies to match clang-format-18 style.
d431887 to
c3ce0cd
Compare
There was a problem hiding this comment.
Fixed — updated both comments to accurately describe checksum-only validation instead of claiming "always report as valid."
Address review feedback: the comments claimed 'always report as valid' but the implementation still rejects hints when the dataset checksum differs. Update both SegmentHint::IsValid and Hint::IsValid comments to accurately describe the checksum-only behavior.
The service files were transitively depending on hint.hpp -> phantom_node.hpp -> boost/assert.hpp for BOOST_ASSERT. Since hint.hpp no longer includes phantom_node.hpp, add the include directly to each file that uses BOOST_ASSERT.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7649 +/- ##
==========================================
+ Coverage 94.12% 94.15% +0.02%
==========================================
Files 483 484 +1
Lines 37723 37690 -33
==========================================
- Hits 35508 35487 -21
+ Misses 2215 2203 -12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…offset Snapping a coordinate that falls inside an open area charges the walk to the vertex it snapped to. That cost was folded into the phantom's weight offset, and a search seeds a source with the negation of the offset and a target with the offset itself, so one stored number had to mean both signs. Which sign it got was decided by the coordinate's place in the request: first is a departure, last an arrival. That holds for a route and nothing else. Every coordinate of a table is a source and a destination at once, so half the matrix was charged the wrong way round, and so is a via point, where charging it as a departure made the leg arriving there seed a negative key that CH asserts against. A trip is the same case for all of its coordinates, since the tour returns to the first, and had to opt out of the charge entirely to avoid the crash. The walk now lives on the phantom in three fields of its own, and the seeding accessors add it in either role. Nothing has to know which end of a journey a coordinate is in order to cost it, the sign is fixed by the accessor rather than by the caller, and the opt-out in the trip plugin is gone. `sizeof(PhantomNode)` goes from 80 to 92 bytes. Nothing public moves with it: #7649 replaced the PhantomNode inside SegmentHint with a fixed 80 byte placeholder, so the hint string stays 112 characters. The candidate's *shape* still follows its position, and still has to: a phantom departed from stands at an edge-based node's start, one arrived at at its end, and a coordinate that is both can only have one. A table cell with one end on a plaza is therefore still short by the stretch between the candidate and the node boundary. Tracked in #7683 with what it would take to finish.
…offset Snapping a coordinate that falls inside an open area charges the walk to the vertex it snapped to. That cost was folded into the phantom's weight offset, and a search seeds a source with the negation of the offset and a target with the offset itself, so one stored number had to mean both signs. Which sign it got was decided by the coordinate's place in the request: first is a departure, last an arrival. That holds for a route and nothing else. Every coordinate of a table is a source and a destination at once, so half the matrix was charged the wrong way round, and so is a via point, where charging it as a departure made the leg arriving there seed a negative key that CH asserts against. A trip is the same case for all of its coordinates, since the tour returns to the first, and had to opt out of the charge entirely to avoid the crash. The walk now lives on the phantom in three fields of its own, and the seeding accessors add it in either role. Nothing has to know which end of a journey a coordinate is in order to cost it, the sign is fixed by the accessor rather than by the caller, and the opt-out in the trip plugin is gone. `sizeof(PhantomNode)` goes from 80 to 92 bytes. Nothing public moves with it: #7649 replaced the PhantomNode inside SegmentHint with a fixed 80 byte placeholder, so the hint string stays 112 characters. The candidate's *shape* still follows its position, and still has to: a phantom departed from stands at an edge-based node's start, one arrived at at its end, and a coordinate that is both can only have one. A table cell with one end on a plaza is therefore still short by the stretch between the candidate and the node boundary. Tracked in #7683 with what it would take to finish.
…offset (#7688) Snapping a coordinate that falls inside an open area charges the walk to the vertex it snapped to. That cost was folded into the phantom's weight offset, and a search seeds a source with the negation of the offset and a target with the offset itself, so one stored number had to mean both signs. Which sign it got was decided by the coordinate's place in the request: first is a departure, last an arrival. That holds for a route and nothing else. Every coordinate of a table is a source and a destination at once, so half the matrix was charged the wrong way round, and so is a via point, where charging it as a departure made the leg arriving there seed a negative key that CH asserts against. A trip is the same case for all of its coordinates, since the tour returns to the first, and had to opt out of the charge entirely to avoid the crash. The walk now lives on the phantom in three fields of its own, and the seeding accessors add it in either role. Nothing has to know which end of a journey a coordinate is in order to cost it, the sign is fixed by the accessor rather than by the caller, and the opt-out in the trip plugin is gone. `sizeof(PhantomNode)` goes from 80 to 92 bytes. Nothing public moves with it: #7649 replaced the PhantomNode inside SegmentHint with a fixed 80 byte placeholder, so the hint string stays 112 characters. The candidate's *shape* still follows its position, and still has to: a phantom departed from stands at an edge-based node's start, one arrived at at its end, and a coordinate that is both can only have one. A table cell with one end on a plaza is therefore still short by the stretch between the candidate and the node boundary. Tracked in #7683 with what it would take to finish.
Summary
Hints are deprecated and ignored by the server on consumption. They are still generated in API responses for backward compatibility, but the server never uses incoming hints to skip phantom node computation.
This PR removes the compile-time coupling between
SegmentHintserialization andPhantomNodeinternals by replacing the 80-bytePhantomNode phantommember with a fixed-sizestd::array<unsigned char, 80> deprecated_dataplaceholder.Changes
hint.hpp: Removes#include "engine/phantom_node.hpp", replacesPhantomNode phantomwithstd::array<unsigned char, 80> deprecated_data{}hint.cpp: SimplifiesIsValid()to only check the data checksum, removes PhantomNode field accessbase_api.hpp: Stops copying real PhantomNode data into SegmentHint during hint generationtable_parameters.hpp: Fixes a transitive include that was relying onhint.hpp→phantom_node.hpp→typedefs.hppWhy
This decoupling allows
PhantomNodeto change freely (e.g., for issue #2357) without breaking the hint wire format. The hint serialization size (112 base64 chars) is preserved for API compatibility.Testing
All base64 tests pass, including the 3 hint-specific roundtrip tests.
🤖 Claude Code, deepseek-v4-pro