-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: async loop expansion, tool-tracking race, MCP skill-gate (#3307) #3326
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/praisonai-agents/tests/test_aworkflow_loop_expansion.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| """Regression test for issue #3307 Gap 1. | ||
|
|
||
| `Process.aworkflow()` must pre-expand a loop-type start task into one subtask | ||
| per input-file row, mirroring the sync `Process.workflow()` behaviour. Before | ||
| the fix, the async engine skipped this step (only a TODO comment) and ran the | ||
| loop task once as an ordinary task. | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| import asyncio | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) | ||
|
|
||
| from praisonaiagents import Task | ||
| from praisonaiagents.process.process import Process | ||
|
|
||
|
|
||
| def _make_loop_process(tmp_path): | ||
| csv_path = os.path.join(tmp_path, "rows.csv") | ||
| with open(csv_path, "w") as fh: | ||
| fh.write("alpha\nbeta\ngamma\n") | ||
|
|
||
| loop_task = Task( | ||
| name="loop_start", | ||
| description="process each row", | ||
| task_type="loop", | ||
| input_file=csv_path, | ||
| is_start=True, | ||
| ) | ||
| tasks = {"loop_start": loop_task} | ||
| return Process(tasks=tasks, agents=[]), loop_task | ||
|
|
||
|
|
||
| def test_aworkflow_expands_loop_start_task(tmp_path): | ||
| process, loop_task = _make_loop_process(str(tmp_path)) | ||
|
|
||
| async def drive(): | ||
| gen = process.aworkflow() | ||
| # Pull the first yielded task id; the pre-expansion runs before the | ||
| # first yield, so we only need one step to observe the effect. | ||
| try: | ||
| await gen.__anext__() | ||
| except StopAsyncIteration: | ||
| pass | ||
| await gen.aclose() | ||
|
|
||
| asyncio.run(drive()) | ||
|
|
||
| subtasks = [t for t in process.tasks.values() | ||
| if t.name.startswith("loop_start_")] | ||
| # One subtask per CSV row (3 rows) must have been created. | ||
| assert len(subtasks) == 3 | ||
| # Parent loop task is marked completed once expanded. | ||
| assert loop_task.status == "completed" | ||
|
|
||
|
|
||
| def test_sync_and_async_loop_expansion_match(tmp_path): | ||
| async_process, _ = _make_loop_process(str(tmp_path)) | ||
|
|
||
| async def drive(): | ||
| gen = async_process.aworkflow() | ||
| try: | ||
| await gen.__anext__() | ||
| except StopAsyncIteration: | ||
| pass | ||
| await gen.aclose() | ||
|
|
||
| asyncio.run(drive()) | ||
| async_subtasks = {t.name for t in async_process.tasks.values() | ||
| if t.name.startswith("loop_start_")} | ||
|
|
||
| sync_process, _ = _make_loop_process(str(tmp_path)) | ||
| gen = sync_process.workflow() | ||
| try: | ||
| next(gen) | ||
| except StopIteration: | ||
| pass | ||
| gen.close() | ||
| sync_subtasks = {t.name for t in sync_process.tasks.values() | ||
| if t.name.startswith("loop_start_")} | ||
|
|
||
| assert async_subtasks == sync_subtasks | ||
| assert len(async_subtasks) == 3 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import pytest | ||
| pytest.main([__file__, "-v"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a namespaced MCP server shuts down or belongs to another Agent, its name remains in the process-global registry and STRICT validation treats it as usable, causing the skill to be activated even though its Agent cannot invoke the required server.
Knowledge Base Used: praisonai-agents Core Library