ros2 build_system ai_generated true

ROS2 'type hash mismatch' or 'incompatible type' error after modifying custom message definition

ID: ros2/message-type-hash-mismatch-rebuild

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

After modifying a .msg/.srv/.action file, the type hash changes. Running nodes using the old compiled message type cannot communicate with nodes using the new type. Clean rebuild of ALL dependent packages is required, not just the message package.

generic

Workarounds

  1. 95% success Clean rebuild all dependent packages after message changes
    colcon build --packages-above my_msgs  # rebuilds my_msgs AND all packages that depend on it
  2. 88% success Delete build/ and install/ directories for a guaranteed clean state
    rm -rf build/ install/ log/ && colcon build  # nuclear option but guarantees no stale artifacts
  3. 85% success Source install/setup.bash in ALL terminals after rebuild
    source install/setup.bash  # every terminal running ROS2 nodes must re-source after message type changes

Dead Ends

Common approaches that don't work:

  1. Rebuild only the message package after changing .msg definition 90% fail

    All packages that depend on the message must also be rebuilt. Their compiled bindings reference the old type hash. Partial rebuild = type hash mismatch at runtime.

  2. Restart nodes without rebuilding after .msg change 88% fail

    Compiled message types are baked into the binaries. Restarting without rebuilding uses the same old binaries with old type hashes.