Skip to content

Ambiguous handling of empty messages or point clouds #710

@youtalk

Description

@youtalk

Checklist

  • I've read the contribution guidelines.
  • I've searched other issues and no duplicate issues were found.
  • I've agreed with the maintainers that I can plan this task.

Description

Nodes across Autoware Core disagree on how to treat empty inputs, with some throwing exceptions, others blocking, and some silently failing. This inconsistency leads to fragile pipelines where empty point clouds or trajectories can crash downstream nodes. This aligns with Anti-pattern 3 in the system performance documentation.

Purpose

The purpose of this task is to:

  1. Establish consistent empty-data handling policies across all nodes
  2. Prevent crashes from empty sensor messages and trajectories
  3. Define clear contracts for empty-input behavior
  4. Improve system robustness during sensor failures or initialization

Possible approaches

Approach 1: Explicit Empty-Data Contract (Recommended)

/// Contract: Empty cloud means "no detection"; publish empty results.
/// Never throw on empty input; never block waiting for non-empty.
void onCloud(const sensor_msgs::msg::PointCloud2 &cloud) {
  if (cloud.width == 0 || cloud.height == 0 || cloud.data.empty()) {
    MyResult empty;
    empty.header = cloud.header;
    empty.detections.clear();  // Explicitly empty
    pub_->publish(empty);
    RCLCPP_DEBUG(get_logger(), "Received empty cloud, publishing empty result");
    return;
  }
  // Normal processing...
}

Approach 2: Guard Clauses with Logging

// Early return pattern with appropriate logging
if (points.empty()) {
  RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 1000,
    "Empty trajectory received, skipping processing");
  return;
}

Approach 3: Default Value Propagation

// Return safe defaults instead of throwing
if (cluster.points.empty()) {
  geometry_msgs::msg::Point centroid;
  centroid.x = centroid.y = centroid.z = 0.0;
  return centroid;  // Valid but neutral value
}

Definition of done

Critical Fixes

  • Fix euclidean_cluster_node: Add empty cloud checks
  • Fix voxel_grid_based_euclidean_cluster: Add empty validation
  • Fix motion_utils/getCentroid: Handle zero-size clusters
  • Fix trajectory utilities: Handle empty point arrays

System-wide Standardization

  • Document empty-data policy in coding guidelines
  • Add validation to all PointCloud2 callbacks
  • Add validation to all Trajectory callbacks
  • Implement consistent logging for empty data cases

Testing and Validation

  • Unit tests verify empty input handling for all nodes
  • Integration tests with simulated sensor failures
  • Document expected behavior in API specifications
  • Add empty-data scenarios to CI/CD tests

Metadata

Metadata

Assignees

Labels

status:staleInactive or outdated issues. (auto-assigned)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions