{"record":{"id":"9be79a84d8589728","repo":"xai-org/x-algorithm","slug":"type-checking-expression-s-failed-invalid-argume-9be79a","errorCode":null,"errorMessage":"type checking expression %s failed: invalid argument type: %s received, %s expected","messagePattern":"type checking expression (.+?) failed: invalid argument type: (.+?) received, (.+?) expected","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/ASTNode.java","lineNumber":236,"sourceCode":"\n  private void buildGenericTypeIdToTypeMapping(\n      Type genericType, Type concreteType, Map<Long, Type> recordMap) throws SemanticCheckFailure {\n    if (genericType.isGenericType()) {\n      long genericTypeId = genericType.genericTypeId;\n      if (!recordMap.containsKey(genericTypeId)) {\n        recordMap.put(genericTypeId, concreteType);\n      } else {\n        recordMap.put(\n            genericTypeId,\n            Type.getClosestCommonSuperType(\n                concreteType,\n                recordMap.get(genericTypeId)\n            )\n        );\n      }\n    } else {\n      if (Type.isDivergentTo(genericType.typeBase, concreteType.typeBase)) {\n        throw new SemanticCheckFailure(String.format(\n            \"type checking expression %s failed: invalid argument type: %s received, %s expected\",\n            exprText,\n            concreteType.toString(),\n            genericType.toString()));\n      }\n      ImmutableList<Type> genericTypeParams = genericType.getTypeParams();\n      ImmutableList<Type> concreteTypeParams = concreteType.getTypeParams();\n      if (genericTypeParams.size() == concreteTypeParams.size()) {\n        for (int i = 0; i < genericTypeParams.size(); i++) {\n          buildGenericTypeIdToTypeMapping(\n              genericTypeParams.get(i),\n              concreteTypeParams.get(i),\n              recordMap\n          );\n        }\n      }\n    }\n  }","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/ASTNode.java#L218-L254","documentation":"XAI_ASSERT is the generic assertion macro in the xla_utils CUDA error utilities. When its condition fails it throws std::runtime_error built from __FILE__:__LINE__ concatenated with the caller-provided message (note the message is appended without a separator, so messages conventionally start with a space or ':' text). It guards non-CUDA preconditions like pointer validity, size sanity, and configuration invariants in XLA-adjacent GPU utility code.","triggerScenarios":"Any XAI_ASSERT(cond, msg) site in phoenix/xrex/cuda/xla_utils evaluating false: null buffer pointers passed to a utility routine, mismatched element counts between source and destination, unsupported combination of dtype/layout arguments, or negative/zero sizes where positive are required. Unlike XAI_CUDA_CHECK this fires from plain C++ logic, not CUDA API return codes.","commonSituations":"Passing empty or wrongly-shaped DLArrays/buffers into XLA custom-call wrappers, mismatched arguments after a library upgrade changed an API contract, integer overflow computing sizes for very large tensors, or forgetting to initialize a handle before calling a utility that asserts on it.","solutions":["Locate the exact assertion via the file:line prefix in the message and read what invariant it enforces","Check all pointer arguments are non-null and correctly typed for the utility being called","Verify size/count arguments are positive, consistent with each other, and don't overflow (use 64-bit size math)","Confirm the library version matches the headers/callers being compiled against (stale prebuilt .so vs new headers)","Add argument validation on the caller side (or from Python) before invoking the utility"],"exampleFix":"// before\nXAI_ASSERT(ptr && numel > 0, \" invalid buffer\");\n\n// after\nXAI_ASSERT(ptr != nullptr, \" buffer pointer is null\");\nXAI_ASSERT(numel > 0, \" numel must be positive, got \" + std::to_string(numel));","handlingStrategy":"validation","validationCode":"// Validate before calling xla_utils routines:\nif (ptr == nullptr) return Status::InvalidArgument(\"null buffer\");\nif (count <= 0 || count > std::numeric_limits<std::ptrdiff_t>::max() / elem_size) {\n  return Status::InvalidArgument(\"bad element count\");\n}","typeGuard":"struct BufArgs { void* p; int64_t numel; int device; };\nbool valid_buf_args(const BufArgs& a, int expected_device) {\n  return a.p != nullptr && a.numel > 0 && a.device == expected_device;\n}","tryCatchPattern":"try {\n  xla_util_op(buf, n);\n} catch (const std::runtime_error& e) {\n  if (strstr(e.what(), \"cuda_error_utils.hpp\") != nullptr) {\n    // precondition violation: fix arguments, don't retry\n    return InvalidArgument(e.what());\n  }\n  throw;\n}","preventionTips":["Validate all pointer/size arguments at the API boundary before asserting internally","Use explicit 64-bit arithmetic for sizes to avoid overflow-triggered assertion failures","Rebuild all translation units against the same library version to keep assertion contracts consistent","Write unit tests for boundary cases (empty, zero, max sizes) around each utility"],"tags":["cuda","assertion","runtime-error","xla","validation"],"backgroundTag":"cuda-kernel-assertion-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}