xai-org/x-algorithm · error · SemanticCheckFailure

type checking expression %s failed: invalid argument type: %

Error message

type checking expression %s failed: invalid argument type: %s received, %s expected

What it means

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.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/ASTNode.java:236

  private void buildGenericTypeIdToTypeMapping(
      Type genericType, Type concreteType, Map<Long, Type> recordMap) throws SemanticCheckFailure {
    if (genericType.isGenericType()) {
      long genericTypeId = genericType.genericTypeId;
      if (!recordMap.containsKey(genericTypeId)) {
        recordMap.put(genericTypeId, concreteType);
      } else {
        recordMap.put(
            genericTypeId,
            Type.getClosestCommonSuperType(
                concreteType,
                recordMap.get(genericTypeId)
            )
        );
      }
    } else {
      if (Type.isDivergentTo(genericType.typeBase, concreteType.typeBase)) {
        throw new SemanticCheckFailure(String.format(
            "type checking expression %s failed: invalid argument type: %s received, %s expected",
            exprText,
            concreteType.toString(),
            genericType.toString()));
      }
      ImmutableList<Type> genericTypeParams = genericType.getTypeParams();
      ImmutableList<Type> concreteTypeParams = concreteType.getTypeParams();
      if (genericTypeParams.size() == concreteTypeParams.size()) {
        for (int i = 0; i < genericTypeParams.size(); i++) {
          buildGenericTypeIdToTypeMapping(
              genericTypeParams.get(i),
              concreteTypeParams.get(i),
              recordMap
          );
        }
      }
    }
  }

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Locate the exact assertion via the file:line prefix in the message and read what invariant it enforces
  2. Check all pointer arguments are non-null and correctly typed for the utility being called
  3. Verify size/count arguments are positive, consistent with each other, and don't overflow (use 64-bit size math)
  4. Confirm the library version matches the headers/callers being compiled against (stale prebuilt .so vs new headers)
  5. Add argument validation on the caller side (or from Python) before invoking the utility

Example fix

// before
XAI_ASSERT(ptr && numel > 0, " invalid buffer");

// after
XAI_ASSERT(ptr != nullptr, " buffer pointer is null");
XAI_ASSERT(numel > 0, " numel must be positive, got " + std::to_string(numel));
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling xla_utils routines:
if (ptr == nullptr) return Status::InvalidArgument("null buffer");
if (count <= 0 || count > std::numeric_limits<std::ptrdiff_t>::max() / elem_size) {
  return Status::InvalidArgument("bad element count");
}

Type guard

struct BufArgs { void* p; int64_t numel; int device; };
bool valid_buf_args(const BufArgs& a, int expected_device) {
  return a.p != nullptr && a.numel > 0 && a.device == expected_device;
}

Try / catch

try {
  xla_util_op(buf, n);
} catch (const std::runtime_error& e) {
  if (strstr(e.what(), "cuda_error_utils.hpp") != nullptr) {
    // precondition violation: fix arguments, don't retry
    return InvalidArgument(e.what());
  }
  throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/9be79a84d8589728. Report an issue: GitHub.