Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤔 [ISSUE] - attached Blocks infinite loop #224

Open
medtaher123 opened this issue Oct 15, 2024 · 0 comments
Open

🤔 [ISSUE] - attached Blocks infinite loop #224

medtaher123 opened this issue Oct 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@medtaher123
Copy link
Contributor

medtaher123 commented Oct 15, 2024

Description:

A block can either have:

  1. Next blocks (linked with a single arrow) — These are blocks with trigger conditions. Only one will be called after the user sends a message.
  2. An attached block (linked with a double arrow) — This block is called automatically without any triggers.
    A block cannot have both nextBlocks and an attachedBlock.

Current Issue:

  • The user can attach a block to itself, potentially causing an infinite loop if the block triggers itself continuously. This was partially handled in a previous PR (the check exists only on the frontend but not the backend).

Problem:

  • Generalized issue: The same problem can occur when two or more blocks are attached to each other, forming an infinite loop (e.g., Block A attaches to Block B, and Block B attaches back to Block A).

Solution:

To prevent this, we need to:

1- Add a check in the backend API to detect and prevent circular attachments.
2- Add a check in the frontend to detect this issue as well.
3- Optionally, in the frontend, display a warning toast when the user attempts to complete the final link that would create a circular reference.

Circular Attachment Detection Algorithm:

  1. Start at the source block and check if it has an attached block (the destination block).
  2. Follow the chain: For each destination block, check if it also has an attached block.
  3. Two possible outcomes:
    • No circular loop: The chain reaches a block with no attached block (valid scenario, the link is accepted).
    • Circular loop detected: The chain loops back to the original source block (invalid scenario, the link is rejected).

Reproduction steps

1. Go to visual editor
2. link a block A to a block B (with the double arrow)
3. link a block B to a block A (also with the double arrow)
4. trigger one of these two blocks in a conversation
5. see infinite loop
to stop the loop you can simply break it by removing one of the blocks or a link

image

Logs

No response

Browsers

No response

OS

No response

@medtaher123 medtaher123 added the bug Something isn't working label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant