[Bug] Agent.run_batched raises before running anything when imgs is omitted, and mislabels images when it is not - #1938
Merged
kyegomez merged 1 commit intoAug 20, 2026
Conversation
`run_batched` zips the tasks against `imgs` using `imgs` as the loop variable:
return [
self.run(task=task, imgs=imgs, *args, **kwargs)
for task, imgs in zip(tasks, imgs)
]
Three problems in four lines:
1. `imgs` defaults to None and is documented as optional, but `zip(tasks, None)`
raises `TypeError: 'NoneType' object is not iterable` — so the documented
basic call `agent.run_batched(["a", "b"])` never runs a single task.
2. The loop variable rebinds the parameter, so each `self.run` call receives
one image string in `imgs`, a field declared `List[str]` and passed straight
through to the provider call. The single-image parameter is `img`.
3. Unequal lengths zip to the shorter one, so passing fewer images than tasks
silently discards tasks rather than reporting the mismatch.
Now: no images runs the tasks plainly, paired images go through `img`, and a
length mismatch raises rather than dropping work. The docstring said
"concurrently" while the body was always a list comprehension; it now says
what it does. Making it actually concurrent is a behaviour change and belongs
in its own PR.
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.
Problem
Agent.run_batchedusesimgsas both the parameter and the loop variable:Three separate failures come out of those four lines:
1. The documented default call raises.
imgsdefaults toNoneand the docstring says it is optional, butzip(tasks, None)fails before any task runs:2. With images, each task gets a
strin aList[str]field. The loop variable rebinds the parameter, soself.runreceives one image path inimgs, whichAgent.run→call_llm→llm_manager.callforwards to the provider asrun_args["imgs"] = "a.png". The parameter for a single image isimg.3. Unequal lengths silently drop tasks.
zipstops at the shorter sequence, so three tasks and one image runs one task and discards two, with no error and no log line.Fix
After:
The docstring said "Run a batch of tasks concurrently" while the body has always been a plain list comprehension, so it now says what it does. Making it genuinely concurrent is a behaviour change — the sibling paths use a call-scoped
ContextThreadPoolExecutorafter #1909 — and belongs in its own PR rather than smuggled into a crash fix.Tests
Three cases added to
tests/structs/test_agent.py, next toTestConcurrentExecutionPool, which is where the otherAgentbatch-path tests live. They build the agent withAgent.__new__like that class does, so there is no model client, no memory file and no provider call.All three fail on master with the source reverted and the tests kept:
tests/structs/test_agent.pygoes from19 failed, 71 passed, 8 errorson master to19 failed, 74 passed, 8 errorshere — same failure set, plus the three new tests. Those 19 are pre-existing and need provider credentials.🤖 Generated with Claude Code