# [WARN] [topic_statistics]: Received message on topic '/scan' with sequence number 123, expected 124

- **ID:** `ros2/ros2-topic-statistics-mismatch`
- **Domain:** ros2
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Topic statistics monitoring detected a gap in message sequence numbers, indicating dropped messages or out-of-order delivery, often due to network congestion, high CPU load, or QoS incompatibility.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ros2:humble | active | — | — |
| ros2:iron | active | — | — |
| ros2:rolling | active | — | — |
| rclcpp:18.0.0 | active | — | — |

## Workarounds

1. **Check network bandwidth and CPU usage. If high, reduce the publishing rate or use a more efficient serialization. Example:
ros2 topic hz /scan  # Check current rate
ros2 topic bw /scan   # Check bandwidth

If bandwidth is high, adjust the publisher to use a lower rate or reduce message size.** (75% success)
   ```
   Check network bandwidth and CPU usage. If high, reduce the publishing rate or use a more efficient serialization. Example:
ros2 topic hz /scan  # Check current rate
ros2 topic bw /scan   # Check bandwidth

If bandwidth is high, adjust the publisher to use a lower rate or reduce message size.
   ```
2. **If using unreliable QoS (e.g., BEST_EFFORT), switch to RELIABLE QoS to reduce drops. In publisher code:
from rclpy.qos import QoSProfile, ReliabilityPolicy

qos = QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE)
self.publisher = self.create_publisher(LaserScan, '/scan', qos)** (85% success)
   ```
   If using unreliable QoS (e.g., BEST_EFFORT), switch to RELIABLE QoS to reduce drops. In publisher code:
from rclpy.qos import QoSProfile, ReliabilityPolicy

qos = QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE)
self.publisher = self.create_publisher(LaserScan, '/scan', qos)
   ```

## Dead Ends

- **Disabling topic statistics without investigating the root cause** — This hides the symptom but does not address the underlying message loss, which may affect application behavior. (60% fail)
- **Increasing the publisher's publishing rate to compensate** — Higher rate increases network and CPU load, potentially worsening the problem. (80% fail)
