# [rosbag2_compression] Compression ratio exceeded threshold: 10.5 (max 5.0). Bag file may be corrupted.

- **ID:** `ros2/rosbag2-compression-ratio-exceeded`
- **Domain:** ros2
- **Category:** data_error
- **Error Code:** `ROSBAG2_COMPRESSION_001`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The compression algorithm (e.g., zstd) produced a compressed file larger than the uncompressed data, often due to incompressible data (e.g., random noise from sensors like lidar or radar) or a misconfigured compression level.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Humble | active | — | — |
| Iron | active | — | — |
| Jazzy | active | — | — |
| Rolling | active | — | — |

## Workarounds

1. **Increase the compression ratio threshold in the storage options: ros2 bag record -o my_bag --compression-mode file --compression-format zstd --compression-queue-size 100 --max-compression-ratio 20.0 /topic1 /topic2** (90% success)
   ```
   Increase the compression ratio threshold in the storage options: ros2 bag record -o my_bag --compression-mode file --compression-format zstd --compression-queue-size 100 --max-compression-ratio 20.0 /topic1 /topic2
   ```
2. **Filter out noisy topics (e.g., raw sensor data) from recording to avoid incompressible data: ros2 bag record -o my_bag --exclude '/noisy_lidar/.*' /important_topic** (85% success)
   ```
   Filter out noisy topics (e.g., raw sensor data) from recording to avoid incompressible data: ros2 bag record -o my_bag --exclude '/noisy_lidar/.*' /important_topic
   ```
3. **Preprocess sensor data to reduce noise (e.g., downsampling or filtering) before recording, using a separate node that publishes filtered messages.** (75% success)
   ```
   Preprocess sensor data to reduce noise (e.g., downsampling or filtering) before recording, using a separate node that publishes filtered messages.
   ```

## Dead Ends

- **Increase the compression level to 22 (max for zstd)** — Higher compression levels can make the ratio worse for incompressible data, as overhead increases. (70% fail)
- **Disable compression entirely and store bags uncompressed** — This solves the warning but defeats the purpose of using compression for storage efficiency. (50% fail)
- **Change the compression format to 'lz4'** — LZ4 is faster but has even worse compression ratios for incompressible data and may still trigger the warning. (75% fail)
