Skip to content

Add async task multiplexing for concurrent task processing#630

Open
nforro wants to merge 4 commits into
packit:mainfrom
nforro:multiplexing
Open

Add async task multiplexing for concurrent task processing#630
nforro wants to merge 4 commits into
packit:mainfrom
nforro:multiplexing

Conversation

@nforro

@nforro nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member

With MAX_CONCURRENT_TASKS=1 (the default), the workflows should behave exactly the same as before. So I think we can deploy this and if there are no regressions, we can try increasing the number and monitor resource usage.

This PR also modifies logging:

  • GlobalTrajectoryMiddleware output now goes through loggers, so it gets prefixed just like regular log messages
  • log messages are associated with a Jira key being processed if possible
  • with LOG_BUFFER_SIZE higher than zero, log messages associated with the same Jira issue are buffered and output in batches, for better readability when multiple tasks are processed in parallel

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

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.

Code Review

This pull request introduces a concurrent task loop (run_task_loop) using an asyncio semaphore to safely process tasks from Redis queues across several agents, alongside a new BufferedTaskHandler to buffer and flush logs per Jira issue. Feedback on these changes highlights a potential deadlock in the task loop's finally block if log flushing raises an exception, which would leak semaphore permits; wrapping the flush in a try-except block is recommended to guarantee release. Additionally, a minor improvement is suggested to simplify trajectory logging by directly passing the pre-formatted message.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/base_utils.py Outdated
Comment thread ymir/common/logging_setup.py Outdated
@nforro nforro force-pushed the multiplexing branch 2 times, most recently from 78f1031 to 109be6d Compare June 25, 2026 15:29
@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/agentic_review

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

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.

Code Review

This pull request introduces a concurrent task loop using a semaphore to limit concurrency, refactoring several agents to use this loop. It also adds a buffered logging mechanism to group logs by Jira issue and integrates a custom writeable adapter for trajectory logging. The review feedback suggests replacing the logging filter with a custom formatter to prevent potential formatting errors, handling multi-line strings in the trajectory writeable, and resetting the Jira issue context variable before flushing logs to prevent messages from being trapped in the buffer.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/logging_setup.py Outdated
Comment thread ymir/common/logging_setup.py Outdated
Comment thread ymir/common/logging_setup.py
Comment thread ymir/common/base_utils.py Outdated
@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

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

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.

Code Review

This pull request introduces concurrent task processing across several agents (backport, rebase, rebuild, and triage) by replacing sequential Redis popping with a concurrent task loop controlled by a new MAX_CONCURRENT_TASKS environment variable. It also adds a log buffering mechanism (BufferedTaskHandler) controlled by LOG_BUFFER_SIZE to group log outputs per Jira issue. Feedback on the changes highlights a critical concurrency issue in BufferedTaskHandler where the _group_depth counter is shared across threads/tasks. This can lead to race conditions when multiple tasks run concurrently. It is recommended to use a ContextVar to track _group_depth independently per task.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/logging_setup.py Outdated
@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

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

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.

Code Review

This pull request introduces concurrent task processing and buffered logging across several agents by implementing a shared run_task_loop and a BufferedTaskHandler to buffer logs per Jira issue. Feedback on these changes highlights critical improvements: implementing flush() and close() in BufferedTaskHandler to prevent log loss on shutdown, refactoring run_task_loop for better performance and graceful task cancellation, and aligning the output streams of the logging handlers to ensure consistent destination streams (stdout vs. stderr).

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/logging_setup.py
Comment thread ymir/common/base_utils.py Outdated
Comment thread ymir/common/logging_setup.py Outdated
@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

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

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.

Code Review

This pull request introduces a centralized, concurrent task processing loop (run_task_loop) across multiple agents, replacing manual polling loops and adding support for concurrent task execution. It also implements a buffered logging mechanism (BufferedTaskHandler) that groups and flushes logs per Jira issue, utilizing a shared current_jira_issue context variable. Feedback on the changes highlights a potential synchronization issue in BufferedTaskHandler.emit where writing to sys.stdout when no Jira issue is present is done without acquiring the lock, which could lead to interleaved console output.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/logging_setup.py
@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

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

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.

Code Review

This pull request introduces a concurrent task loop (run_task_loop) and a buffered logging mechanism (BufferedTaskHandler) to handle task execution and logging more efficiently across various agents. It also standardizes the tracking of the current Jira issue using a shared ContextVar and updates GlobalTrajectoryMiddleware to write logs via a custom writeable adapter. Feedback was provided regarding the cancellation behavior of run_task_loop in ymir/common/base_utils.py. Currently, active tasks are immediately cancelled upon loop cancellation, which could lead to task loss or inconsistent states during a shutdown. It is recommended to allow active tasks to complete gracefully using asyncio.shield before propagating the cancellation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/base_utils.py
@nforro

nforro commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

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

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.

Code Review

This pull request introduces concurrent task processing and buffered logging per Jira issue across various agents. It replaces the infinite polling loops in the agents with a centralized, concurrent run_task_loop utility that manages task execution using a semaphore. Additionally, it introduces a BufferedTaskHandler to buffer log lines by Jira issue, flushing them in contiguous batches, and updates the logging format to include the active Jira issue. Feedback on the changes suggests swapping the order of clearing the Jira issue context and flushing task logs in run_task_loop to ensure that any exceptions raised during log flushing are correctly associated with the active Jira issue context.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ymir/common/base_utils.py

@TomasKorbar TomasKorbar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please bump the common subpackage version. Otherwise LGTM!

nforro added 4 commits June 26, 2026 13:34
Signed-off-by: Nikola Forró <nforro@redhat.com>
Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Nikola Forró <nforro@redhat.com>
Assisted-by: Claude Opus 4.6 via Claude Code
Signed-off-by: Nikola Forró <nforro@redhat.com>
@nforro

nforro commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

Please bump the common subpackage version.

I've added a hook to bump automatically before pushing, unless the version has already changed.

@TomasKorbar TomasKorbar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the hook. LGTM!

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.

2 participants