{"record":{"id":"e984013898df953e","repo":"jax-ml/jax","slug":"invalid-stronglrucache-pickle-version-got-d-exp","errorCode":null,"errorMessage":"Invalid StrongLRUCache pickle version, got %d, expected 1","messagePattern":"Invalid StrongLRUCache pickle version, got (.+?), expected 1","errorType":"validation","errorClass":"invalid_argument","httpStatus":null,"severity":"error","filePath":"jaxlib/strong_lru_cache.cc","lineNumber":714,"sourceCode":"          .def_prop_ro(\"__wrapped__\", &StrongLRUCache::wrapped)\n          .def(\n              \"__getstate__\",\n              [](const StrongLRUCache& cache) {\n                nb::dict pickle;\n                pickle[\"version\"] = 1;\n                pickle[\"fn\"] = cache.wrapped();\n                pickle[\"cache_context_fn\"] = cache.cache_context_fn();\n                pickle[\"maxsize\"] = cache.maxsize();\n                pickle[\"explain\"] = cache.explain();\n                pickle[\"num_shards\"] = cache.num_shards();\n                return pickle;\n              },\n              nb::lock_self())\n          .def(\"__setstate__\", [](StrongLRUCache* cache,\n                                  const nb::dict& pickle) {\n            int version = nb::cast<int>(pickle[\"version\"]);\n            if (version != 1) {\n              throw std::invalid_argument(absl::StrFormat(\n                  \"Invalid StrongLRUCache pickle version, got %d, expected 1\",\n                  version));\n            }\n            auto fn = nb::cast<nb::callable>(pickle[\"fn\"]);\n            auto cache_context_fn = nb::cast<std::optional<nb::callable>>(\n                pickle[\"cache_context_fn\"]);\n            int64_t maxsize = nb::cast<int64_t>(pickle[\"maxsize\"]);\n            auto explain =\n                nb::cast<std::optional<nb::callable>>(pickle[\"explain\"]);\n            int64_t num_shards = nb::cast<int64_t>(pickle[\"num_shards\"]);\n\n            new (cache)\n                StrongLRUCache(std::move(cache_context_fn), std::move(fn),\n                               maxsize, std::move(explain), num_shards);\n          });\n\n  strong_lru_cache.attr(\"__call__\") = nb::steal<nb::object>(\n      PyDescr_NewMethod(reinterpret_cast<PyTypeObject*>(strong_lru_cache.ptr()),","sourceCodeStart":696,"sourceCodeEnd":732,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/strong_lru_cache.cc#L696-L732","documentation":"StrongLRUCache.__setstate__ only accepts pickle version 1. Unpickling a cache whose pickled 'version' field differs (older or newer format) throws std::invalid_argument.","triggerScenarios":"Unpickling a jaxlib StrongLRUCache (used by jax._src.util.weakref_lru_cache / compiled-function caches) produced by a jaxlib version with a different pickle format version.","commonSituations":"Loading cached artifacts across JAX version upgrades/downgrades; stale cache files restored after an upgrade.","solutions":["Clear/regenerate the pickled cache with the current JAX version","Pin JAX versions when persisting cached objects","Avoid pickling internal LRU caches; persist the underlying data instead"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"state = pickle.loads(payload) if isinstance(payload, bytes) else payload\nif not isinstance(state, dict) or state.get('version') != 1:\n    raise ValueError('stale cache pickle; regenerate with current jaxlib')","typeGuard":null,"tryCatchPattern":"try:\n    cache = pickle.loads(payload)\nexcept ValueError as e:\n    if 'pickle version' in str(e):\n        cache = rebuild_cache()  # cold start\n    else:\n        raise","preventionTips":["Don't persist internal LRU caches across JAX upgrades","Version-stamp cache files with the jaxlib version and invalidate on mismatch"],"tags":["jax","lru-cache","pickle","versioning"],"backgroundTag":"pickle-format-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}