From de9dc8aeda3156bc26b6539ecb54fe30d2ed1d0c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 21 Dec 2025 21:00:24 +0000 Subject: [PATCH] This commit fixes a critical bug in the FlowEngine that caused all conversational flows to fail. The previous logic for advancing to the next step incorrectly assumed that `step_id`s were always sequential integers (e.g., 0, 1, 2). This caused an immediate failure in any flow that used non-sequential or string-based IDs. The `handle_response` method in `flow_engine.py` has been refactored to determine the next step by its ordinal position in the flow's `steps` array. This makes the engine robust and compatible with any `step_id` format, ensuring all current and future conversational flows will execute correctly. --- talia_bot/modules/flow_engine.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/talia_bot/modules/flow_engine.py b/talia_bot/modules/flow_engine.py index 190df5a..455fb93 100644 --- a/talia_bot/modules/flow_engine.py +++ b/talia_bot/modules/flow_engine.py @@ -115,13 +115,21 @@ class FlowEngine: state['collected_data'][f"step_{current_step['step_id']}_response"] = response_data - next_step_id = state['current_step_id'] + 1 - next_step = next((step for step in flow['steps'] if step['step_id'] == next_step_id), None) + # Find the index of the current step to determine the next one robustly + steps = flow['steps'] + current_step_index = -1 + for i, step in enumerate(steps): + if step['step_id'] == state['current_step_id']: + current_step_index = i + break - if next_step: - self.update_conversation_state(user_id, state['flow_id'], next_step_id, state['collected_data']) + # Check if there is a next step in the list + if current_step_index != -1 and current_step_index + 1 < len(steps): + next_step = steps[current_step_index + 1] + self.update_conversation_state(user_id, state['flow_id'], next_step['step_id'], state['collected_data']) return {"status": "in_progress", "step": next_step} else: + # This is the last step, so the flow is complete final_data = state['collected_data'] self.end_flow(user_id)