# Protobuf deserialization produces wrong values when field numbers are reused across different message types

- **ID:** `data/protobuf-field-number-collision`
- **Domain:** data
- **Category:** serialization_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Protobuf wire format uses field numbers only, not names, so reusing field numbers across different message types in the same file can cause field values to be assigned to the wrong fields during deserialization.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Protocol Buffers 3.21.0 | active | — | — |
| protoc 24.0 | active | — | — |
| gRPC 1.57.0 | active | — | — |

## Workarounds

1. **Ensure all message types use unique field numbers across the entire .proto file: message User { int32 id = 1; } message Product { int32 product_id = 1; } // Change to use distinct numbers** (95% success)
   ```
   Ensure all message types use unique field numbers across the entire .proto file: message User { int32 id = 1; } message Product { int32 product_id = 1; } // Change to use distinct numbers
   ```
2. **Use a migration script to rewrite existing serialized data with corrected field numbers: for each message, decode using old schema, then re-encode with new schema mapping old field numbers to new ones** (85% success)
   ```
   Use a migration script to rewrite existing serialized data with corrected field numbers: for each message, decode using old schema, then re-encode with new schema mapping old field numbers to new ones
   ```

## Dead Ends

- **Adding deprecated annotations to conflicting fields** — Adding fields with new numbers does not fix the existing field number collision issue. (80% fail)
- **Using 'reserved' keyword for conflicting field numbers** — Reserved prevents new use but does not fix existing serialized data with wrong field numbers. (75% fail)
