Skip to content

refactor(hints): replace PhantomNode in SegmentHint with fixed placeholder - #7649

Merged
DennisOSRM merged 9 commits into
masterfrom
refactor/deprecate-hint-placeholder
Jul 6, 2026
Merged

DennisOSRM merged 9 commits into
masterfrom
refactor/deprecate-hint-placeholder

Conversation

@DennisOSRM

Copy link
Copy Markdown
Collaborator

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 SegmentHint serialization and PhantomNode internals by replacing the 80-byte PhantomNode phantom member with a fixed-size std::array<unsigned char, 80> deprecated_data placeholder.

Changes

  • hint.hpp: Removes #include "engine/phantom_node.hpp", replaces PhantomNode phantom with std::array<unsigned char, 80> deprecated_data{}
  • hint.cpp: Simplifies IsValid() to only check the data checksum, removes PhantomNode field access
  • base_api.hpp: Stops copying real PhantomNode data into SegmentHint during hint generation
  • table_parameters.hpp: Fixes a transitive include that was relying on hint.hpp → phantom_node.hpp → typedefs.hpp

Why

This decoupling allows PhantomNode to 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

… 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.
Copilot AI review requested due to automatic review settings July 5, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 embedded PhantomNode with a fixed 80-byte placeholder and keep checksum-only validation/roundtrips.
  • Stop populating real PhantomNode data when generating response hints (placeholders only).
  • Refactor findObviousTurn to return std::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.

Comment thread src/engine/hint.cpp Outdated
Comment on lines +17 to +19
// Hints are deprecated; always report as valid to avoid rejecting requests
// that still include hints from older responses.
return facade.GetCheckSum() == data_checksum;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — updated the comment to say "only validate via dataset checksum" instead of "always report as valid."

Comment thread src/engine/hint.cpp Outdated
bool Hint::IsValid(const util::Coordinate /*new_input_coordinates*/,
const datafacade::BaseDataFacade &facade) const
{
// Hints are deprecated; always report as valid.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.
@DennisOSRM
DennisOSRM force-pushed the refactor/deprecate-hint-placeholder branch from d431887 to c3ce0cd Compare July 5, 2026 20:48
Comment thread src/engine/hint.cpp

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — updated both comments to accurately describe checksum-only validation instead of claiming "always report as valid."

DennisOSRM and others added 4 commits July 5, 2026 22:52
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

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.14286% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.15%. Comparing base (6678ebc) to head (09e4c89).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/engine/hint.cpp 11.11% 8 Missing ⚠️
include/guidance/intersection_handler.hpp 80.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DennisOSRM
DennisOSRM merged commit 563571d into master Jul 6, 2026
22 of 23 checks passed
@DennisOSRM
DennisOSRM deleted the refactor/deprecate-hint-placeholder branch July 6, 2026 19:53
DennisOSRM added a commit that referenced this pull request Aug 11, 2026
…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.
DennisOSRM added a commit that referenced this pull request Aug 12, 2026
…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.
DennisOSRM added a commit that referenced this pull request Aug 12, 2026
…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.
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.

2 participants