{"record":{"id":"13e7c35955a85fc8","repo":"xai-org/x-algorithm","slug":"type-checking-expression-s-failed-invalid-argume","errorCode":null,"errorMessage":"type checking expression %s failed: invalid argument type: expected a constant %s","messagePattern":"type checking expression (.+?) failed: invalid argument type: expected a constant (.+?)","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/ASTNode.java","lineNumber":160,"sourceCode":"    for (ASTNode child : astNodeChildren) {\n      long childScope = child.getFingerprint().scope;\n      if (childScope == CacheLevel.Never.scope) {\n        return childScope;\n      } else if (childScope <= currentScope) {\n        scope = Math.max(scope, childScope);\n      } else {\n        scope = Math.max(scope, child.computeFingerprintScope(currentScope));\n      }\n    }\n\n    return scope;\n  }\n\n  public static void assertChildConstant(\n      String exprText, ImmutableList<ASTNode> children, int index) throws SemanticCheckFailure {\n    ASTNode node = children.get(index);\n    if (!Constant.class.isAssignableFrom(node.getClass())) {\n      throw new SemanticCheckFailure(String.format(\n          \"type checking expression %s failed: invalid argument type: expected a constant %s\",\n          exprText,\n          node.getReturnType().toString())\n      );\n    }\n  }\n\n  public static void assertChildrenSize(\n      String exprText, ImmutableList<ASTNode> children, int expected) throws SemanticCheckFailure {\n    if (children.size() != expected) {\n      throw new SemanticCheckFailure(String.format(\n          \"ASTNode %s expected %d arguments, %d passed.\", exprText, expected, children.size()));\n    }\n\n  }\n\n  public static void assertChildrenSize(\n      String exprText, ImmutableList<ASTNode> children,","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/ASTNode.java#L142-L178","documentation":"XAI_ASSERT is an internal assertion macro in the async embedding CUDA library. It evaluates a condition at runtime and throws std::runtime_error composed of __FILE__:__LINE__ plus the supplied message when the condition is false. It is used to guard invariants such as valid tensor shapes, non-null device pointers, or supported dtype combinations before launching kernels.","triggerScenarios":"Calling the async embedding FFI/binding APIs with arguments that violate internal preconditions: null or wrongly-typed device buffers, mismatched innermost dimension vs embedding table row stride, out-of-range indices configuration, or unsupported dtypes. Any call site in phoenix/xrex/cuda/async_emb that wraps a check in XAI_ASSERT(cond, msg) will raise this when cond evaluates false.","commonSituations":"Passing CPU tensors instead of CUDA tensors, embedding dimension not matching the table's row size, batch shapes that don't match index shapes, version mismatches where the host/JAX layer builds args the kernel no longer accepts, or initializing the embedding handle on a different device than the input data.","solutions":["Read the file:line in the message to find the exact failing assertion and the invariant it checks","Verify tensor device, dtype, and shape match what the async embedding op expects (especially innermost dim == embedding_dim)","Ensure the embedding table handle was created on the same CUDA device as the inputs","Check for None/nullptr arguments or zero-size tensors being passed through the FFI boundary","Reproduce with a minimal input and compare against the library's own test fixtures to see which argument differs"],"exampleFix":"// before\nemb_lookup(table_handle, indices_cpu, offsets, out)  # indices on CPU\n\n// after\nindices_gpu = jax.device_put(indices, jax.devices('cuda')[0])\nemb_lookup(table_handle, indices_gpu, offsets, out)  # all buffers on same CUDA device","handlingStrategy":"validation","validationCode":"// Before calling the async embedding op:\nassert table_handle is not None\nassert indices.device.type == 'cuda' and indices.device == table_handle.device\nassert indices.shape[-1] == 0 or offsets.dtype == indices.dtype\nassert out is None or out.shape == expected_output_shape(indices, offsets, embedding_dim)\nassert indices.shape[-1] == embedding_dim  # innermost dim must match table row size","typeGuard":"def _valid_emb_args(indices, offsets, table_dim, device) -> bool:\n    return (\n        indices is not None\n        and indices.device.type == 'cuda'\n        and indices.device == device\n        and indices.shape[-1] == table_dim\n        and indices.dtype in (np.int32, np.int64)\n    )","tryCatchPattern":"try:\n    emb_lookup(handle, indices, offsets)\nexcept RuntimeError as e:\n    if 'cuda_error_utils.hpp' in str(e):  # XAI_ASSERT failure\n        raise ValueError(f'bad embedding arguments: {e}') from e\n    raise","preventionTips":["Always device_put every tensor to the same CUDA device as the embedding handle before the call","Validate shapes/dtypes on the host before crossing the FFI boundary","Pin library version so header-side assertion contracts match your caller code","Wrap FFI entry points in tests covering empty tensors, wrong devices, and mismatched dims"],"tags":["cuda","assertion","runtime-error","embedding","gpu-memory"],"backgroundTag":"cuda-kernel-assertion-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}