Skip to content

fix: prevent infinite loop in parallel task execution#884

Merged
MervinPraison merged 2 commits intomainfrom
claude/issue-874-20250714_005622
Jul 14, 2025
Merged

fix: prevent infinite loop in parallel task execution#884
MervinPraison merged 2 commits intomainfrom
claude/issue-874-20250714_005622

Conversation

@MervinPraison
Copy link
Copy Markdown
Owner

Fixes #874

When all tasks are completed and workflow_finished is set to True, the workflow now immediately exits to prevent tasks from being reset to "not started" state. This fixes the issue where parallel tasks would repeat in a loop and the aggregator task would never run.

Generated with Claude Code

…flow when all tasks complete

When all tasks are completed and workflow_finished is set to True, the workflow now immediately exits to prevent tasks from being reset to "not started" state. This fixes the issue where parallel tasks would repeat in a loop and the aggregator task would never run.

Fixes #874

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 14, 2025

Warning

Rate limit exceeded

@claude[bot] has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 30 seconds before requesting another review.

βŒ› How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between c971fa8 and 0ad9721.

πŸ“’ Files selected for processing (1)
  • src/praisonai-agents/praisonaiagents/process/process.py (3 hunks)
✨ Finishing Touches
  • πŸ“ Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where parallel task execution could lead to an infinite loop, preventing the workflow from completing and aggregator tasks from running. The fix ensures that the workflow exits immediately once all tasks are finished, resolving the looping behavior and allowing for proper workflow termination.

Highlights

  • Workflow Termination Logic: Modified both the asynchronous aworkflow and synchronous workflow methods to immediately break out of their respective loops once all tasks are marked as 'completed' and self.workflow_finished is set to True. This change ensures that the workflow terminates promptly, preventing tasks from being inadvertently reset to a 'not started' state.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with πŸ‘ and πŸ‘Ž on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a potential infinite loop in both the synchronous and asynchronous workflow execution by adding a break statement to exit immediately once all tasks are complete. I've added one comment suggesting a refactoring to abstract the duplicated completion-check logic into a helper method, which would improve the code's maintainability.

logging.info("All tasks are completed.")
self.workflow_finished = True
# The next iteration loop check will break the workflow
break # Exit immediately to prevent task reset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The break statement and surrounding logic (lines 324-327) are duplicated in the workflow method (lines 884-887). Consider extracting this completion-checking logic into a private helper method to improve maintainability and adhere to the DRY principle.

@MervinPraison
Copy link
Copy Markdown
Owner Author

@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes.

1 similar comment
@MervinPraison
Copy link
Copy Markdown
Owner Author

@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 14, 2025

Claude encountered an error β€”β€” View job


πŸ“‹ Task List

  • Read and analyze the current changes in process.py
  • Review the infinite loop fix implementation
  • Check for backward compatibility issues
  • Verify no existing features are removed
  • Address code duplication (as suggested by Gemini)
  • Test the implementation if possible
  • Apply minimal fixes if needed
  • Final review of all changes

πŸ” Starting Analysis

Let me first examine the changes made in this PR to understand the fix for the infinite loop issue.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 14, 2025

Claude encountered an error β€”β€” View job


I'll analyze this and get back to you.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 14, 2025

Claude encountered an error β€”β€” View job


πŸ“‹ Task List

πŸ“Š Detailed Analysis

1. The Fix is Correct and Necessary βœ…

The current fix properly addresses the infinite loop issue by:

  • Adding immediate break statements when all tasks are completed
  • Preventing the workflow from reaching the task reset logic (lines 1095-1117)
  • This ensures parallel tasks don't get reset to "not started" and re-executed

2. Backward Compatibility βœ…

The fix maintains backward compatibility:

  • No existing features are removed
  • The change only affects the exit behavior when all tasks are completed
  • The workflow still supports all existing task types (loop, decision, parallel)
  • Task reset logic remains intact for legitimate use cases

3. No Features Removed βœ…

All existing functionality is preserved:

  • Task reset logic still works for non-parallel tasks
  • Loop and decision tasks continue to function normally
  • The workflow_finished flag behavior is enhanced, not replaced

4. Code Duplication Issue ⚠️

Gemini correctly identified that the completion check logic is duplicated between:

  • Async workflow (lines 324-327)
  • Sync workflow (lines 884-887)

πŸ”§ Implementing Improvements

I'll now address the code duplication by creating a helper method to encapsulate the completion check logic...

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jul 14, 2025

Claude finished @MervinPraison's task β€”β€” View job


πŸ“‹ Task List

πŸ“Š Detailed Analysis

1. The Fix is Correct and Necessary βœ…

The current fix properly addresses the infinite loop issue by:

  • Adding immediate break statements when all tasks are completed
  • Preventing the workflow from reaching the task reset logic (lines 1095-1117)
  • This ensures parallel tasks don't get reset to "not started" and re-executed

2. Backward Compatibility βœ…

The fix maintains backward compatibility:

  • No existing features are removed
  • The change only affects the exit behavior when all tasks are completed
  • The workflow still supports all existing task types (loop, decision, parallel)
  • Task reset logic remains intact for legitimate use cases

3. No Features Removed βœ…

All existing functionality is preserved:

  • Task reset logic still works for non-parallel tasks
  • Loop and decision tasks continue to function normally
  • The workflow_finished flag behavior is enhanced, not replaced

4. Code Duplication Issue ⚠️

Gemini correctly identified that the completion check logic is duplicated between:

  • Async workflow (lines 324-327)
  • Sync workflow (lines 884-887)

