Skip to content

Conversation

dst03106
Copy link
Contributor

@dst03106 dst03106 commented May 13, 2025

User description

When integrating with logging observability platforms:

  • Langfuse(==v2.60.4): I encountered an issue where the error "Set of Tasks/Futures is empty" was raised. To resolve this, I added a condition to handle that case.
스크린샷 2025-05-13 오후 2 51 34
  • Langsmith(with litellm==v1.66.3): I experienced an infinite wait issue, which turned out to be caused by periodic flushing. To mitigate this, I added a TTL (time-to-live) to limit the waiting time.
스크린샷 2025-05-13 오후 2 55 17 스크린샷 2025-05-13 오후 2 56 08

PR Type

Bug fix, Enhancement


Description

  • Add timeout to asyncio.wait when callbacks are enabled
    • Prevents infinite wait by limiting to 30 seconds
    • Handles empty task set to avoid errors

Changes walkthrough 📝

Relevant files
Bug fix
cli.py
Add timeout and empty-task check to event queue wait         

pr_agent/cli.py

  • Added a 30-second timeout to asyncio.wait for callback tasks
  • Added a check to ensure the task list is not empty before waiting
  • Prevents errors and infinite waits during event queue flushing
  • +3/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @dst03106 dst03106 marked this pull request as ready for review May 13, 2025 05:57
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Timeout Value

    The 30-second timeout is hardcoded. Consider making this configurable through settings to allow users to adjust based on their specific environment needs.

    await asyncio.wait(tasks, timeout=30)

    Copy link
    Contributor

    qodo-merge-for-open-source bot commented May 13, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Handle timeout results
    Suggestion Impact:The commit implemented exactly what was suggested - capturing the done and pending tasks from asyncio.wait() and adding a warning log when tasks exceed the timeout

    code diff:

    -                await asyncio.wait(tasks, timeout=30)
    +                done, pending = await asyncio.wait(tasks, timeout=30)
    +                if pending:
    +                    get_logger().warning(f"{len(pending)} callback tasks did not complete within timeout")

    Handle the case where tasks don't complete within the timeout. Currently, if
    tasks exceed the timeout, they continue running but the program proceeds, which
    could lead to unexpected behavior. Consider adding a warning log or handling
    incomplete tasks.

    pr_agent/cli.py [89-91]

     tasks = [task for task in asyncio.all_tasks() if task is not asyncio.current_task()]
     if tasks:
    -    await asyncio.wait(tasks, timeout=30)
    +    done, pending = await asyncio.wait(tasks, timeout=30)
    +    if pending:
    +        get_logger().warning(f"{len(pending)} callback tasks did not complete within timeout")

    [Suggestion processed]

    Suggestion importance[1-10]: 7

    __

    Why: The suggestion improves robustness by warning if callback tasks do not complete within the timeout, which helps with debugging and monitoring but does not address a critical bug or security issue.

    Medium
    • Update
    • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    @dst03106 dst03106 changed the title fix: add timeout to asyncio.wait when callback is enabled fix: add timeout to asyncio.wait during CLI execution to avoid hanging when callback is enabled May 13, 2025
    dst03106 and others added 2 commits May 13, 2025 17:34
    Co-authored-by: qodo-merge-pro-for-open-source[bot] <189517486+qodo-merge-pro-for-open-source[bot]@users.noreply.github.com>
    Comment on lines +91 to +95
    _, pending = await asyncio.wait(tasks, timeout=30)
    if pending:
    get_logger().warning(
    f"{len(pending)} callback tasks({[task.get_coro() for task in pending]}) did not complete within timeout"
    )
    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    @mrT23 Thanks! I added coroutine details to help identify which task is pending. Let me know if anything looks off.
    image

    @mrT23 mrT23 merged commit 35d75e9 into qodo-ai:main May 13, 2025
    2 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants