[Bug] arun() drops its own *args with a TypeError, and awaits a synchronous error handler (#1853 item 3) - #1871
Merged
Conversation
…g a sync error handler]
|
Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap. |
This was referenced Aug 12, 2026
6 tasks
ayaangazali
added a commit
to ayaangazali/swarms
that referenced
this pull request
Aug 23, 2026
test_extra_positional_args_reach_run came in with kyegomez#1871 and asserts that arun(task, img, "EXTRA") forwards "EXTRA" positionally to run(). That is the behaviour this PR removes, so the test locked the defect in. It only ever passed because its stub is declared `fake_run(*args, **kwargs)`, which accepts anything positionally and so cannot observe where the argument actually lands. Against the real signature it lands on `imgs`: >>> inspect.signature(Agent.run).bind_partial(None, "T", "I", "EXTRA") {'task': 'T', 'img': 'I', 'imgs': 'EXTRA'} `imgs` is a List[str] of image paths, not run()'s own *args. Replaced with two tests that use a stub with the real parameter names, so a mis-bind is visible: - task/img/kwargs reach run() as themselves - a third positional raises TypeError at the arun boundary instead of being silently bound to imgs The second fails on master's agent.py and passes here, which is the whole point of the change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ayaangazali
added a commit
to ayaangazali/swarms
that referenced
this pull request
Aug 23, 2026
test_extra_positional_args_reach_run came in with kyegomez#1871 and asserts that arun(task, img, "EXTRA") forwards "EXTRA" positionally to run(). That is the behaviour this PR removes, so the test locked the defect in. It only ever passed because its stub is declared `fake_run(*args, **kwargs)`, which accepts anything positionally and so cannot observe where the argument actually lands. Against the real signature it lands on `imgs`: >>> inspect.signature(Agent.run).bind_partial(None, "T", "I", "EXTRA") {'task': 'T', 'img': 'I', 'imgs': 'EXTRA'} `imgs` is a List[str] of image paths, not run()'s own *args. Replaced with two tests that use a stub with the real parameter names, so a mis-bind is visible: - task/img/kwargs reach run() as themselves - a third positional raises TypeError at the arun boundary instead of being silently bound to imgs The second fails on master's agent.py and passes here, which is the whole point of the change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ayaangazali
added a commit
to ayaangazali/swarms
that referenced
this pull request
Aug 27, 2026
test_extra_positional_args_reach_run came in with kyegomez#1871 and asserts that arun(task, img, "EXTRA") forwards "EXTRA" positionally to run(). That is the behaviour this PR removes, so the test locked the defect in. It only ever passed because its stub is declared `fake_run(*args, **kwargs)`, which accepts anything positionally and so cannot observe where the argument actually lands. Against the real signature it lands on `imgs`: >>> inspect.signature(Agent.run).bind_partial(None, "T", "I", "EXTRA") {'task': 'T', 'img': 'I', 'imgs': 'EXTRA'} `imgs` is a List[str] of image paths, not run()'s own *args. Replaced with two tests that use a stub with the real parameter names, so a mis-bind is visible: - task/img/kwargs reach run() as themselves - a third positional raises TypeError at the arun boundary instead of being silently bound to imgs The second fails on master's agent.py and passes here, which is the whole point of the change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses item 3 in #1853, plus a second defect in the same three lines.
1.
arun(task, img, extra)raises instead of runningarunforwarded torunlike this:asyncio.to_thread(func, *a, **kw)callsfunc(*a, **kw), so the splatted*argsarrive positionally whiletaskis also passed by keyword — andrun's first positional parameter istask. Any extra positional argument therefore collides:arundeclares*argsspecifically to accept those arguments, so the one documented way to use them was the one way that failed.Fixed by forwarding positionally, in
run's own parameter order, which makesarun(t, i, x)behave exactly likerun(t, i, x):2.
awaiton a synchronous method_handle_run_erroris a plaindefwhose last statement israise error. It is not a coroutine function, and the seven other call sites —agent.py:1679,:1688,:2060,:3114,llm_manager.py:889,:899,autonomous_loop.py:954— all call it withoutawait.This only ever worked by accident: the method raises before returning, so the
awaitnever evaluates its operand. The moment_handle_run_errorstops raising unconditionally, this line becomesawait None→TypeError, on the error path, where it is hardest to notice. Dropped theawaitand the stale "Ensure this is also async if needed" comment.Tests
Appended to
tests/structs/test_agent.pyasTestArunForwarding— no new file. Neither test constructs a model or makes an LLM call;runis replaced on a bare instance, so they exercisearun's plumbing only.test_extra_positional_args_reach_run—arun("T", "I", "EXTRA")reachesrunas("T", "I", "EXTRA")test_error_path_does_not_await_a_sync_handler— asserts_handle_run_erroris not a coroutine function, thatarun's source no longer awaits it, and that the originalValueErrorsurfaces rather than aTypeErrorThe rest of
test_agent.pyis red onmasterbefore and after this change (missing provider credentials); this diff does not move those numbers.Red checks are the repo-wide pre-existing ones, addressed in #1812.