Skip to content

fix(bot): honor delays after gotoFlow - #1276

Open
harsh-thakkar7 wants to merge 1 commit into
codigoencasa:builderbotfrom
harsh-thakkar7:fix/877-gotoflow-delay
Open

harsh-thakkar7 wants to merge 1 commit into
codigoencasa:builderbotfrom
harsh-thakkar7:fix/877-gotoflow-delay

Conversation

@harsh-thakkar7

Copy link
Copy Markdown
Contributor

Que tipo de Pull Request es?

  • Mejoras
  • Bug
  • Docs / tests

Descripci贸n

Fixes #877.

gotoFlow waited once using flowInstance.ctx.options.delay, which contains the final answer's options, and then sent the target answers without applying their individual delays. Consequently, consecutive delayed addAnswer messages could be sent immediately, and the initial wait could use the wrong answer's delay.

Changes

  • Replace the single flow-level wait with a wait before each target answer.
  • Use each answer's configured delay, falling back to the bot's general delay exactly like sendFlow.
  • Strengthen the existing issue regression with two delayed answers and timestamp assertions for both intervals.
  • No public API or flow-definition changes.

Verification

  • The strengthened regression failed before the fix because the second answer was not delayed.
  • Targeted gotoFlow tests: 6/6 passed.
  • pnpm test: all 29 monorepo test projects passed.
  • pnpm --filter @builderbot/bot build: passed.
  • ESLint and Prettier checks for both changed files: passed.

@leifermendez

Copy link
Copy Markdown
Member

Antes de aprobar, necesitamos corregir una regresi贸n en la interacci贸n entre gotoFlow y el timeout de la cola. La espera por nodo soluciona el problema original, pero ahora las esperas se acumulan dentro del callback de un elemento cuyo timeout sigue corriendo. Si vence, el rechazo puede quedar sin manejar y terminar el proceso; si la aplicaci贸n captura globalmente ese rechazo, el bucle sigue enviando despu茅s de la cancelaci贸n.

Lo reproduje en 29c014603b3cedfaef458b6c13c23b9079746296, compar谩ndolo con la base cb24cf93f0efe7d7d3cc586223115b44f0dc8b4f, con Node 24.19.0 y usando createBot, createFlow, addKeyword y TestTool:

  • Flujo inicial: addKeyword('start').addAction(async (_, { gotoFlow }) => gotoFlow(target)).
  • Destino: tres addAnswer (A, B, C), cada uno con { delay: 200 }.
  • Configuraci贸n de createBot: { queue: { timeout: 450, concurrencyLimit: 15 } }.
  • Al enviar start mediante el provider de prueba, la base termina con exit 0; el head termina con exit 1 y Error: Queue item timeout after 450ms.
  • Con un listener de unhandledRejection para observar la continuaci贸n, el head todav铆a env铆a C despu茅s del timeout, aproximadamente a los 808 ms.

El timeout de 450 ms solo acorta la reproducci贸n; el predeterminado de createBot es 50000 ms. La debilidad de cancelaci贸n ya exist铆a, pero este cambio hace que la misma entrada y configuraci贸n de gotoFlow ahora la active. Los 6 tests de gotoFlow y los 208 tests del paquete pasan, por lo que esa interacci贸n no est谩 cubierta actualmente.

驴Podr铆as mantener la correcci贸n por nodo y agregar un manejo controlado del timeout, propagando y respetando la cancelaci贸n, junto con un test de integraci贸n que exceda el timeout durante gotoFlow? El test deber铆a comprobar que no haya rechazo no manejado ni env铆os posteriores a la cancelaci贸n. Aumentar el timeout solamente no resuelve ese segundo problema. Gracias por trabajar en esta correcci贸n.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[馃悰] Bug un flujo no respeta delay si entr贸 por medio de gotoFlow

2 participants