10. Handle operation limits

Ordinary calls pass NULL for limits. When processing input of uncertain size, initialize a TididiLimits with tididi_limits_default and set the fields you need: memory bytes, emitted nodes, or a cooperative timeout in seconds.

10.1. Keep inputs for a retry

This example combines local-or-remote storage with encryption. A zero memory budget makes the first attempt fail. The originals survive because only copies were passed to the consuming operation; a retry uses fresh copies.

TididiLimits limits = tididi_limits_default();
limits.memory_bytes = 0;
TididiCircuit *a = copy(destination), *b = copy(encrypted), *result = NULL;
TididiError *error = tididi_and(a, b, &result, &limits);
if (error) {
    if (tididi_error_code(error) != TIDIDI_ERROR_CODE_MEMORY_LIMIT) check(error);
    puts("Operation exceeded its memory budget; retrying with fresh copies.");
    tididi_error_free(error);
    release(a); release(b);
    a = copy(destination); b = copy(encrypted);
    check(tididi_and(a, b, &result, NULL));
}
printf("Encrypted configurations: %" PRIu64 "\n", count(result));

Output:

Operation exceeded its memory budget; retrying with fresh copies.
Encrypted configurations: 6

10.2. Complete program

Download execution.c and the shared helper. The source includes cleanup for all handles. Both files are included in the source checkout.