{
  "id": "go/grpc-failed-precondition",
  "signature": "rpc error: code = FailedPrecondition desc = resource version mismatch: expected 42, got 41",
  "signature_zh": "rpc 错误：code = FailedPrecondition desc = 资源版本不匹配：期望 42，实际 41",
  "regex": "rpc\\ error:\\ code\\ =\\ FailedPrecondition\\ desc\\ =\\ resource\\ version\\ mismatch:\\ expected\\ 42,\\ got\\ 41",
  "domain": "go",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "The server rejected the operation because a precondition on the resource state was not met — typically optimistic concurrency control where the client's version/etag is stale relative to the current server state.",
  "root_cause_type": "generic",
  "root_cause_zh": "服务器拒绝了操作，因为资源状态的前置条件未满足——通常是乐观并发控制，客户端携带的版本/etag 相对于服务器当前状态已过时。",
  "versions": [
    {
      "version": "1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The version is still stale; the server rejects every identical attempt with the same FailedPrecondition.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Removing the precondition bypasses concurrency control and risks last-writer-wins data loss.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Re-fetch the latest resource, apply the mutation to the fresh copy, and retry with the new version:\n\nfor i := 0; i < 5; i++ {\n    cur, err := client.Get(ctx, &pb.GetReq{Id: id})\n    if err != nil { return err }\n    cur.Data = newData\n    _, err = client.Update(ctx, &pb.UpdateReq{Id: id, Data: newData, Version: cur.Version})\n    if status.Code(err) != codes.FailedPrecondition { return err }\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Use an ETag/If-Match style conditional request and surface a conflict to the caller when it persists:\n\nif status.Code(err) == codes.FailedPrecondition {\n    return ErrConflict // let the caller resolve\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-12-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}