xai-org/x-algorithm · error · FunctionFailure

batch size must be a positive integer

Error message

batch size must be a positive integer

What it means

Any(batchSize) requires the second argument (batch size) to evaluate to a positive integer. When the joined collection and batch-size futures resolve, a batchSize of 0 or negative triggers FunctionFailure wrapping IllegalArgumentException. It is a runtime error, so the bad value only surfaces when the rule executes.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/function/collection/Any.java:117

                return Boolean.FALSE;
              } catch (Exception e) {
                throw FunctionFailure.wrap(e, getAstNode(), context);
              }
            }
          };
        } else {
          return new Extractor<Runtime>(this, children) {
            @Override
            public Future run(Context<Runtime> context) {
              Future<Object> collectionExtractionFuture = context.run(collectionExtractor);
              Future<Object> batchSizeExtractionFuture = context.run(batchSizeExtractor);
              return Futures.join(collectionExtractionFuture, batchSizeExtractionFuture)
                  .flatMap(collectionAndBatchSize -> {
                        Collection<Object> collection =
                            (Collection<Object>) collectionAndBatchSize._1();
                        int batchSize = ((Long) collectionAndBatchSize._2()).intValue();
                        if (batchSize <= 0) {
                          throw new FunctionFailure(getAstNode(),
                              context.getStackFrames(),
                              new IllegalArgumentException(
                                  "batch size must be a positive integer"));
                        }

                        if (collection.isEmpty()) {
                          return FUTURE_FALSE;
                        }

                        return evaluate(
                            context,
                            varName,
                            new ArrayList<>(collection),
                            0,
                            conditionExtractor,
                            batchSize
                        );
                      }

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Set the batch size to a positive integer literal such as 1 or 10
  2. If batchSize is computed, wrap it with Max(1, expr) or guard it before use
  3. Check the rule's parameters/constants feeding the second argument of Any()

Example fix

// before
Any(items, 0)
// after
Any(items, 10)
Defensive patterns

Strategy: validation

Validate before calling

// before calling Any: ensure batchSize > 0
long batchSize = getBatchSize();
if (batchSize <= 0) { batchSize = DEFAULT_BATCH_SIZE; }
collection = Any(items, batchSize);

Prevention

When it happens

Trigger: Calling Any(collection, batchSize) where batchSize evaluates to 0 or a negative Long at runtime, e.g. Any(x, 0), or batchSize derived from user data/another function that returns 0.

Common situations: Hardcoding a batch size of 0, using a computed batch size (e.g. length of an empty collection) that collapses to 0, or copying an example with a placeholder value.

Related errors


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