Knowledge base for Bubble® apps

Recursive backend workflow stuck in a loop

By Red Center Studio / Updated

TL;DR

A backend workflow that schedules itself without a working stop condition can run indefinitely and burn workload units. Pause or cancel it in the Scheduler, fix the terminating condition, and confirm Infinite Recursion Protection is enabled as a backstop.

What is happening

A recursive API workflow processes one item, then schedules itself for the next. The official manual warns that this pattern can lead to infinite recursion and significant workload unit consumption if the stop condition never becomes true. Each scheduling adds cost: the documentation lists a starting cost of 0.1 WU for adding an item to the API workflow scheduler, plus 0.6 WU for each server-side action the workflow runs, and these can rise with complexity.

Bubble also offers Infinite Recursion Protection. It is set in Settings, API, with separate limits for development and live. Apps created on or after July 1, 2024 default to a limit of 10. Older apps have no limit until you enable it. When the limit is hit, the workflow stops, the event is logged in the server logs, and app admins receive an email (at most once a day).

How to stop a running loop

  1. Open Logs, Scheduler. Set the date range and click Show to see what is queued.
  2. Pause if it is urgent. Pause tasks stops the scheduler. It is global: it pauses every scheduled workflow, including ones your live users rely on. Click Resume tasks once the loop is dealt with.
  3. Cancel the queued runs. Use the Cancel all options to remove the scheduled workflows, or cancel a specific chain with the Cancel a scheduled API workflow action using the ID you saved when it was scheduled.

How to fix it for good

  1. Write a stop condition that must become true. The manual's own example only schedules the next run while the count of remaining items is greater than zero. Make sure each run actually reduces that count, for example by marking the processed item.
  2. Put the condition on the scheduling step. Only schedule the next run when there is work left.
  3. Consider not recursing at all. For most bulk processing, the official manual recommends Schedule API workflow on a list, which is usually faster and cheaper.
  4. Enable Infinite Recursion Protection. Treat it as a backstop, not the main control. The documentation describes workflow-level conditions as the primary safeguard.
  5. Test in development. Cancelling a half-finished chain on live data is hard to undo.
Fix this for a fixed price

Triage / $99

Approximately 1 hour of work. Determining issues and coming back to you with a plan.

Pay $99 and book

Related fixes