Batching keeps looping with larger data inputs

Hi,

I have a Bubble app that generates AI-powered Change Strategies from a list of Change Impact records. The OpenAI integration works and the JSON parsing works, but I’m having trouble with the batching workflow used to process large numbers of impacts safely.

I need someone experienced with Bubble backend workflows and recursive batching

Goal

The system should:

  1. Take all ImpactType records linked to a Project.

  2. Process them in batches (e.g. batch size = 9).

  3. Store each batch in an ExtractedBatch record with:

    • start_index

    • end_index

    • extracted_text

  4. When all batches are complete, run B.E. WF generate_strategy, which sends the combined impacts to OpenAI to produce a Change Strategy.

This previously worked but after adding batching safeguards it now loops or produces incorrect batch ranges.


Current Data Structure

ImpactType

Fields include:

  • Project

  • As Is

  • To Be

  • culture_level

  • customer_level

  • data_level

  • organisation_level

  • people_level

  • policies_level

  • process_level

  • systems_level

  • created date

ChangeStrategy

Fields include:

  • Project

  • batch_size

  • batches_done

  • Impact_Count_ForProject

  • overview_text

  • objectives_text

  • timeline_text

  • stakeholder_text

  • training_text

  • comms_text

  • hypercare_text

  • strategyJSON

  • strategyJSON_raw

  • status

ExtractedBatch

Fields include:

  • strategy

  • project

  • batch_number

  • start_index

  • end_index

  • extracted_text

  • status


Backend Workflows

:one: extract_batch

Parameters:

  • Project

  • Strategy

  • batch_number

  • start_index

  • end_index

Workflow does:

  1. Create ExtractedBatch records

  2. Build extracted_text using:

Search for ImpactTypes
→ sorted by Created Date
→ items from #start_index
→ items until #end_index
→ format as text

  1. Schedule next batch using:

batch_number + 1
start_index = end_index + 1
end_index = end_index + batch_size

  1. When all impacts processed → schedule generate_strategy.

Problem:
The batching logic sometimes produces invalid ranges like:

start_index = 10
end_index = 9

or loops continuously.


:two: generate_strategy

This workflow:

  1. Combines all ExtractedBatch texts

  2. Sends them to OpenAI

  3. Receives a structured JSON change strategy

  4. Saves it into ChangeStrategy fields

  5. Runs parse_strategy_json

This part works correctly.

What screenshots would be helpful to share?

I’m not very techsavvy and as you can might read have gotten chatgpt to help me with most of it.

Thank you for taking the time to read all this.
Simon

Kudos on trying but id caution this isnt the kind of workflow you can build, let alone maintain, without understanding what’s going on, especially considering the ramifications of such a WF going off the rails.