πŸ”§ Implemented Improvements

I've addressed the code duplication by creating a helper method to encapsulate the completion check logic:

def _check_all_tasks_completed(self) -> bool:
    """Check if all tasks are completed and handle workflow completion.
    
    Returns:
        bool: True if all tasks are completed and workflow should exit, False otherwise.
    """
    if all(task.status == "completed" for task in self.tasks.values()):
        logging.info("All tasks are completed.")
        self.workflow_finished = True
        return True
    return False

Both the aworkflow and workflow methods now use this shared helper method, eliminating the duplication while maintaining the same functionality.

πŸ“ Summary

The PR correctly fixes the infinite loop issue in parallel task execution. I've enhanced it by:

  1. Refactoring the duplicated code into a reusable helper method
  2. Maintaining backward compatibility - no breaking changes
  3. Preserving all existing features - only the bug is fixed

The fix ensures that when all tasks complete, the workflow exits immediately rather than allowing tasks to be reset, preventing the infinite loop described in issue #874.


- Created _check_all_tasks_completed() helper method to eliminate code duplication
- Both async and sync workflow methods now use the same completion check logic
- No functional changes, pure refactoring for better maintainability

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@MervinPraison
Copy link
Copy Markdown
Owner Author

@claude review if the changes made are as per the requirements

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 14, 2025

Claude encountered an error β€”β€” View job

Failed with exit code 128

I'll analyze this and get back to you.

@MervinPraison
Copy link
Copy Markdown
Owner Author

@claude fix above issue

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 14, 2025

Claude encountered an error β€”β€” View job

Failed with exit code 128

I'll analyze this and get back to you.

@MervinPraison
Copy link
Copy Markdown
Owner Author

@claude fix above issue

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 14, 2025

Claude finished @MervinPraison's task β€”β€” View job


πŸ“‹ Task List

  • Analyze current PR changes and understand the infinite loop fix
  • Investigate GitHub Action failures (exit code 128)
  • Address code duplication issue identified by Gemini Code Assist
  • Verify backward compatibility and no feature removal
  • Test the implementation if possible
  • Apply fixes if needed
  • Final review of all changes

πŸ” Starting Analysis

Let me first examine the current changes and understand what needs to be fixed...

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 14, 2025

Claude finished @MervinPraison's task β€”β€” View job


πŸ“‹ Task List

  • Read repository CLAUDE.md for setup instructions
  • Analyze current PR changes and understand the infinite loop fix
  • Investigate GitHub Action failures (exit code 128)
  • Address code duplication issue identified by Gemini Code Assist
  • Verify backward compatibility and no feature removal
  • Test the implementation if possible
  • Apply fixes if needed
  • Final review of all changes

πŸ” Starting Analysis

Let me first examine the current changes and understand what needs to be fixed...

@MervinPraison
Copy link
Copy Markdown
Owner Author

@claude review if the changes made are as per the requirements and fix issues if anything exists

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 14, 2025

Claude finished @MervinPraison's task β€”β€” View job


πŸ“‹ Task List

  • Read and analyze the current changes in process.py
  • Review the infinite loop fix implementation
  • Check for backward compatibility issues
  • Verify no existing features are removed
  • Address code duplication (as suggested by Gemini)
  • Test the implementation if possible
  • Apply minimal fixes if needed
  • Final review of all changes

πŸ“Š Detailed Analysis

1. The Fix is Correct and Necessary βœ…

The current fix properly addresses the infinite loop issue by:

  • Adding immediate break statements when all tasks are completed
  • Preventing the workflow from reaching the task reset logic (lines 1095-1117)
  • This ensures parallel tasks don't get reset to "not started" and re-executed

2. Backward Compatibility βœ…

The fix maintains backward compatibility:

  • No existing features are removed
  • The change only affects the exit behavior when all tasks are completed
  • The workflow still supports all existing task types (loop, decision, parallel)
  • Task reset logic remains intact for legitimate use cases

3. No Features Removed βœ…

All existing functionality is preserved:

  • Task reset logic still works for non-parallel tasks
  • Loop and decision tasks continue to function normally
  • The workflow_finished flag behavior is enhanced, not replaced

4. Code Duplication Issue ⚠️

Gemini correctly identified that the completion check logic is duplicated between:

  • Async workflow (lines 324-327)
  • Sync workflow (lines 884-887)

πŸ”§ Implemented Improvements

I've addressed the code duplication by creating a helper method to encapsulate the completion check logic:

def _check_all_tasks_completed(self) -> bool:
    """Check if all tasks are completed and handle workflow completion.
    
    Returns:
        bool: True if all tasks are completed and workflow should exit, False otherwise.
    """
    if all(task.status == "completed" for task in self.tasks.values()):
        logging.info("All tasks are completed.")
        self.workflow_finished = True
        return True
    return False

Both the aworkflow and workflow methods now use this shared helper method, eliminating the duplication while maintaining the same functionality.

πŸ“ Summary

The PR correctly fixes the infinite loop issue in parallel task execution. I've enhanced it by:

  1. Refactoring the duplicated code into a reusable helper method
  2. Maintaining backward compatibility - no breaking changes
  3. Preserving all existing features - only the bug is fixed

The fix ensures that when all tasks complete, the workflow exits immediately rather than allowing tasks to be reset, preventing the infinite loop described in issue #874.


@MervinPraison MervinPraison merged commit 83bdc5d into main Jul 14, 2025
9 checks passed
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.

Agentic parallelization mode: parallel tasks repeat in a loop, aggregator/summary never runs, process never completes

1 participant