# rpc error: code = FailedPrecondition desc = resource version conflict: expected 3, got 5

- **ID:** `go/grpc-failed-precondition-state-mismatch`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The request violates a precondition, such as an outdated resource version in an optimistic concurrency control scenario.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## Workarounds

1. **Fetch the latest resource version and retry the update.** (90% success)
   ```
   currentResource, err := client.GetResource(ctx, &pb.GetRequest{Id: id})
if err != nil { return err }
req.Version = currentResource.Version
resp, err := client.UpdateResource(ctx, req)
   ```
2. **Implement a retry loop with backoff to handle concurrent updates.** (85% success)
   ```
   for i := 0; i < 3; i++ {
    resp, err := client.UpdateResource(ctx, req)
    if err == nil { return resp }
    if status.Code(err) != codes.FailedPrecondition { return err }
    time.Sleep(100 * time.Millisecond)
    // Refresh resource
}
   ```

## Dead Ends

- **Retry the same request without updating the version.** — The version mismatch will persist, causing the same error. (100% fail)
- **Ignore the version and force the update.** — This can lead to data corruption or lost updates. (80% fail)
