[Bug] CronJob rejects every plain callable it documents supporting — the Callable check is inverted - #1904
Conversation
|
Still needed after #1920 — flagging it because the two land in the same method's neighbourhood and it would be easy to read one as covering the other. #1920 fixed Reproduced just now against master at 36d40c3 (with #1920 in): The docstring on that same method still advertises plain callables, and the class docstring shows one as an example, so the documented usage is the broken one. |
|
Accepted and merged as Verified against
I tested this on the merge result rather than the branch alone, since the branch predated #1920. Merged onto master it applies cleanly, both fixes coexist, and #1920's hourly-interval and Worth noting this had already surfaced in practice: while reviewing #1920 I wrote a probe agent with One thing for next time: seven lines of production change with no test. The three shapes in the table above are cheap to encode, and |
CronJobis documented as "A wrapper class that turns any callable (including Swarms agents) into a scheduled cron job" and typedagent: Optional[Union[Any, Callable]]. Only the Agent half works. The discriminator is inverted, so both non-Agent shapes fail — each one down the branch meant for the other.Reproduce
Cause
isinstance(x, Callable)tests for__call__, which is the wrong question here — it is true for plain functions and false for a plain object that only definesrun(). So:Callable→ takes the.run()branch →AttributeErrorrun()but no__call__is notCallable→ takes the direct-call branch →TypeErrorAn
Agentsatisfies both, which is why the only shape that works is the one that hides the bug. Theelsebranch is unreachable for every function, i.e. the documented "any callable" path never executed.Fix
Ask the question the branch actually cares about — does this thing have a
run()to call:Agent behaviour is unchanged (it has
run, so it takes the same branch as before, with the sametask=/**kwargscall shape). Callbacks and kwargs forwarding verified unaffected:handled: cb task [cb] | meta=1.Same root cause as #1900 (
create_agent_mapused the same test to tell Agents from functions). Separate PR because it is a different module and a different symptom — that one silently returns an empty map, this one raises.No test file: four-line change inside one branch.
Adjacent finding
Filed as #1905:
batched_run(tasks)can only ever schedule the first task.run()ends inwhile True: time.sleep(1), sobatched_run's loop never reaches iteration two and never returns. Verified — three tasks in,['task-A']scheduled, thread still alive.