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
- Set the batch size to a positive integer literal such as 1 or 10
- If batchSize is computed, wrap it with Max(1, expr) or guard it before use
- 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
- Never hardcode 0 as a batch size
- Validate computed batch sizes with a Max(1, x) style guard
- Treat FunctionFailure with 'batch size must be a positive integer' as a configuration bug, not transient
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
- Non-optional parameter %s must be declared before optional p
- Duplicated argument name %s
- cannot pass empty collection to Foldl1()
- Date String Format Error:
- Assert failed
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/24c3088aa30296c8.
Report an issue: GitHub.