{"record":{"id":"5793206815a134bb","repo":"jax-ml/jax","slug":"c-api-argument-to-clear-xla-transform-c-api-is-not","errorCode":null,"errorMessage":"c_api argument to clear_xla_transform_c_api is not a pjrt_c_api capsule.","messagePattern":"c_api argument to clear_xla_transform_c_api is not a pjrt_c_api capsule\\.","errorType":"validation","errorClass":"nb::value_error","httpStatus":null,"severity":"error","filePath":"jaxlib/xla.cc","lineNumber":272,"sourceCode":"        args.name = name.c_str();\n        args.name_size = name.size();\n        args.stage = static_cast<PJRT_XlaTransform_PipelineStage>(stage);\n        args.callbacks = &state->callbacks;\n\n        PJRT_Error* error = extension->register_xla_transform(&args);\n        if (error != nullptr) {\n          absl::Status status = pjrt::PjrtErrorToStatus(error);\n          throw std::runtime_error(status.ToString());\n        }\n      },\n      nb::arg(\"c_api\"), nb::arg(\"name\"), nb::arg(\"stage\"),\n      nb::arg(\"callback\"));\n\n  m.def(\n      \"clear_xla_transform_c_api\",\n      [](nb::capsule c_api, std::string name, int stage) {\n        if (std::string_view(c_api.name()) != \"pjrt_c_api\") {\n          throw nb::value_error(\n              \"c_api argument to clear_xla_transform_c_api is not a \"\n              \"pjrt_c_api capsule.\");\n        }\n        const PJRT_Api* c_api_value =\n            static_cast<const PJRT_Api*>(c_api.data());\n\n        PJRT_Xla_Transform_Extension* extension =\n            pjrt::FindExtension<PJRT_Xla_Transform_Extension>(\n                c_api_value,\n                PJRT_Extension_Type::PJRT_Extension_Type_XlaTransform);\n        if (extension == nullptr) {\n          return false;\n        }\n\n        PJRT_Clear_Xla_Transform_Args args;\n        args.struct_size = PJRT_Clear_Xla_Transform_Args_STRUCT_SIZE;\n        args.name = name.c_str();\n        args.name_size = name.size();","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/xla.cc#L254-L290","documentation":"clear_xla_transform_c_api mirrors the registration check: its first argument must be a PyCapsule named 'pjrt_c_api'. Passing any other capsule or object raises this value error.","triggerScenarios":"Calling jaxlib's clear_xla_transform_c_api with the wrong capsule (different name) or a non-capsule object.","commonSituations":"Cleanup code that passes the backend client or module instead of the plugin's _C_API capsule; capsule name lost during serialization/handoff.","solutions":["Pass the same pjrt_c_api capsule used at registration (plugin._C_API)","Store the capsule reference used for registration and reuse it in clear"],"exampleFix":"# before\nclear_xla_transform_c_api(backend_client, 'my_pass', 0)\n\n# after\nclear_xla_transform_c_api(plugin._C_API, 'my_pass', 0)  # 'pjrt_c_api' capsule","handlingStrategy":"type-guard","validationCode":"api = plugin._C_API  # the 'pjrt_c_api' capsule used at registration\nif type(api).__name__ != 'PyCapsule':\n    raise TypeError('expected pjrt_c_api capsule')","typeGuard":"def is_pjrt_capsule(c) -> bool:\n    return type(c).__name__ == 'PyCapsule'","tryCatchPattern":null,"preventionTips":["Store the capsule used at registration and pass the same object to clear"],"tags":["jax","xla","pjrt","pycapsule"],"backgroundTag":"wrong-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}