# INTERNAL: compression dictionary mismatch: expected gzip but received deflate

- **ID:** `grpc/compression-dictionary-mismatch`
- **Domain:** grpc
- **Category:** encoding_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

gRPC message compression algorithm mismatch between client and server: the client sends a message compressed with 'deflate' but the server expects 'gzip', or vice versa, due to incompatible compression configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| gRPC v1.63.0 | active | — | — |
| gRPC-Python v1.62.0 | active | — | — |
| gRPC-Go v1.64.0 | active | — | — |

## Workarounds

1. **Align compression algorithms: set the same compression on both client and server; e.g., in Python: 'grpc.insecure_channel(target, options=[("grpc.default_compression_algorithm", 2)])' (2=gzip) and on server: 'grpc.server(futures.ThreadPoolExecutor(), options=[("grpc.default_compression_algorithm", 2)])'.** (90% success)
   ```
   Align compression algorithms: set the same compression on both client and server; e.g., in Python: 'grpc.insecure_channel(target, options=[("grpc.default_compression_algorithm", 2)])' (2=gzip) and on server: 'grpc.server(futures.ThreadPoolExecutor(), options=[("grpc.default_compression_algorithm", 2)])'.
   ```
2. **Use environment variables to override compression: set 'GRPC_DEFAULT_COMPRESSION_ALGORITHM=gzip' on both client and server to enforce consistency, and 'GRPC_DEFAULT_COMPRESSION_LEVEL=1' for low latency.** (85% success)
   ```
   Use environment variables to override compression: set 'GRPC_DEFAULT_COMPRESSION_ALGORITHM=gzip' on both client and server to enforce consistency, and 'GRPC_DEFAULT_COMPRESSION_LEVEL=1' for low latency.
   ```
3. **Implement a client-side interceptor to detect and log compression headers: inspect 'grpc-encoding' metadata and adjust the algorithm dynamically if mismatch is detected; fall back to no compression if negotiation fails.** (75% success)
   ```
   Implement a client-side interceptor to detect and log compression headers: inspect 'grpc-encoding' metadata and adjust the algorithm dynamically if mismatch is detected; fall back to no compression if negotiation fails.
   ```

## Dead Ends

- **** — Disabling compression entirely on the client side (e.g., 'grpc.default_compression_algorithm=none') may break if the server requires compression; the error changes to 'UNIMPLEMENTED: Decompressor is not installed'. (75% fail)
- **** — Switching to a third compression library (e.g., zstd) without updating both sides causes a new mismatch error; both client and server must agree on the algorithm. (85% fail)
- **** — Restarting the server with the same configuration doesn't fix the root cause; the mismatch persists until the client's compression algorithm is changed. (95% fail)
